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( "CameraActor" );
513 DALI_TEST_CHECK( type );
514 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
515 DALI_TEST_CHECK( ca );
516 Stage::GetCurrent().Add( ca );
517 application.Render();
520 type = registry.GetTypeInfo( "Animation" );
521 DALI_TEST_CHECK( type );
522 Animation an = Animation::DownCast(type.CreateInstance());
523 DALI_TEST_CHECK( an );
525 application.Render();
528 type = registry.GetTypeInfo( "ShaderEffect" );
529 DALI_TEST_CHECK( type );
530 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
531 DALI_TEST_CHECK( ef );
532 application.Render();
537 /*******************************************************************************
539 * Action through the base handle
541 ******************************************************************************/
542 int UtcDaliTypeRegistryActionViaBaseHandle(void)
544 TestApplication application;
548 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
549 DALI_TEST_CHECK( type );
551 BaseHandle hdl = type.CreateInstance();
552 DALI_TEST_CHECK( hdl );
554 Actor a = Actor::DownCast(hdl);
555 DALI_TEST_CHECK( a );
559 application.SendNotification();
560 application.Render(0);
561 DALI_TEST_CHECK(!a.IsVisible());
563 std::vector<Property::Value> attributes;
565 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
567 application.SendNotification();
568 application.Render(0);
569 DALI_TEST_CHECK(a.IsVisible());
571 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
575 int UtcDaliTypeRegistryNames(void)
577 TestApplication application;
581 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
583 for(TypeRegistry::NameContainer::iterator iter = names.begin();
584 iter != names.end(); ++iter)
586 type = TypeRegistry::Get().GetTypeInfo( *iter );
587 DALI_TEST_CHECK( type );
593 // Check named and typeid are equivalent
594 int UtcDaliTypeRegistryNameEquivalence(void)
596 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "ImageActor" );
597 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::ImageActor) );
599 DALI_TEST_CHECK( named_type );
600 DALI_TEST_CHECK( typeinfo_type );
602 DALI_TEST_CHECK( named_type == typeinfo_type );
604 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
605 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
611 int UtcDaliTypeRegistryCustomActor(void)
613 ResetFunctorCounts();
615 TestApplication application;
617 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
618 DALI_TEST_CHECK( type );
620 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
621 DALI_TEST_CHECK( baseType );
623 BaseHandle handle = type.CreateInstance();
624 DALI_TEST_CHECK( handle );
626 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
627 DALI_TEST_CHECK( customHandle );
629 TypeInfo::NameContainer names;
630 type.GetActions(names);
631 TypeInfo::NameContainer baseNames;
632 baseType.GetActions(baseNames);
633 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
636 type.GetSignals(names);
639 baseType.GetSignals(baseNames);
641 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
644 TestConnectionTracker tracker;
646 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
647 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
648 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
649 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
650 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
652 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
653 customHandle.GetCustomSignal().Emit();
654 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
655 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
656 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
658 // tracker should automatically disconnect here
659 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
660 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
662 // Test that functor is disconnected
663 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
664 customHandle.GetCustomSignal().Emit();
665 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
666 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
667 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
669 std::vector<Property::Value> attributes;
670 handle.DoAction("act1", attributes);
671 DALI_TEST_CHECK( lastActionCustom == "act1" );
675 int UtcDaliTypeRegistryCustomSignalFailure(void)
677 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
679 ResetFunctorCounts();
681 TestApplication application;
683 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
684 DALI_TEST_CHECK( type );
686 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
687 DALI_TEST_CHECK( baseType );
689 BaseHandle handle = type.CreateInstance();
690 DALI_TEST_CHECK( handle );
692 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
693 DALI_TEST_CHECK( customHandle );
695 TypeInfo::NameContainer names;
696 TypeInfo::NameContainer baseNames;
698 type.GetActions(names);
699 baseType.GetActions(baseNames);
701 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
706 type.GetSignals(names);
707 baseType.GetSignals(baseNames);
709 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
712 TestConnectionTracker tracker;
714 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
715 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
716 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
717 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
718 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
721 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
722 customHandle.GetCustomSignal().Emit();
723 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
725 // tracker should have nothing to disconnect here
728 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
729 customHandle.GetCustomSignal().Emit();
730 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
736 int UtcDaliTypeRegistryInitFunctions(void)
738 TestApplication application;
740 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
742 DALI_TEST_CHECK( true == CreateCustomInitCalled );
743 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
744 DALI_TEST_CHECK( type );
751 int UtcDaliTypeRegistryNameInitFunctions(void)
753 TestApplication application;
755 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
757 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
758 DALI_TEST_CHECK( baseType );
760 BaseHandle handle = baseType.CreateInstance();
762 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
763 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
764 DALI_TEST_CHECK( type );
769 int UtcDaliPropertyRegistration(void)
771 TestApplication application;
772 TypeRegistry typeRegistry = TypeRegistry::Get();
774 // Check property count before property registration
775 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
776 DALI_TEST_CHECK( typeInfo );
777 BaseHandle handle = typeInfo.CreateInstance();
778 DALI_TEST_CHECK( handle );
779 Actor customActor = Actor::DownCast( handle );
780 DALI_TEST_CHECK( customActor );
781 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
783 std::string propertyName( "prop-1" );
784 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
785 Property::Type propertyType( Property::BOOLEAN );
786 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
788 // Check property count after registration
789 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
790 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
792 // Add custom property and check property count
793 customActor.RegisterProperty( "custom-prop-1", true );
794 unsigned int customPropertyCount( customActor.GetPropertyCount() );
795 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
797 // Set the property, ensure SetProperty called
798 DALI_TEST_CHECK( !setPropertyCalled );
799 customActor.SetProperty( propertyIndex, false );
800 DALI_TEST_CHECK( setPropertyCalled );
802 // Get the property, ensure GetProperty called
803 DALI_TEST_CHECK( !getPropertyCalled );
804 (void)customActor.GetProperty< bool >( propertyIndex );
805 DALI_TEST_CHECK( getPropertyCalled );
807 // Check the property name
808 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
809 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
811 // Check the property index
812 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
814 // Check the property type
815 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
817 // Check property count of type-info is 1
818 Property::IndexContainer indices;
819 typeInfo.GetPropertyIndices( indices );
820 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
822 // Ensure indices returned from actor and customActor differ by two
823 Actor actor = Actor::New();
824 actor.GetPropertyIndices( indices );
825 unsigned int actorIndices = indices.size();
826 customActor.GetPropertyIndices( indices );
827 unsigned int customActorIndices = indices.size();
828 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
832 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
834 TestApplication application;
835 TypeRegistry typeRegistry = TypeRegistry::Get();
837 // Attempt to register a property type out-of-bounds index (less than)
840 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
841 tet_result( TET_FAIL );
843 catch ( DaliException& e )
845 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
848 // Attempt to register a property type out-of-bounds index (greater than)
851 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
852 tet_result( TET_FAIL );
854 catch ( DaliException& e )
856 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
861 int UtcDaliPropertyRegistrationFunctions(void)
863 TestApplication application;
864 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
866 // Attempt to register a property without a setter
869 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
870 tet_result( TET_PASS );
872 catch ( DaliException& e )
874 tet_result( TET_FAIL );
877 // Attempt to register a property without a getter
880 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
881 tet_result( TET_FAIL );
883 catch ( DaliException& e )
885 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
890 int UtcDaliPropertyRegistrationAddSameIndex(void)
892 TestApplication application;
893 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
895 // Add one property with a valid property index
896 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
898 // Attempt to add another property with the same index
901 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
903 catch ( DaliException& e )
905 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
910 int UtcDaliPropertyRegistrationPropertyWritable(void)
912 TestApplication application;
913 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
914 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
916 // Add two properties, one with SetProperty, one without
917 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
918 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
920 // Create custom-actor
921 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
922 DALI_TEST_CHECK( typeInfo );
923 BaseHandle handle = typeInfo.CreateInstance();
924 DALI_TEST_CHECK( handle );
925 Actor customActor = Actor::DownCast( handle );
926 DALI_TEST_CHECK( customActor );
928 // Check whether properties are writable
929 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
930 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
934 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
936 TestApplication application;
937 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
939 // These properties are not animatable
940 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
942 // Create custom-actor
943 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
944 DALI_TEST_CHECK( typeInfo );
945 BaseHandle handle = typeInfo.CreateInstance();
946 DALI_TEST_CHECK( handle );
947 Actor customActor = Actor::DownCast( handle );
948 DALI_TEST_CHECK( customActor );
950 // Check if animatable
951 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
955 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
957 TestApplication application;
958 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
960 // Create custom-actor
961 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
962 DALI_TEST_CHECK( typeInfo );
963 BaseHandle handle = typeInfo.CreateInstance();
964 DALI_TEST_CHECK( handle );
965 Actor customActor = Actor::DownCast( handle );
966 DALI_TEST_CHECK( customActor );
968 // Try to set an index that hasn't been added
971 customActor.SetProperty( propertyIndex, true );
972 tet_result( TET_FAIL );
974 catch ( DaliException& e )
976 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
979 // Try to get an index that hasn't been added
982 (void) customActor.GetProperty< bool >( propertyIndex );
983 tet_result( TET_FAIL );
985 catch ( DaliException& e )
987 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
994 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
996 TestApplication application;
998 Actor actor = Actor::New();
999 actor.SetSize(100.0f, 100.0f);
1000 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1001 Stage::GetCurrent().Add(actor);
1005 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1006 DALI_TEST_CHECK( type );
1007 BaseHandle handle = type.CreateInstance();
1008 DALI_TEST_CHECK( handle );
1009 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1010 DALI_TEST_CHECK( detector );
1012 // Attach actor to detector
1014 GestureReceivedFunctor functor( data );
1015 detector.Attach(actor);
1017 // Connect to signal through type
1018 handle.ConnectSignal( &application, "long-press-detected", functor );
1020 // Render and notify
1021 application.SendNotification();
1022 application.Render();
1025 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1026 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1027 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1028 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1032 int UtcDaliPanGestureDetectorTypeRegistry(void)
1034 TestApplication application;
1036 Actor actor = Actor::New();
1037 actor.SetSize(100.0f, 100.0f);
1038 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1039 Stage::GetCurrent().Add(actor);
1043 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1044 DALI_TEST_CHECK( type );
1045 BaseHandle handle = type.CreateInstance();
1046 DALI_TEST_CHECK( handle );
1047 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1048 DALI_TEST_CHECK( detector );
1050 // Attach actor to detector
1052 GestureReceivedFunctor functor( data );
1053 detector.Attach(actor);
1055 // Connect to signal through type
1056 handle.ConnectSignal( &application, "pan-detected", functor );
1058 // Render and notify
1059 application.SendNotification();
1060 application.Render();
1063 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1064 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1065 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1066 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1070 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1072 TestApplication application;
1074 Actor actor = Actor::New();
1075 actor.SetSize(100.0f, 100.0f);
1076 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1077 Stage::GetCurrent().Add(actor);
1081 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1082 DALI_TEST_CHECK( type );
1083 BaseHandle handle = type.CreateInstance();
1084 DALI_TEST_CHECK( handle );
1085 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1086 DALI_TEST_CHECK( detector );
1088 // Attach actor to detector
1090 GestureReceivedFunctor functor( data );
1091 detector.Attach(actor);
1093 // Connect to signal through type
1094 handle.ConnectSignal( &application, "pinch-detected", functor );
1096 // Render and notify
1097 application.SendNotification();
1098 application.Render();
1101 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1102 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1106 int UtcDaliTapGestureDetectorTypeRegistry(void)
1108 TestApplication application;
1110 Actor actor = Actor::New();
1111 actor.SetSize(100.0f, 100.0f);
1112 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1113 Stage::GetCurrent().Add(actor);
1117 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1118 DALI_TEST_CHECK( type );
1119 BaseHandle handle = type.CreateInstance();
1120 DALI_TEST_CHECK( handle );
1121 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1122 DALI_TEST_CHECK( detector );
1124 // Attach actor to detector
1126 GestureReceivedFunctor functor( data );
1127 detector.Attach(actor);
1129 // Connect to signal through type
1130 handle.ConnectSignal( &application, "tap-detected", functor );
1132 // Render and notify
1133 application.SendNotification();
1134 application.Render();
1137 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1138 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1139 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1143 int UtcDaliTypeRegistryNamedType(void)
1145 TestApplication application;
1146 TypeRegistry typeRegistry = TypeRegistry::Get();
1148 // Create a normal actor
1149 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1150 DALI_TEST_CHECK( actorHandle );
1151 Actor actor( Actor::DownCast( actorHandle ) );
1152 DALI_TEST_CHECK( actor );
1153 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1155 // Create Named Actor Type
1156 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1157 DALI_TEST_CHECK( namedHandle );
1158 Actor namedActor( Actor::DownCast( namedHandle ) );
1159 DALI_TEST_CHECK( namedActor );
1160 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1162 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );