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)
245 virtual Vector3 GetNaturalSize()
247 return Vector3( 0.0f, 0.0f, 0.0f );
257 class MyTestCustomActor : public CustomActor
261 typedef SignalV2< void ()> SignalType;
262 typedef SignalV2< 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();
521 type = registry.GetTypeInfo( "LightActor" );
522 DALI_TEST_CHECK( type );
523 LightActor la = LightActor::DownCast(type.CreateInstance());
524 DALI_TEST_CHECK( la );
525 Stage::GetCurrent().Add( la );
526 application.Render();
529 type = registry.GetTypeInfo( "Animation" );
530 DALI_TEST_CHECK( type );
531 Animation an = Animation::DownCast(type.CreateInstance());
532 DALI_TEST_CHECK( an );
534 application.Render();
537 type = registry.GetTypeInfo( "ShaderEffect" );
538 DALI_TEST_CHECK( type );
539 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
540 DALI_TEST_CHECK( ef );
541 application.Render();
546 /*******************************************************************************
548 * Action through the base handle
550 ******************************************************************************/
551 int UtcDaliTypeRegistryActionViaBaseHandle(void)
553 TestApplication application;
557 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
558 DALI_TEST_CHECK( type );
560 BaseHandle hdl = type.CreateInstance();
561 DALI_TEST_CHECK( hdl );
563 Actor a = Actor::DownCast(hdl);
564 DALI_TEST_CHECK( a );
568 application.SendNotification();
569 application.Render(0);
570 DALI_TEST_CHECK(!a.IsVisible());
572 std::vector<Property::Value> attributes;
574 DALI_TEST_CHECK(hdl.DoAction(Actor::ACTION_SHOW, attributes));
576 application.SendNotification();
577 application.Render(0);
578 DALI_TEST_CHECK(a.IsVisible());
580 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
584 int UtcDaliTypeRegistryNames(void)
586 TestApplication application;
590 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
592 for(TypeRegistry::NameContainer::iterator iter = names.begin();
593 iter != names.end(); ++iter)
595 type = TypeRegistry::Get().GetTypeInfo( *iter );
596 DALI_TEST_CHECK( type );
602 // Check named and typeid are equivalent
603 int UtcDaliTypeRegistryNameEquivalence(void)
605 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
606 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
608 DALI_TEST_CHECK( named_type );
609 DALI_TEST_CHECK( typeinfo_type );
611 DALI_TEST_CHECK( named_type == typeinfo_type );
613 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
614 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
620 int UtcDaliTypeRegistryCustomActor(void)
622 ResetFunctorCounts();
624 TestApplication application;
626 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
627 DALI_TEST_CHECK( type );
629 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
630 DALI_TEST_CHECK( baseType );
632 BaseHandle handle = type.CreateInstance();
633 DALI_TEST_CHECK( handle );
635 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
636 DALI_TEST_CHECK( customHandle );
638 TypeInfo::NameContainer names;
639 type.GetActions(names);
640 TypeInfo::NameContainer baseNames;
641 baseType.GetActions(baseNames);
642 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
645 type.GetSignals(names);
648 baseType.GetSignals(baseNames);
650 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
653 TestConnectionTracker tracker;
655 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
656 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
657 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
658 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
659 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
661 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
662 customHandle.GetCustomSignal().Emit();
663 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
664 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
665 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
667 // tracker should automatically disconnect here
668 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
669 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
671 // Test that functor is disconnected
672 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
673 customHandle.GetCustomSignal().Emit();
674 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
675 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
676 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
678 std::vector<Property::Value> attributes;
679 handle.DoAction("act1", attributes);
680 DALI_TEST_CHECK( lastActionCustom == "act1" );
684 int UtcDaliTypeRegistryCustomSignalFailure(void)
686 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
688 ResetFunctorCounts();
690 TestApplication application;
692 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
693 DALI_TEST_CHECK( type );
695 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
696 DALI_TEST_CHECK( baseType );
698 BaseHandle handle = type.CreateInstance();
699 DALI_TEST_CHECK( handle );
701 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
702 DALI_TEST_CHECK( customHandle );
704 TypeInfo::NameContainer names;
705 TypeInfo::NameContainer baseNames;
707 type.GetActions(names);
708 baseType.GetActions(baseNames);
710 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
715 type.GetSignals(names);
716 baseType.GetSignals(baseNames);
718 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
721 TestConnectionTracker tracker;
723 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
724 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
725 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
726 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
727 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
730 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
731 customHandle.GetCustomSignal().Emit();
732 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
734 // tracker should have nothing to disconnect here
737 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
738 customHandle.GetCustomSignal().Emit();
739 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
745 int UtcDaliTypeRegistryInitFunctions(void)
747 TestApplication application;
749 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
751 DALI_TEST_CHECK( true == CreateCustomInitCalled );
752 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
753 DALI_TEST_CHECK( type );
760 int UtcDaliTypeRegistryNameInitFunctions(void)
762 TestApplication application;
764 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
766 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
767 DALI_TEST_CHECK( baseType );
769 BaseHandle handle = baseType.CreateInstance();
771 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
772 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
773 DALI_TEST_CHECK( type );
778 int UtcDaliPropertyRegistration(void)
780 TestApplication application;
781 TypeRegistry typeRegistry = TypeRegistry::Get();
783 // Check property count before property registration
784 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
785 DALI_TEST_CHECK( typeInfo );
786 BaseHandle handle = typeInfo.CreateInstance();
787 DALI_TEST_CHECK( handle );
788 Actor customActor = Actor::DownCast( handle );
789 DALI_TEST_CHECK( customActor );
790 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
792 std::string propertyName( "prop-1" );
793 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
794 Property::Type propertyType( Property::BOOLEAN );
795 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
797 // Check property count after registration
798 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
799 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
801 // Add custom property and check property count
802 customActor.RegisterProperty( "custom-prop-1", true );
803 unsigned int customPropertyCount( customActor.GetPropertyCount() );
804 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
806 // Set the property, ensure SetProperty called
807 DALI_TEST_CHECK( !setPropertyCalled );
808 customActor.SetProperty( propertyIndex, false );
809 DALI_TEST_CHECK( setPropertyCalled );
811 // Get the property, ensure GetProperty called
812 DALI_TEST_CHECK( !getPropertyCalled );
813 (void)customActor.GetProperty< bool >( propertyIndex );
814 DALI_TEST_CHECK( getPropertyCalled );
816 // Check the property name
817 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
818 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
820 // Check the property index
821 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
823 // Check the property type
824 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
826 // Check property count of type-info is 1
827 Property::IndexContainer indices;
828 typeInfo.GetPropertyIndices( indices );
829 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
831 // Ensure indices returned from actor and customActor differ by two
832 Actor actor = Actor::New();
833 actor.GetPropertyIndices( indices );
834 unsigned int actorIndices = indices.size();
835 customActor.GetPropertyIndices( indices );
836 unsigned int customActorIndices = indices.size();
837 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
841 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
843 TestApplication application;
844 TypeRegistry typeRegistry = TypeRegistry::Get();
846 // Attempt to register a property type out-of-bounds index (less than)
849 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
850 tet_result( TET_FAIL );
852 catch ( DaliException& e )
854 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
857 // Attempt to register a property type out-of-bounds index (greater than)
860 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
861 tet_result( TET_FAIL );
863 catch ( DaliException& e )
865 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
870 int UtcDaliPropertyRegistrationFunctions(void)
872 TestApplication application;
873 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
875 // Attempt to register a property without a setter
878 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
879 tet_result( TET_PASS );
881 catch ( DaliException& e )
883 tet_result( TET_FAIL );
886 // Attempt to register a property without a getter
889 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
890 tet_result( TET_FAIL );
892 catch ( DaliException& e )
894 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
899 int UtcDaliPropertyRegistrationAddSameIndex(void)
901 TestApplication application;
902 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
904 // Add one property with a valid property index
905 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
907 // Attempt to add another property with the same index
910 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
912 catch ( DaliException& e )
914 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
919 int UtcDaliPropertyRegistrationPropertyWritable(void)
921 TestApplication application;
922 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
923 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
925 // Add two properties, one with SetProperty, one without
926 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
927 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
929 // Create custom-actor
930 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
931 DALI_TEST_CHECK( typeInfo );
932 BaseHandle handle = typeInfo.CreateInstance();
933 DALI_TEST_CHECK( handle );
934 Actor customActor = Actor::DownCast( handle );
935 DALI_TEST_CHECK( customActor );
937 // Check whether properties are writable
938 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
939 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
943 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
945 TestApplication application;
946 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
948 // These properties are not animatable
949 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
951 // Create custom-actor
952 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
953 DALI_TEST_CHECK( typeInfo );
954 BaseHandle handle = typeInfo.CreateInstance();
955 DALI_TEST_CHECK( handle );
956 Actor customActor = Actor::DownCast( handle );
957 DALI_TEST_CHECK( customActor );
959 // Check if animatable
960 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
964 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
966 TestApplication application;
967 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
969 // Create custom-actor
970 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
971 DALI_TEST_CHECK( typeInfo );
972 BaseHandle handle = typeInfo.CreateInstance();
973 DALI_TEST_CHECK( handle );
974 Actor customActor = Actor::DownCast( handle );
975 DALI_TEST_CHECK( customActor );
977 // Try to set an index that hasn't been added
980 customActor.SetProperty( propertyIndex, true );
981 tet_result( TET_FAIL );
983 catch ( DaliException& e )
985 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
988 // Try to get an index that hasn't been added
991 (void) customActor.GetProperty< bool >( propertyIndex );
992 tet_result( TET_FAIL );
994 catch ( DaliException& e )
996 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1003 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1005 TestApplication application;
1007 Actor actor = Actor::New();
1008 actor.SetSize(100.0f, 100.0f);
1009 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1010 Stage::GetCurrent().Add(actor);
1014 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1015 DALI_TEST_CHECK( type );
1016 BaseHandle handle = type.CreateInstance();
1017 DALI_TEST_CHECK( handle );
1018 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1019 DALI_TEST_CHECK( detector );
1021 // Attach actor to detector
1023 GestureReceivedFunctor functor( data );
1024 detector.Attach(actor);
1026 // Connect to signal through type
1027 handle.ConnectSignal( &application, LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED, functor );
1029 // Render and notify
1030 application.SendNotification();
1031 application.Render();
1034 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1035 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1036 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1037 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1041 int UtcDaliPanGestureDetectorTypeRegistry(void)
1043 TestApplication application;
1045 Actor actor = Actor::New();
1046 actor.SetSize(100.0f, 100.0f);
1047 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1048 Stage::GetCurrent().Add(actor);
1052 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1053 DALI_TEST_CHECK( type );
1054 BaseHandle handle = type.CreateInstance();
1055 DALI_TEST_CHECK( handle );
1056 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1057 DALI_TEST_CHECK( detector );
1059 // Attach actor to detector
1061 GestureReceivedFunctor functor( data );
1062 detector.Attach(actor);
1064 // Connect to signal through type
1065 handle.ConnectSignal( &application, PanGestureDetector::SIGNAL_PAN_DETECTED, functor );
1067 // Render and notify
1068 application.SendNotification();
1069 application.Render();
1072 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1073 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1074 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1075 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1079 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1081 TestApplication application;
1083 Actor actor = Actor::New();
1084 actor.SetSize(100.0f, 100.0f);
1085 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1086 Stage::GetCurrent().Add(actor);
1090 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1091 DALI_TEST_CHECK( type );
1092 BaseHandle handle = type.CreateInstance();
1093 DALI_TEST_CHECK( handle );
1094 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1095 DALI_TEST_CHECK( detector );
1097 // Attach actor to detector
1099 GestureReceivedFunctor functor( data );
1100 detector.Attach(actor);
1102 // Connect to signal through type
1103 handle.ConnectSignal( &application, PinchGestureDetector::SIGNAL_PINCH_DETECTED, functor );
1105 // Render and notify
1106 application.SendNotification();
1107 application.Render();
1110 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1111 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1115 int UtcDaliTapGestureDetectorTypeRegistry(void)
1117 TestApplication application;
1119 Actor actor = Actor::New();
1120 actor.SetSize(100.0f, 100.0f);
1121 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1122 Stage::GetCurrent().Add(actor);
1126 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1127 DALI_TEST_CHECK( type );
1128 BaseHandle handle = type.CreateInstance();
1129 DALI_TEST_CHECK( handle );
1130 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1131 DALI_TEST_CHECK( detector );
1133 // Attach actor to detector
1135 GestureReceivedFunctor functor( data );
1136 detector.Attach(actor);
1138 // Connect to signal through type
1139 handle.ConnectSignal( &application, TapGestureDetector::SIGNAL_TAP_DETECTED, functor );
1141 // Render and notify
1142 application.SendNotification();
1143 application.Render();
1146 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1147 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1148 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1152 int UtcDaliTypeRegistryNamedType(void)
1154 TestApplication application;
1155 TypeRegistry typeRegistry = TypeRegistry::Get();
1157 // Create a normal actor
1158 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1159 DALI_TEST_CHECK( actorHandle );
1160 Actor actor( Actor::DownCast( actorHandle ) );
1161 DALI_TEST_CHECK( actor );
1162 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1164 // Create Named Actor Type
1165 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1166 DALI_TEST_CHECK( namedHandle );
1167 Actor namedActor( Actor::DownCast( namedHandle ) );
1168 DALI_TEST_CHECK( namedActor );
1169 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1171 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );