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/dali.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <dali/integration-api/events/long-press-gesture-event.h>
24 #include <dali/integration-api/events/pan-gesture-event.h>
25 #include <dali/integration-api/events/pinch-gesture-event.h>
26 #include <dali/integration-api/events/tap-gesture-event.h>
27 #include <dali/integration-api/events/touch-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 SignalV2< void ()> SignalType;
192 typedef SignalV2< 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 OnMouseWheelEvent(const MouseWheelEvent& event)
231 virtual bool OnKeyEvent(const KeyEvent& event)
235 virtual void OnKeyInputFocusGained()
238 virtual void OnKeyInputFocusLost()
241 virtual Actor GetChildByAlias(const std::string& actorAlias)
253 class MyTestCustomActor : public CustomActor
257 typedef SignalV2< void ()> SignalType;
258 typedef SignalV2< void (float)> SignalTypeFloat;
264 static MyTestCustomActor New()
266 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
267 return MyTestCustomActor( *p ); // takes ownership
270 virtual ~MyTestCustomActor()
274 static MyTestCustomActor DownCast( BaseHandle handle )
276 MyTestCustomActor result;
278 CustomActor custom = Dali::CustomActor::DownCast( handle );
281 CustomActorImpl& customImpl = custom.GetImplementation();
283 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
287 result = MyTestCustomActor(customImpl.GetOwner());
294 SignalType& GetCustomSignal()
296 Dali::RefObject& obj = GetImplementation();
297 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
302 MyTestCustomActor(Internal::CustomActor* internal)
303 : CustomActor(internal)
307 MyTestCustomActor( Impl::MyTestCustomActor& impl )
308 : CustomActor( impl )
314 class MyTestCustomActor2 : public CustomActor
322 static MyTestCustomActor2 New()
324 return MyTestCustomActor2(); // takes ownership
327 virtual ~MyTestCustomActor2()
331 static MyTestCustomActor2 DownCast( BaseHandle handle )
333 MyTestCustomActor2 result;
335 CustomActor custom = Dali::CustomActor::DownCast( handle );
338 CustomActorImpl& customImpl = custom.GetImplementation();
340 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
344 result = MyTestCustomActor2(customImpl.GetOwner());
353 MyTestCustomActor2(Internal::CustomActor* internal)
354 : CustomActor(internal)
358 MyTestCustomActor2( Impl::MyTestCustomActor& impl )
359 : CustomActor( impl )
364 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
367 BaseHandle CreateCustom(void)
369 return MyTestCustomActor::New();
372 static std::string lastSignalConnectionCustom;
374 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
376 lastSignalConnectionCustom = signalName;
378 bool connected( true );
380 Dali::BaseHandle handle(object);
381 MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
383 if( "sig1" == signalName )
385 customActor.GetCustomSignal().Connect( tracker, functor );
389 // signalName does not match any signal
396 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
398 lastSignalConnectionCustom = "failed";
400 return false; // This is supposed to fail
403 struct CustomTestFunctor
407 ++mTotalInstanceCount;
408 ++mCurrentInstanceCount;
411 CustomTestFunctor( const CustomTestFunctor& copyMe )
413 ++mTotalInstanceCount;
414 ++mCurrentInstanceCount;
419 --mCurrentInstanceCount;
427 static int mTotalInstanceCount;
428 static int mCurrentInstanceCount;
429 static int mCallbackCount;
432 int CustomTestFunctor::mTotalInstanceCount = 0;
433 int CustomTestFunctor::mCurrentInstanceCount = 0;
434 int CustomTestFunctor::mCallbackCount = 0;
436 static void ResetFunctorCounts()
438 CustomTestFunctor::mTotalInstanceCount = 0;
439 CustomTestFunctor::mCurrentInstanceCount = 0;
440 CustomTestFunctor::mCallbackCount = 0;
443 static std::string lastActionCustom;
444 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
446 lastActionCustom = actionName;
450 // Custom type registration
451 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
454 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
455 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
456 static const int TEST_SIGNAL_COUNT = 2;
459 static TypeAction customAction1( customType1, "act1", DoActionCustom);
460 static const int TEST_ACTION_COUNT = 1;
462 class TestConnectionTracker : public ConnectionTracker
466 TestConnectionTracker()
471 BaseHandle CreateNamedActorType()
473 Actor actor = Actor::New();
474 actor.SetName( "NamedActor" );
478 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
479 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
481 } // Anonymous namespace
484 // Positive test case for a method
485 int UtcDaliTypeRegistryCreateDaliObjects(void)
487 TestApplication application;
489 TypeRegistry registry; // like this for ctor test coverage
490 registry = TypeRegistry::Get();
494 type = registry.GetTypeInfo( "ImageActor" );
495 DALI_TEST_CHECK( type );
496 DALI_TEST_CHECK( type.GetCreator() );
497 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
498 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
499 DALI_TEST_CHECK( ia );
500 Stage::GetCurrent().Add( ia );
501 application.Render();
503 type = registry.GetTypeInfo( "TextActor" );
504 DALI_TEST_CHECK( type );
505 TextActor ta = TextActor::DownCast(type.CreateInstance());
506 DALI_TEST_CHECK( ta );
507 Stage::GetCurrent().Add( ta );
508 application.Render();
510 type = registry.GetTypeInfo( "CameraActor" );
511 DALI_TEST_CHECK( type );
512 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
513 DALI_TEST_CHECK( ca );
514 Stage::GetCurrent().Add( ca );
515 application.Render();
517 type = registry.GetTypeInfo( "LightActor" );
518 DALI_TEST_CHECK( type );
519 LightActor la = LightActor::DownCast(type.CreateInstance());
520 DALI_TEST_CHECK( la );
521 Stage::GetCurrent().Add( la );
522 application.Render();
525 type = registry.GetTypeInfo( "Animation" );
526 DALI_TEST_CHECK( type );
527 Animation an = Animation::DownCast(type.CreateInstance());
528 DALI_TEST_CHECK( an );
530 application.Render();
533 type = registry.GetTypeInfo( "ShaderEffect" );
534 DALI_TEST_CHECK( type );
535 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
536 DALI_TEST_CHECK( ef );
537 application.Render();
542 /*******************************************************************************
544 * Action through the base handle
546 ******************************************************************************/
547 int UtcDaliTypeRegistryActionViaBaseHandle(void)
549 TestApplication application;
553 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
554 DALI_TEST_CHECK( type );
556 BaseHandle hdl = type.CreateInstance();
557 DALI_TEST_CHECK( hdl );
559 Actor a = Actor::DownCast(hdl);
560 DALI_TEST_CHECK( a );
564 application.SendNotification();
565 application.Render(0);
566 DALI_TEST_CHECK(!a.IsVisible());
568 std::vector<Property::Value> attributes;
570 DALI_TEST_CHECK(hdl.DoAction(Actor::ACTION_SHOW, attributes));
572 application.SendNotification();
573 application.Render(0);
574 DALI_TEST_CHECK(a.IsVisible());
576 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
580 int UtcDaliTypeRegistryNames(void)
582 TestApplication application;
586 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
588 for(TypeRegistry::NameContainer::iterator iter = names.begin();
589 iter != names.end(); ++iter)
591 type = TypeRegistry::Get().GetTypeInfo( *iter );
592 DALI_TEST_CHECK( type );
598 // Check named and typeid are equivalent
599 int UtcDaliTypeRegistryNameEquivalence(void)
601 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
602 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
604 DALI_TEST_CHECK( named_type );
605 DALI_TEST_CHECK( typeinfo_type );
607 DALI_TEST_CHECK( named_type == typeinfo_type );
609 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
610 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
616 int UtcDaliTypeRegistryCustomActor(void)
618 ResetFunctorCounts();
620 TestApplication application;
622 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
623 DALI_TEST_CHECK( type );
625 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
626 DALI_TEST_CHECK( baseType );
628 BaseHandle handle = type.CreateInstance();
629 DALI_TEST_CHECK( handle );
631 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
632 DALI_TEST_CHECK( customHandle );
634 DALI_TEST_EQUALS( type.GetActions().size(), TEST_ACTION_COUNT + baseType.GetActions().size(), TEST_LOCATION );
635 DALI_TEST_EQUALS( type.GetSignals().size(), TEST_SIGNAL_COUNT + baseType.GetSignals().size(), TEST_LOCATION );
638 TestConnectionTracker tracker;
640 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
641 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
642 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
643 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
644 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
646 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
647 customHandle.GetCustomSignal().Emit();
648 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
649 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
650 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
652 // tracker should automatically disconnect here
653 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
654 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
656 // Test that functor is disconnected
657 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
658 customHandle.GetCustomSignal().Emit();
659 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
660 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
661 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
663 std::vector<Property::Value> attributes;
664 handle.DoAction("act1", attributes);
665 DALI_TEST_CHECK( lastActionCustom == "act1" );
669 int UtcDaliTypeRegistryCustomSignalFailure(void)
671 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
673 ResetFunctorCounts();
675 TestApplication application;
677 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
678 DALI_TEST_CHECK( type );
680 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
681 DALI_TEST_CHECK( baseType );
683 BaseHandle handle = type.CreateInstance();
684 DALI_TEST_CHECK( handle );
686 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
687 DALI_TEST_CHECK( customHandle );
689 DALI_TEST_EQUALS( type.GetActions().size(), TEST_ACTION_COUNT + baseType.GetActions().size(), TEST_LOCATION );
690 DALI_TEST_EQUALS( type.GetSignals().size(), TEST_SIGNAL_COUNT + baseType.GetSignals().size(), TEST_LOCATION );
693 TestConnectionTracker tracker;
695 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
696 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
697 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
698 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
699 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
702 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
703 customHandle.GetCustomSignal().Emit();
704 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
706 // tracker should have nothing to disconnect here
709 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
710 customHandle.GetCustomSignal().Emit();
711 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
717 int UtcDaliTypeRegistryInitFunctions(void)
719 TestApplication application;
721 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
723 DALI_TEST_CHECK( true == CreateCustomInitCalled );
724 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
725 DALI_TEST_CHECK( type );
732 int UtcDaliTypeRegistryNameInitFunctions(void)
734 TestApplication application;
736 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
738 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
739 DALI_TEST_CHECK( baseType );
741 BaseHandle handle = baseType.CreateInstance();
743 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
744 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
745 DALI_TEST_CHECK( type );
750 int UtcDaliPropertyRegistration(void)
752 TestApplication application;
753 TypeRegistry typeRegistry = TypeRegistry::Get();
755 // Check property count before property registration
756 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
757 DALI_TEST_CHECK( typeInfo );
758 BaseHandle handle = typeInfo.CreateInstance();
759 DALI_TEST_CHECK( handle );
760 Actor customActor = Actor::DownCast( handle );
761 DALI_TEST_CHECK( customActor );
762 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
764 std::string propertyName( "prop-1" );
765 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
766 Property::Type propertyType( Property::BOOLEAN );
767 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
769 // Check property count after registration
770 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
771 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
773 // Add custom property and check property count
774 customActor.RegisterProperty( "custom-prop-1", true );
775 unsigned int customPropertyCount( customActor.GetPropertyCount() );
776 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
778 // Set the property, ensure SetProperty called
779 DALI_TEST_CHECK( !setPropertyCalled );
780 customActor.SetProperty( propertyIndex, false );
781 DALI_TEST_CHECK( setPropertyCalled );
783 // Get the property, ensure GetProperty called
784 DALI_TEST_CHECK( !getPropertyCalled );
785 (void)customActor.GetProperty< bool >( propertyIndex );
786 DALI_TEST_CHECK( getPropertyCalled );
788 // Check the property name
789 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
790 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
792 // Check the property index
793 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
795 // Check the property type
796 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
798 // Check property count of type-info is 1
799 Property::IndexContainer indices;
800 typeInfo.GetPropertyIndices( indices );
801 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
803 // Ensure indices returned from actor and customActor differ by two
804 Actor actor = Actor::New();
805 actor.GetPropertyIndices( indices );
806 unsigned int actorIndices = indices.size();
807 customActor.GetPropertyIndices( indices );
808 unsigned int customActorIndices = indices.size();
809 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
813 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
815 TestApplication application;
816 TypeRegistry typeRegistry = TypeRegistry::Get();
818 // Attempt to register a property type out-of-bounds index (less than)
821 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
822 tet_result( TET_FAIL );
824 catch ( DaliException& e )
826 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
829 // Attempt to register a property type out-of-bounds index (greater than)
832 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
833 tet_result( TET_FAIL );
835 catch ( DaliException& e )
837 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
842 int UtcDaliPropertyRegistrationFunctions(void)
844 TestApplication application;
845 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
847 // Attempt to register a property without a setter
850 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
851 tet_result( TET_PASS );
853 catch ( DaliException& e )
855 tet_result( TET_FAIL );
858 // Attempt to register a property without a getter
861 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
862 tet_result( TET_FAIL );
864 catch ( DaliException& e )
866 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
871 int UtcDaliPropertyRegistrationAddSameIndex(void)
873 TestApplication application;
874 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
876 // Add one property with a valid property index
877 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
879 // Attempt to add another property with the same index
882 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
884 catch ( DaliException& e )
886 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
891 int UtcDaliPropertyRegistrationPropertyWritable(void)
893 TestApplication application;
894 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
895 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
897 // Add two properties, one with SetProperty, one without
898 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
899 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
901 // Create custom-actor
902 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
903 DALI_TEST_CHECK( typeInfo );
904 BaseHandle handle = typeInfo.CreateInstance();
905 DALI_TEST_CHECK( handle );
906 Actor customActor = Actor::DownCast( handle );
907 DALI_TEST_CHECK( customActor );
909 // Check whether properties are writable
910 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
911 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
915 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
917 TestApplication application;
918 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
920 // These properties are not animatable
921 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
923 // Create custom-actor
924 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
925 DALI_TEST_CHECK( typeInfo );
926 BaseHandle handle = typeInfo.CreateInstance();
927 DALI_TEST_CHECK( handle );
928 Actor customActor = Actor::DownCast( handle );
929 DALI_TEST_CHECK( customActor );
931 // Check if animatable
932 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
936 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
938 TestApplication application;
939 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
941 // Create custom-actor
942 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
943 DALI_TEST_CHECK( typeInfo );
944 BaseHandle handle = typeInfo.CreateInstance();
945 DALI_TEST_CHECK( handle );
946 Actor customActor = Actor::DownCast( handle );
947 DALI_TEST_CHECK( customActor );
949 // Try to set an index that hasn't been added
952 customActor.SetProperty( propertyIndex, true );
953 tet_result( TET_FAIL );
955 catch ( DaliException& e )
957 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
960 // Try to get an index that hasn't been added
963 (void) customActor.GetProperty< bool >( propertyIndex );
964 tet_result( TET_FAIL );
966 catch ( DaliException& e )
968 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
975 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
977 TestApplication application;
979 Actor actor = Actor::New();
980 actor.SetSize(100.0f, 100.0f);
981 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
982 Stage::GetCurrent().Add(actor);
986 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
987 DALI_TEST_CHECK( type );
988 BaseHandle handle = type.CreateInstance();
989 DALI_TEST_CHECK( handle );
990 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
991 DALI_TEST_CHECK( detector );
993 // Attach actor to detector
995 GestureReceivedFunctor functor( data );
996 detector.Attach(actor);
998 // Connect to signal through type
999 handle.ConnectSignal( &application, LongPressGestureDetector::SIGNAL_LONG_PRESS_DETECTED, functor );
1001 // Render and notify
1002 application.SendNotification();
1003 application.Render();
1006 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1007 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1008 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1009 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1013 int UtcDaliPanGestureDetectorTypeRegistry(void)
1015 TestApplication application;
1017 Actor actor = Actor::New();
1018 actor.SetSize(100.0f, 100.0f);
1019 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1020 Stage::GetCurrent().Add(actor);
1024 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1025 DALI_TEST_CHECK( type );
1026 BaseHandle handle = type.CreateInstance();
1027 DALI_TEST_CHECK( handle );
1028 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1029 DALI_TEST_CHECK( detector );
1031 // Attach actor to detector
1033 GestureReceivedFunctor functor( data );
1034 detector.Attach(actor);
1036 // Connect to signal through type
1037 handle.ConnectSignal( &application, PanGestureDetector::SIGNAL_PAN_DETECTED, functor );
1039 // Render and notify
1040 application.SendNotification();
1041 application.Render();
1044 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1045 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1046 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1047 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1051 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1053 TestApplication application;
1055 Actor actor = Actor::New();
1056 actor.SetSize(100.0f, 100.0f);
1057 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1058 Stage::GetCurrent().Add(actor);
1062 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1063 DALI_TEST_CHECK( type );
1064 BaseHandle handle = type.CreateInstance();
1065 DALI_TEST_CHECK( handle );
1066 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1067 DALI_TEST_CHECK( detector );
1069 // Attach actor to detector
1071 GestureReceivedFunctor functor( data );
1072 detector.Attach(actor);
1074 // Connect to signal through type
1075 handle.ConnectSignal( &application, PinchGestureDetector::SIGNAL_PINCH_DETECTED, functor );
1077 // Render and notify
1078 application.SendNotification();
1079 application.Render();
1082 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1083 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1087 int UtcDaliTapGestureDetectorTypeRegistry(void)
1089 TestApplication application;
1091 Actor actor = Actor::New();
1092 actor.SetSize(100.0f, 100.0f);
1093 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1094 Stage::GetCurrent().Add(actor);
1098 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1099 DALI_TEST_CHECK( type );
1100 BaseHandle handle = type.CreateInstance();
1101 DALI_TEST_CHECK( handle );
1102 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1103 DALI_TEST_CHECK( detector );
1105 // Attach actor to detector
1107 GestureReceivedFunctor functor( data );
1108 detector.Attach(actor);
1110 // Connect to signal through type
1111 handle.ConnectSignal( &application, TapGestureDetector::SIGNAL_TAP_DETECTED, functor );
1113 // Render and notify
1114 application.SendNotification();
1115 application.Render();
1118 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1119 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1120 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1124 int UtcDaliTypeRegistryNamedType(void)
1126 TestApplication application;
1127 TypeRegistry typeRegistry = TypeRegistry::Get();
1129 // Create a normal actor
1130 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1131 DALI_TEST_CHECK( actorHandle );
1132 Actor actor( Actor::DownCast( actorHandle ) );
1133 DALI_TEST_CHECK( actor );
1134 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1136 // Create Named Actor Type
1137 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1138 DALI_TEST_CHECK( namedHandle );
1139 Actor namedActor( Actor::DownCast( namedHandle ) );
1140 DALI_TEST_CHECK( namedActor );
1141 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1143 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );