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 Actor GetChildByAlias(const std::string& actorAlias)
250 virtual Vector3 GetNaturalSize()
252 return Vector3( 0.0f, 0.0f, 0.0f );
262 class MyTestCustomActor : public CustomActor
266 typedef Signal< void ()> SignalType;
267 typedef Signal< void (float)> SignalTypeFloat;
273 static MyTestCustomActor New()
275 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
276 return MyTestCustomActor( *p ); // takes ownership
279 virtual ~MyTestCustomActor()
283 static MyTestCustomActor DownCast( BaseHandle handle )
285 MyTestCustomActor result;
287 CustomActor custom = Dali::CustomActor::DownCast( handle );
290 CustomActorImpl& customImpl = custom.GetImplementation();
292 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
296 result = MyTestCustomActor(customImpl.GetOwner());
303 SignalType& GetCustomSignal()
305 Dali::RefObject& obj = GetImplementation();
306 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
311 MyTestCustomActor(Internal::CustomActor* internal)
312 : CustomActor(internal)
316 MyTestCustomActor( Impl::MyTestCustomActor& impl )
317 : CustomActor( impl )
323 class MyTestCustomActor2 : public CustomActor
331 static MyTestCustomActor2 New()
333 return MyTestCustomActor2(); // takes ownership
336 virtual ~MyTestCustomActor2()
340 static MyTestCustomActor2 DownCast( BaseHandle handle )
342 MyTestCustomActor2 result;
344 CustomActor custom = Dali::CustomActor::DownCast( handle );
347 CustomActorImpl& customImpl = custom.GetImplementation();
349 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
353 result = MyTestCustomActor2(customImpl.GetOwner());
362 MyTestCustomActor2(Internal::CustomActor* internal)
363 : CustomActor(internal)
367 MyTestCustomActor2( Impl::MyTestCustomActor& impl )
368 : CustomActor( impl )
373 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
376 BaseHandle CreateCustom(void)
378 return MyTestCustomActor::New();
381 static std::string lastSignalConnectionCustom;
383 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
385 lastSignalConnectionCustom = signalName;
387 bool connected( true );
389 Dali::BaseHandle handle(object);
390 MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
392 if( "sig1" == signalName )
394 customActor.GetCustomSignal().Connect( tracker, functor );
398 // signalName does not match any signal
405 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
407 lastSignalConnectionCustom = "failed";
409 return false; // This is supposed to fail
412 struct CustomTestFunctor
416 ++mTotalInstanceCount;
417 ++mCurrentInstanceCount;
420 CustomTestFunctor( const CustomTestFunctor& copyMe )
422 ++mTotalInstanceCount;
423 ++mCurrentInstanceCount;
428 --mCurrentInstanceCount;
436 static int mTotalInstanceCount;
437 static int mCurrentInstanceCount;
438 static int mCallbackCount;
441 int CustomTestFunctor::mTotalInstanceCount = 0;
442 int CustomTestFunctor::mCurrentInstanceCount = 0;
443 int CustomTestFunctor::mCallbackCount = 0;
445 static void ResetFunctorCounts()
447 CustomTestFunctor::mTotalInstanceCount = 0;
448 CustomTestFunctor::mCurrentInstanceCount = 0;
449 CustomTestFunctor::mCallbackCount = 0;
452 static std::string lastActionCustom;
453 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
455 lastActionCustom = actionName;
459 // Custom type registration
460 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
463 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
464 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
465 static const int TEST_SIGNAL_COUNT = 2;
468 static TypeAction customAction1( customType1, "act1", DoActionCustom);
469 static const int TEST_ACTION_COUNT = 1;
471 class TestConnectionTracker : public ConnectionTracker
475 TestConnectionTracker()
480 BaseHandle CreateNamedActorType()
482 Actor actor = Actor::New();
483 actor.SetName( "NamedActor" );
487 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
488 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
490 } // Anonymous namespace
493 // Positive test case for a method
494 int UtcDaliTypeRegistryCreateDaliObjects(void)
496 TestApplication application;
498 TypeRegistry registry; // like this for ctor test coverage
499 registry = TypeRegistry::Get();
503 type = registry.GetTypeInfo( "ImageActor" );
504 DALI_TEST_CHECK( type );
505 DALI_TEST_CHECK( type.GetCreator() );
506 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
507 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
508 DALI_TEST_CHECK( ia );
509 Stage::GetCurrent().Add( ia );
510 application.Render();
512 type = registry.GetTypeInfo( "TextActor" );
513 DALI_TEST_CHECK( type );
514 TextActor ta = TextActor::DownCast(type.CreateInstance());
515 DALI_TEST_CHECK( ta );
516 Stage::GetCurrent().Add( ta );
517 application.Render();
519 type = registry.GetTypeInfo( "CameraActor" );
520 DALI_TEST_CHECK( type );
521 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
522 DALI_TEST_CHECK( ca );
523 Stage::GetCurrent().Add( ca );
524 application.Render();
527 type = registry.GetTypeInfo( "Animation" );
528 DALI_TEST_CHECK( type );
529 Animation an = Animation::DownCast(type.CreateInstance());
530 DALI_TEST_CHECK( an );
532 application.Render();
535 type = registry.GetTypeInfo( "ShaderEffect" );
536 DALI_TEST_CHECK( type );
537 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
538 DALI_TEST_CHECK( ef );
539 application.Render();
544 /*******************************************************************************
546 * Action through the base handle
548 ******************************************************************************/
549 int UtcDaliTypeRegistryActionViaBaseHandle(void)
551 TestApplication application;
555 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
556 DALI_TEST_CHECK( type );
558 BaseHandle hdl = type.CreateInstance();
559 DALI_TEST_CHECK( hdl );
561 Actor a = Actor::DownCast(hdl);
562 DALI_TEST_CHECK( a );
566 application.SendNotification();
567 application.Render(0);
568 DALI_TEST_CHECK(!a.IsVisible());
570 std::vector<Property::Value> attributes;
572 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
574 application.SendNotification();
575 application.Render(0);
576 DALI_TEST_CHECK(a.IsVisible());
578 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
582 int UtcDaliTypeRegistryNames(void)
584 TestApplication application;
588 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
590 for(TypeRegistry::NameContainer::iterator iter = names.begin();
591 iter != names.end(); ++iter)
593 type = TypeRegistry::Get().GetTypeInfo( *iter );
594 DALI_TEST_CHECK( type );
600 // Check named and typeid are equivalent
601 int UtcDaliTypeRegistryNameEquivalence(void)
603 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
604 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
606 DALI_TEST_CHECK( named_type );
607 DALI_TEST_CHECK( typeinfo_type );
609 DALI_TEST_CHECK( named_type == typeinfo_type );
611 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
612 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
618 int UtcDaliTypeRegistryCustomActor(void)
620 ResetFunctorCounts();
622 TestApplication application;
624 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
625 DALI_TEST_CHECK( type );
627 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
628 DALI_TEST_CHECK( baseType );
630 BaseHandle handle = type.CreateInstance();
631 DALI_TEST_CHECK( handle );
633 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
634 DALI_TEST_CHECK( customHandle );
636 TypeInfo::NameContainer names;
637 type.GetActions(names);
638 TypeInfo::NameContainer baseNames;
639 baseType.GetActions(baseNames);
640 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
643 type.GetSignals(names);
646 baseType.GetSignals(baseNames);
648 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
651 TestConnectionTracker tracker;
653 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
654 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
655 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
656 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
657 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
659 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
660 customHandle.GetCustomSignal().Emit();
661 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
662 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
663 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
665 // tracker should automatically disconnect here
666 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
667 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
669 // Test that functor is disconnected
670 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
671 customHandle.GetCustomSignal().Emit();
672 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
673 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
674 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
676 std::vector<Property::Value> attributes;
677 handle.DoAction("act1", attributes);
678 DALI_TEST_CHECK( lastActionCustom == "act1" );
682 int UtcDaliTypeRegistryCustomSignalFailure(void)
684 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
686 ResetFunctorCounts();
688 TestApplication application;
690 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
691 DALI_TEST_CHECK( type );
693 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
694 DALI_TEST_CHECK( baseType );
696 BaseHandle handle = type.CreateInstance();
697 DALI_TEST_CHECK( handle );
699 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
700 DALI_TEST_CHECK( customHandle );
702 TypeInfo::NameContainer names;
703 TypeInfo::NameContainer baseNames;
705 type.GetActions(names);
706 baseType.GetActions(baseNames);
708 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
713 type.GetSignals(names);
714 baseType.GetSignals(baseNames);
716 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
719 TestConnectionTracker tracker;
721 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
722 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
723 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
724 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
725 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
728 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
729 customHandle.GetCustomSignal().Emit();
730 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
732 // tracker should have nothing to disconnect here
735 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
736 customHandle.GetCustomSignal().Emit();
737 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
743 int UtcDaliTypeRegistryInitFunctions(void)
745 TestApplication application;
747 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
749 DALI_TEST_CHECK( true == CreateCustomInitCalled );
750 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
751 DALI_TEST_CHECK( type );
758 int UtcDaliTypeRegistryNameInitFunctions(void)
760 TestApplication application;
762 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
764 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
765 DALI_TEST_CHECK( baseType );
767 BaseHandle handle = baseType.CreateInstance();
769 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
770 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
771 DALI_TEST_CHECK( type );
776 int UtcDaliPropertyRegistration(void)
778 TestApplication application;
779 TypeRegistry typeRegistry = TypeRegistry::Get();
781 // Check property count before property registration
782 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
783 DALI_TEST_CHECK( typeInfo );
784 BaseHandle handle = typeInfo.CreateInstance();
785 DALI_TEST_CHECK( handle );
786 Actor customActor = Actor::DownCast( handle );
787 DALI_TEST_CHECK( customActor );
788 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
790 std::string propertyName( "prop-1" );
791 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
792 Property::Type propertyType( Property::BOOLEAN );
793 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
795 // Check property count after registration
796 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
797 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
799 // Add custom property and check property count
800 customActor.RegisterProperty( "custom-prop-1", true );
801 unsigned int customPropertyCount( customActor.GetPropertyCount() );
802 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
804 // Set the property, ensure SetProperty called
805 DALI_TEST_CHECK( !setPropertyCalled );
806 customActor.SetProperty( propertyIndex, false );
807 DALI_TEST_CHECK( setPropertyCalled );
809 // Get the property, ensure GetProperty called
810 DALI_TEST_CHECK( !getPropertyCalled );
811 (void)customActor.GetProperty< bool >( propertyIndex );
812 DALI_TEST_CHECK( getPropertyCalled );
814 // Check the property name
815 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
816 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
818 // Check the property index
819 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
821 // Check the property type
822 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
824 // Check property count of type-info is 1
825 Property::IndexContainer indices;
826 typeInfo.GetPropertyIndices( indices );
827 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
829 // Ensure indices returned from actor and customActor differ by two
830 Actor actor = Actor::New();
831 actor.GetPropertyIndices( indices );
832 unsigned int actorIndices = indices.size();
833 customActor.GetPropertyIndices( indices );
834 unsigned int customActorIndices = indices.size();
835 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
839 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
841 TestApplication application;
842 TypeRegistry typeRegistry = TypeRegistry::Get();
844 // Attempt to register a property type out-of-bounds index (less than)
847 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
848 tet_result( TET_FAIL );
850 catch ( DaliException& e )
852 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
855 // Attempt to register a property type out-of-bounds index (greater than)
858 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
859 tet_result( TET_FAIL );
861 catch ( DaliException& e )
863 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
868 int UtcDaliPropertyRegistrationFunctions(void)
870 TestApplication application;
871 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
873 // Attempt to register a property without a setter
876 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
877 tet_result( TET_PASS );
879 catch ( DaliException& e )
881 tet_result( TET_FAIL );
884 // Attempt to register a property without a getter
887 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
888 tet_result( TET_FAIL );
890 catch ( DaliException& e )
892 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
897 int UtcDaliPropertyRegistrationAddSameIndex(void)
899 TestApplication application;
900 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
902 // Add one property with a valid property index
903 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
905 // Attempt to add another property with the same index
908 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
910 catch ( DaliException& e )
912 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
917 int UtcDaliPropertyRegistrationPropertyWritable(void)
919 TestApplication application;
920 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
921 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
923 // Add two properties, one with SetProperty, one without
924 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
925 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
927 // Create custom-actor
928 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
929 DALI_TEST_CHECK( typeInfo );
930 BaseHandle handle = typeInfo.CreateInstance();
931 DALI_TEST_CHECK( handle );
932 Actor customActor = Actor::DownCast( handle );
933 DALI_TEST_CHECK( customActor );
935 // Check whether properties are writable
936 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
937 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
941 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
943 TestApplication application;
944 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
946 // These properties are not animatable
947 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
949 // Create custom-actor
950 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
951 DALI_TEST_CHECK( typeInfo );
952 BaseHandle handle = typeInfo.CreateInstance();
953 DALI_TEST_CHECK( handle );
954 Actor customActor = Actor::DownCast( handle );
955 DALI_TEST_CHECK( customActor );
957 // Check if animatable
958 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
962 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
964 TestApplication application;
965 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
967 // Create custom-actor
968 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
969 DALI_TEST_CHECK( typeInfo );
970 BaseHandle handle = typeInfo.CreateInstance();
971 DALI_TEST_CHECK( handle );
972 Actor customActor = Actor::DownCast( handle );
973 DALI_TEST_CHECK( customActor );
975 // Try to set an index that hasn't been added
978 customActor.SetProperty( propertyIndex, true );
979 tet_result( TET_FAIL );
981 catch ( DaliException& e )
983 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
986 // Try to get an index that hasn't been added
989 (void) customActor.GetProperty< bool >( propertyIndex );
990 tet_result( TET_FAIL );
992 catch ( DaliException& e )
994 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1001 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1003 TestApplication application;
1005 Actor actor = Actor::New();
1006 actor.SetSize(100.0f, 100.0f);
1007 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1008 Stage::GetCurrent().Add(actor);
1012 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1013 DALI_TEST_CHECK( type );
1014 BaseHandle handle = type.CreateInstance();
1015 DALI_TEST_CHECK( handle );
1016 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1017 DALI_TEST_CHECK( detector );
1019 // Attach actor to detector
1021 GestureReceivedFunctor functor( data );
1022 detector.Attach(actor);
1024 // Connect to signal through type
1025 handle.ConnectSignal( &application, "long-press-detected", functor );
1027 // Render and notify
1028 application.SendNotification();
1029 application.Render();
1032 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1033 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1034 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1035 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1039 int UtcDaliPanGestureDetectorTypeRegistry(void)
1041 TestApplication application;
1043 Actor actor = Actor::New();
1044 actor.SetSize(100.0f, 100.0f);
1045 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1046 Stage::GetCurrent().Add(actor);
1050 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1051 DALI_TEST_CHECK( type );
1052 BaseHandle handle = type.CreateInstance();
1053 DALI_TEST_CHECK( handle );
1054 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1055 DALI_TEST_CHECK( detector );
1057 // Attach actor to detector
1059 GestureReceivedFunctor functor( data );
1060 detector.Attach(actor);
1062 // Connect to signal through type
1063 handle.ConnectSignal( &application, "pan-detected", functor );
1065 // Render and notify
1066 application.SendNotification();
1067 application.Render();
1070 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1071 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1072 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1073 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1077 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1079 TestApplication application;
1081 Actor actor = Actor::New();
1082 actor.SetSize(100.0f, 100.0f);
1083 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1084 Stage::GetCurrent().Add(actor);
1088 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1089 DALI_TEST_CHECK( type );
1090 BaseHandle handle = type.CreateInstance();
1091 DALI_TEST_CHECK( handle );
1092 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1093 DALI_TEST_CHECK( detector );
1095 // Attach actor to detector
1097 GestureReceivedFunctor functor( data );
1098 detector.Attach(actor);
1100 // Connect to signal through type
1101 handle.ConnectSignal( &application, "pinch-detected", functor );
1103 // Render and notify
1104 application.SendNotification();
1105 application.Render();
1108 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1109 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1113 int UtcDaliTapGestureDetectorTypeRegistry(void)
1115 TestApplication application;
1117 Actor actor = Actor::New();
1118 actor.SetSize(100.0f, 100.0f);
1119 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1120 Stage::GetCurrent().Add(actor);
1124 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1125 DALI_TEST_CHECK( type );
1126 BaseHandle handle = type.CreateInstance();
1127 DALI_TEST_CHECK( handle );
1128 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1129 DALI_TEST_CHECK( detector );
1131 // Attach actor to detector
1133 GestureReceivedFunctor functor( data );
1134 detector.Attach(actor);
1136 // Connect to signal through type
1137 handle.ConnectSignal( &application, "tap-detected", functor );
1139 // Render and notify
1140 application.SendNotification();
1141 application.Render();
1144 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1145 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1146 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1150 int UtcDaliTypeRegistryNamedType(void)
1152 TestApplication application;
1153 TypeRegistry typeRegistry = TypeRegistry::Get();
1155 // Create a normal actor
1156 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1157 DALI_TEST_CHECK( actorHandle );
1158 Actor actor( Actor::DownCast( actorHandle ) );
1159 DALI_TEST_CHECK( actor );
1160 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1162 // Create Named Actor Type
1163 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1164 DALI_TEST_CHECK( namedHandle );
1165 Actor namedActor( Actor::DownCast( namedHandle ) );
1166 DALI_TEST_CHECK( namedActor );
1167 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1169 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );