2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22 #include <dali/integration-api/events/long-press-gesture-event.h>
23 #include <dali/integration-api/events/pan-gesture-event.h>
24 #include <dali/integration-api/events/pinch-gesture-event.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali/integration-api/events/hover-event-integ.h>
35 // Stores data that is populated in the callback and will be read by the Test cases
39 : functorCalled( false ),
40 voidFunctorCalled( false ),
41 receivedGesture( Gesture::Clear ),
47 functorCalled = false;
48 voidFunctorCalled = false;
50 receivedGesture.numberOfTouches = 0u;
51 receivedGesture.screenPoint = Vector2(0.0f, 0.0f);
52 receivedGesture.localPoint = Vector2(0.0f, 0.0f);
58 bool voidFunctorCalled;
59 LongPressGesture receivedGesture;
63 // Functor that sets the data when called
64 struct GestureReceivedFunctor
66 GestureReceivedFunctor(SignalData& data) : signalData(data) { }
68 void operator()(Actor actor, LongPressGesture longPress)
70 signalData.functorCalled = true;
71 signalData.receivedGesture = longPress;
72 signalData.pressedActor = actor;
77 signalData.voidFunctorCalled = true;
80 SignalData& signalData;
83 // Generate a LongPressGestureEvent to send to Core
84 Integration::LongPressGestureEvent GenerateLongPress(
86 unsigned int numberOfTouches,
89 Integration::LongPressGestureEvent longPress( state );
91 longPress.numberOfTouches = numberOfTouches;
92 longPress.point = point;
97 // Generate a PanGestureEvent to send to Core
98 Integration::PanGestureEvent GeneratePan(
100 Vector2 previousPosition,
101 Vector2 currentPosition,
102 unsigned long timeDelta,
103 unsigned int numberOfTouches = 1,
104 unsigned int time = 1u)
106 Integration::PanGestureEvent pan(state);
108 pan.previousPosition = previousPosition;
109 pan.currentPosition = currentPosition;
110 pan.timeDelta = timeDelta;
111 pan.numberOfTouches = numberOfTouches;
116 // Generate a PinchGestureEvent to send to Core
117 Integration::PinchGestureEvent GeneratePinch(
118 Gesture::State state,
123 Integration::PinchGestureEvent pinch(state);
127 pinch.centerPoint = centerpoint;
131 // Generate a TapGestureEvent to send to Core
132 Integration::TapGestureEvent GenerateTap(
133 Gesture::State state,
134 unsigned int numberOfTaps,
135 unsigned int numberOfTouches,
138 Integration::TapGestureEvent tap( state );
140 tap.numberOfTaps = numberOfTaps;
141 tap.numberOfTouches = numberOfTouches;
148 // Create function as Init function called
150 static bool CreateCustomInitCalled = false;
151 BaseHandle CreateCustomInit(void)
153 CreateCustomInitCalled = true;
157 static bool CreateCustomNamedInitCalled = false;
158 BaseHandle CreateCustomNamedInit(void)
160 CreateCustomNamedInitCalled = true;
164 const std::string scriptedName("PopupStyle");
165 static TypeRegistration scriptedType( scriptedName, typeid(Dali::CustomActor), CreateCustomNamedInit );
167 // Property Registration
168 bool setPropertyCalled = false;
169 bool getPropertyCalled = false;
170 void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value )
172 setPropertyCalled = true;
174 Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex )
176 getPropertyCalled = true;
177 return Property::Value( true );
182 /*******************************************************************************
186 ******************************************************************************/
189 struct MyTestCustomActor : public CustomActorImpl
191 typedef Signal< void ()> SignalType;
192 typedef Signal< void (float)> SignalTypeFloat;
194 MyTestCustomActor() : CustomActorImpl( true ) // requires touch
197 virtual ~MyTestCustomActor()
200 void ResetCallStack()
204 // From CustomActorImpl
205 virtual void OnStageConnection()
208 virtual void OnStageDisconnection()
211 virtual void OnChildAdd(Actor& child)
214 virtual void OnChildRemove(Actor& child)
217 virtual void OnSizeSet(const Vector3& targetSize)
220 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
223 virtual bool OnTouchEvent(const TouchEvent& event)
227 virtual bool OnHoverEvent(const HoverEvent& event)
231 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
235 virtual bool OnKeyEvent(const KeyEvent& event)
239 virtual void OnKeyInputFocusGained()
242 virtual void OnKeyInputFocusLost()
245 virtual Actor GetChildByAlias(const std::string& actorAlias)
250 virtual Vector3 GetNaturalSize()
252 return Vector3( 0.0f, 0.0f, 0.0f );
262 class MyTestCustomActor : public CustomActor
266 typedef Signal< void ()> SignalType;
267 typedef Signal< void (float)> SignalTypeFloat;
273 static MyTestCustomActor New()
275 Impl::MyTestCustomActor* p = new Impl::MyTestCustomActor;
276 return MyTestCustomActor( *p ); // takes ownership
279 virtual ~MyTestCustomActor()
283 static MyTestCustomActor DownCast( BaseHandle handle )
285 MyTestCustomActor result;
287 CustomActor custom = Dali::CustomActor::DownCast( handle );
290 CustomActorImpl& customImpl = custom.GetImplementation();
292 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
296 result = MyTestCustomActor(customImpl.GetOwner());
303 SignalType& GetCustomSignal()
305 Dali::RefObject& obj = GetImplementation();
306 return static_cast<Impl::MyTestCustomActor&>( obj ).mSignal;
311 MyTestCustomActor(Internal::CustomActor* internal)
312 : CustomActor(internal)
316 MyTestCustomActor( Impl::MyTestCustomActor& impl )
317 : CustomActor( impl )
323 class MyTestCustomActor2 : public CustomActor
331 static MyTestCustomActor2 New()
333 return MyTestCustomActor2(); // takes ownership
336 virtual ~MyTestCustomActor2()
340 static MyTestCustomActor2 DownCast( BaseHandle handle )
342 MyTestCustomActor2 result;
344 CustomActor custom = Dali::CustomActor::DownCast( handle );
347 CustomActorImpl& customImpl = custom.GetImplementation();
349 Impl::MyTestCustomActor* impl = dynamic_cast<Impl::MyTestCustomActor*>(&customImpl);
353 result = MyTestCustomActor2(customImpl.GetOwner());
362 MyTestCustomActor2(Internal::CustomActor* internal)
363 : CustomActor(internal)
367 MyTestCustomActor2( Impl::MyTestCustomActor& impl )
368 : CustomActor( impl )
373 static TypeRegistration customTypeInit( typeid(MyTestCustomActor2), typeid(Dali::CustomActor), CreateCustomInit, true );
376 BaseHandle CreateCustom(void)
378 return MyTestCustomActor::New();
381 static std::string lastSignalConnectionCustom;
383 bool DoConnectSignalCustom( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
385 lastSignalConnectionCustom = signalName;
387 bool connected( true );
389 Dali::BaseHandle handle(object);
390 MyTestCustomActor customActor = MyTestCustomActor::DownCast(handle);
392 if( "sig1" == signalName )
394 customActor.GetCustomSignal().Connect( tracker, functor );
398 // signalName does not match any signal
405 bool DoConnectSignalCustomFailure( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
407 lastSignalConnectionCustom = "failed";
409 return false; // This is supposed to fail
412 struct CustomTestFunctor
416 ++mTotalInstanceCount;
417 ++mCurrentInstanceCount;
420 CustomTestFunctor( const CustomTestFunctor& copyMe )
422 ++mTotalInstanceCount;
423 ++mCurrentInstanceCount;
428 --mCurrentInstanceCount;
436 static int mTotalInstanceCount;
437 static int mCurrentInstanceCount;
438 static int mCallbackCount;
441 int CustomTestFunctor::mTotalInstanceCount = 0;
442 int CustomTestFunctor::mCurrentInstanceCount = 0;
443 int CustomTestFunctor::mCallbackCount = 0;
445 static void ResetFunctorCounts()
447 CustomTestFunctor::mTotalInstanceCount = 0;
448 CustomTestFunctor::mCurrentInstanceCount = 0;
449 CustomTestFunctor::mCallbackCount = 0;
452 static std::string lastActionCustom;
453 bool DoActionCustom(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes)
455 lastActionCustom = actionName;
459 // Custom type registration
460 static TypeRegistration customType1( typeid(MyTestCustomActor), typeid(Dali::CustomActor), CreateCustom );
463 static SignalConnectorType customSignalConnector1( customType1, "sig1", DoConnectSignalCustom );
464 static SignalConnectorType customSignalConnector2( customType1, "sig2", DoConnectSignalCustomFailure );
465 static const int TEST_SIGNAL_COUNT = 2;
468 static TypeAction customAction1( customType1, "act1", DoActionCustom);
469 static const int TEST_ACTION_COUNT = 1;
471 class TestConnectionTracker : public ConnectionTracker
475 TestConnectionTracker()
480 BaseHandle CreateNamedActorType()
482 Actor actor = Actor::New();
483 actor.SetName( "NamedActor" );
487 TypeRegistration namedActorType( "MyNamedActor", typeid(Dali::Actor), CreateNamedActorType );
488 PropertyRegistration namedActorPropertyOne( namedActorType, "prop-name", PROPERTY_REGISTRATION_START_INDEX, Property::BOOLEAN, &SetProperty, &GetProperty );
490 } // Anonymous namespace
493 // Positive test case for a method
494 int UtcDaliTypeRegistryCreateDaliObjects(void)
496 TestApplication application;
498 TypeRegistry registry; // like this for ctor test coverage
499 registry = TypeRegistry::Get();
503 type = registry.GetTypeInfo( "ImageActor" );
504 DALI_TEST_CHECK( type );
505 DALI_TEST_CHECK( type.GetCreator() );
506 DALI_TEST_CHECK( ImageActor::DownCast( type.GetCreator()() ) );
507 ImageActor ia = ImageActor::DownCast(type.CreateInstance());
508 DALI_TEST_CHECK( ia );
509 Stage::GetCurrent().Add( ia );
510 application.Render();
512 type = registry.GetTypeInfo( "TextActor" );
513 DALI_TEST_CHECK( type );
514 TextActor ta = TextActor::DownCast(type.CreateInstance());
515 DALI_TEST_CHECK( ta );
516 Stage::GetCurrent().Add( ta );
517 application.Render();
519 type = registry.GetTypeInfo( "CameraActor" );
520 DALI_TEST_CHECK( type );
521 CameraActor ca = CameraActor::DownCast(type.CreateInstance());
522 DALI_TEST_CHECK( ca );
523 Stage::GetCurrent().Add( ca );
524 application.Render();
526 type = registry.GetTypeInfo( "LightActor" );
527 DALI_TEST_CHECK( type );
528 LightActor la = LightActor::DownCast(type.CreateInstance());
529 DALI_TEST_CHECK( la );
530 Stage::GetCurrent().Add( la );
531 application.Render();
534 type = registry.GetTypeInfo( "Animation" );
535 DALI_TEST_CHECK( type );
536 Animation an = Animation::DownCast(type.CreateInstance());
537 DALI_TEST_CHECK( an );
539 application.Render();
542 type = registry.GetTypeInfo( "ShaderEffect" );
543 DALI_TEST_CHECK( type );
544 ShaderEffect ef = ShaderEffect::DownCast(type.CreateInstance());
545 DALI_TEST_CHECK( ef );
546 application.Render();
551 /*******************************************************************************
553 * Action through the base handle
555 ******************************************************************************/
556 int UtcDaliTypeRegistryActionViaBaseHandle(void)
558 TestApplication application;
562 type = TypeRegistry::Get().GetTypeInfo( "Actor" );
563 DALI_TEST_CHECK( type );
565 BaseHandle hdl = type.CreateInstance();
566 DALI_TEST_CHECK( hdl );
568 Actor a = Actor::DownCast(hdl);
569 DALI_TEST_CHECK( a );
573 application.SendNotification();
574 application.Render(0);
575 DALI_TEST_CHECK(!a.IsVisible());
577 std::vector<Property::Value> attributes;
579 DALI_TEST_CHECK(hdl.DoAction("show", attributes));
581 application.SendNotification();
582 application.Render(0);
583 DALI_TEST_CHECK(a.IsVisible());
585 DALI_TEST_CHECK(!hdl.DoAction("unknown-action", attributes));
589 int UtcDaliTypeRegistryNames(void)
591 TestApplication application;
595 TypeRegistry::NameContainer names = TypeRegistry::Get().GetTypeNames();
597 for(TypeRegistry::NameContainer::iterator iter = names.begin();
598 iter != names.end(); ++iter)
600 type = TypeRegistry::Get().GetTypeInfo( *iter );
601 DALI_TEST_CHECK( type );
607 // Check named and typeid are equivalent
608 int UtcDaliTypeRegistryNameEquivalence(void)
610 TypeInfo named_type = TypeRegistry::Get().GetTypeInfo( "TextActor" );
611 TypeInfo typeinfo_type = TypeRegistry::Get().GetTypeInfo( typeid(Dali::TextActor) );
613 DALI_TEST_CHECK( named_type );
614 DALI_TEST_CHECK( typeinfo_type );
616 DALI_TEST_CHECK( named_type == typeinfo_type );
618 DALI_TEST_CHECK( named_type.GetName() == typeinfo_type.GetName() );
619 DALI_TEST_CHECK( named_type.GetBaseName() == typeinfo_type.GetBaseName() );
625 int UtcDaliTypeRegistryCustomActor(void)
627 ResetFunctorCounts();
629 TestApplication application;
631 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
632 DALI_TEST_CHECK( type );
634 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
635 DALI_TEST_CHECK( baseType );
637 BaseHandle handle = type.CreateInstance();
638 DALI_TEST_CHECK( handle );
640 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
641 DALI_TEST_CHECK( customHandle );
643 TypeInfo::NameContainer names;
644 type.GetActions(names);
645 TypeInfo::NameContainer baseNames;
646 baseType.GetActions(baseNames);
647 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
650 type.GetSignals(names);
653 baseType.GetSignals(baseNames);
655 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
658 TestConnectionTracker tracker;
660 bool connected = handle.ConnectSignal( &tracker, "sig1", CustomTestFunctor() );
661 DALI_TEST_EQUALS( connected, true, TEST_LOCATION );
662 DALI_TEST_CHECK( lastSignalConnectionCustom == "sig1" );
663 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
664 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
666 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
667 customHandle.GetCustomSignal().Emit();
668 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
669 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
670 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 1, TEST_LOCATION );
672 // tracker should automatically disconnect here
673 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
674 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
676 // Test that functor is disconnected
677 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1, TEST_LOCATION );
678 customHandle.GetCustomSignal().Emit();
679 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 1/*not incremented*/, TEST_LOCATION );
680 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
681 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0, TEST_LOCATION );
683 std::vector<Property::Value> attributes;
684 handle.DoAction("act1", attributes);
685 DALI_TEST_CHECK( lastActionCustom == "act1" );
689 int UtcDaliTypeRegistryCustomSignalFailure(void)
691 // Test what happens when signal connnector (DoConnectSignalFailure method) returns false
693 ResetFunctorCounts();
695 TestApplication application;
697 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor" );
698 DALI_TEST_CHECK( type );
700 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( "CustomActor" );
701 DALI_TEST_CHECK( baseType );
703 BaseHandle handle = type.CreateInstance();
704 DALI_TEST_CHECK( handle );
706 MyTestCustomActor customHandle = MyTestCustomActor::DownCast( handle );
707 DALI_TEST_CHECK( customHandle );
709 TypeInfo::NameContainer names;
710 TypeInfo::NameContainer baseNames;
712 type.GetActions(names);
713 baseType.GetActions(baseNames);
715 DALI_TEST_EQUALS( names.size(), TEST_ACTION_COUNT + baseNames.size(), TEST_LOCATION );
720 type.GetSignals(names);
721 baseType.GetSignals(baseNames);
723 DALI_TEST_EQUALS( names.size(), TEST_SIGNAL_COUNT + baseNames.size(), TEST_LOCATION );
726 TestConnectionTracker tracker;
728 bool connected = handle.ConnectSignal( &tracker, "sig2", CustomTestFunctor() );
729 DALI_TEST_EQUALS( connected, false/*This is supposed to fail*/, TEST_LOCATION );
730 DALI_TEST_CHECK( lastSignalConnectionCustom == "failed" );
731 DALI_TEST_EQUALS( CustomTestFunctor::mTotalInstanceCount, 2/*temporary copy + FunctorDelegate copy*/, TEST_LOCATION );
732 DALI_TEST_EQUALS( CustomTestFunctor::mCurrentInstanceCount, 0/*deleted along with FunctorDelegate*/, TEST_LOCATION );
735 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
736 customHandle.GetCustomSignal().Emit();
737 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
739 // tracker should have nothing to disconnect here
742 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0, TEST_LOCATION );
743 customHandle.GetCustomSignal().Emit();
744 DALI_TEST_EQUALS( CustomTestFunctor::mCallbackCount, 0/*never called*/, TEST_LOCATION );
750 int UtcDaliTypeRegistryInitFunctions(void)
752 TestApplication application;
754 DALI_TEST_CHECK( "MyTestCustomActor2" == customTypeInit.RegisteredName() );
756 DALI_TEST_CHECK( true == CreateCustomInitCalled );
757 TypeInfo type = TypeRegistry::Get().GetTypeInfo( "MyTestCustomActor2" );
758 DALI_TEST_CHECK( type );
765 int UtcDaliTypeRegistryNameInitFunctions(void)
767 TestApplication application;
769 DALI_TEST_CHECK( scriptedName == scriptedType.RegisteredName() );
771 TypeInfo baseType = TypeRegistry::Get().GetTypeInfo( scriptedName );
772 DALI_TEST_CHECK( baseType );
774 BaseHandle handle = baseType.CreateInstance();
776 DALI_TEST_CHECK( true == CreateCustomNamedInitCalled );
777 TypeInfo type = TypeRegistry::Get().GetTypeInfo( scriptedName );
778 DALI_TEST_CHECK( type );
783 int UtcDaliPropertyRegistration(void)
785 TestApplication application;
786 TypeRegistry typeRegistry = TypeRegistry::Get();
788 // Check property count before property registration
789 TypeInfo typeInfo = typeRegistry.GetTypeInfo( typeid(MyTestCustomActor) );
790 DALI_TEST_CHECK( typeInfo );
791 BaseHandle handle = typeInfo.CreateInstance();
792 DALI_TEST_CHECK( handle );
793 Actor customActor = Actor::DownCast( handle );
794 DALI_TEST_CHECK( customActor );
795 unsigned int initialPropertyCount( customActor.GetPropertyCount() );
797 std::string propertyName( "prop-1" );
798 int propertyIndex( PROPERTY_REGISTRATION_START_INDEX );
799 Property::Type propertyType( Property::BOOLEAN );
800 PropertyRegistration property1( customType1, propertyName, propertyIndex, propertyType, &SetProperty, &GetProperty );
802 // Check property count after registration
803 unsigned int postRegistrationPropertyCount( customActor.GetPropertyCount() );
804 DALI_TEST_EQUALS( initialPropertyCount + 1u, postRegistrationPropertyCount, TEST_LOCATION );
806 // Add custom property and check property count
807 customActor.RegisterProperty( "custom-prop-1", true );
808 unsigned int customPropertyCount( customActor.GetPropertyCount() );
809 DALI_TEST_EQUALS( postRegistrationPropertyCount + 1u, customPropertyCount, TEST_LOCATION );
811 // Set the property, ensure SetProperty called
812 DALI_TEST_CHECK( !setPropertyCalled );
813 customActor.SetProperty( propertyIndex, false );
814 DALI_TEST_CHECK( setPropertyCalled );
816 // Get the property, ensure GetProperty called
817 DALI_TEST_CHECK( !getPropertyCalled );
818 (void)customActor.GetProperty< bool >( propertyIndex );
819 DALI_TEST_CHECK( getPropertyCalled );
821 // Check the property name
822 DALI_TEST_EQUALS( customActor.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
823 DALI_TEST_EQUALS( typeInfo.GetPropertyName( propertyIndex ), propertyName, TEST_LOCATION );
825 // Check the property index
826 DALI_TEST_EQUALS( customActor.GetPropertyIndex( propertyName ), propertyIndex, TEST_LOCATION );
828 // Check the property type
829 DALI_TEST_EQUALS( customActor.GetPropertyType( propertyIndex ), propertyType, TEST_LOCATION );
831 // Check property count of type-info is 1
832 Property::IndexContainer indices;
833 typeInfo.GetPropertyIndices( indices );
834 DALI_TEST_EQUALS( indices.size(), 1u, TEST_LOCATION );
836 // Ensure indices returned from actor and customActor differ by two
837 Actor actor = Actor::New();
838 actor.GetPropertyIndices( indices );
839 unsigned int actorIndices = indices.size();
840 customActor.GetPropertyIndices( indices );
841 unsigned int customActorIndices = indices.size();
842 DALI_TEST_EQUALS( actorIndices + 2u, customActorIndices, TEST_LOCATION ); // Custom property + registered property
846 int UtcDaliPropertyRegistrationIndexOutOfBounds(void)
848 TestApplication application;
849 TypeRegistry typeRegistry = TypeRegistry::Get();
851 // Attempt to register a property type out-of-bounds index (less than)
854 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_START_INDEX - 1, Property::BOOLEAN, &SetProperty, &GetProperty );
855 tet_result( TET_FAIL );
857 catch ( DaliException& e )
859 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
862 // Attempt to register a property type out-of-bounds index (greater than)
865 PropertyRegistration property1( customType1, "prop-name", PROPERTY_REGISTRATION_MAX_INDEX + 1, Property::BOOLEAN, &SetProperty, &GetProperty );
866 tet_result( TET_FAIL );
868 catch ( DaliException& e )
870 DALI_TEST_ASSERT( e, "( index >= PROPERTY_REGISTRATION_START_INDEX ) && ( index <= PROPERTY_REGISTRATION_MAX_INDEX )", TEST_LOCATION );
875 int UtcDaliPropertyRegistrationFunctions(void)
877 TestApplication application;
878 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 10;
880 // Attempt to register a property without a setter
883 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, &GetProperty );
884 tet_result( TET_PASS );
886 catch ( DaliException& e )
888 tet_result( TET_FAIL );
891 // Attempt to register a property without a getter
894 PropertyRegistration property1( customType1, "prop-name", propertyIndex++, Property::BOOLEAN, NULL, NULL );
895 tet_result( TET_FAIL );
897 catch ( DaliException& e )
899 DALI_TEST_ASSERT( e, "! \"GetProperty", TEST_LOCATION );
904 int UtcDaliPropertyRegistrationAddSameIndex(void)
906 TestApplication application;
907 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 100;
909 // Add one property with a valid property index
910 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
912 // Attempt to add another property with the same index
915 PropertyRegistration property2( customType1, "prop-name-2", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
917 catch ( DaliException& e )
919 DALI_TEST_ASSERT( e, "! \"Property index already added", TEST_LOCATION );
924 int UtcDaliPropertyRegistrationPropertyWritable(void)
926 TestApplication application;
927 int propertyIndex1 = PROPERTY_REGISTRATION_START_INDEX + 200;
928 int propertyIndex2 = PROPERTY_REGISTRATION_START_INDEX + 201;
930 // Add two properties, one with SetProperty, one without
931 PropertyRegistration property1( customType1, "prop-name-readwrite", propertyIndex1, Property::BOOLEAN, &SetProperty, &GetProperty );
932 PropertyRegistration property2( customType1, "prop-name-readonly", propertyIndex2, Property::BOOLEAN, NULL, &GetProperty );
934 // Create custom-actor
935 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
936 DALI_TEST_CHECK( typeInfo );
937 BaseHandle handle = typeInfo.CreateInstance();
938 DALI_TEST_CHECK( handle );
939 Actor customActor = Actor::DownCast( handle );
940 DALI_TEST_CHECK( customActor );
942 // Check whether properties are writable
943 DALI_TEST_CHECK( customActor.IsPropertyWritable( propertyIndex1 ) );
944 DALI_TEST_CHECK( ! customActor.IsPropertyWritable( propertyIndex2 ) );
948 int UtcDaliPropertyRegistrationPropertyAnimatable(void)
950 TestApplication application;
951 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 400;
953 // These properties are not animatable
954 PropertyRegistration property1( customType1, "prop-name", propertyIndex, Property::BOOLEAN, &SetProperty, &GetProperty );
956 // Create custom-actor
957 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
958 DALI_TEST_CHECK( typeInfo );
959 BaseHandle handle = typeInfo.CreateInstance();
960 DALI_TEST_CHECK( handle );
961 Actor customActor = Actor::DownCast( handle );
962 DALI_TEST_CHECK( customActor );
964 // Check if animatable
965 DALI_TEST_CHECK( ! customActor.IsPropertyAnimatable( propertyIndex ) );
969 int UtcDaliPropertyRegistrationInvalidGetAndSet(void)
971 TestApplication application;
972 int propertyIndex = PROPERTY_REGISTRATION_START_INDEX + 2000;
974 // Create custom-actor
975 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( typeid(MyTestCustomActor) );
976 DALI_TEST_CHECK( typeInfo );
977 BaseHandle handle = typeInfo.CreateInstance();
978 DALI_TEST_CHECK( handle );
979 Actor customActor = Actor::DownCast( handle );
980 DALI_TEST_CHECK( customActor );
982 // Try to set an index that hasn't been added
985 customActor.SetProperty( propertyIndex, true );
986 tet_result( TET_FAIL );
988 catch ( DaliException& e )
990 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
993 // Try to get an index that hasn't been added
996 (void) customActor.GetProperty< bool >( propertyIndex );
997 tet_result( TET_FAIL );
999 catch ( DaliException& e )
1001 DALI_TEST_ASSERT( e, "! \"Cannot find property index", TEST_LOCATION );
1008 int UtcDaliLongPressGestureDetectorTypeRegistry(void)
1010 TestApplication application;
1012 Actor actor = Actor::New();
1013 actor.SetSize(100.0f, 100.0f);
1014 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1015 Stage::GetCurrent().Add(actor);
1019 type = TypeRegistry::Get().GetTypeInfo( "LongPressGestureDetector" );
1020 DALI_TEST_CHECK( type );
1021 BaseHandle handle = type.CreateInstance();
1022 DALI_TEST_CHECK( handle );
1023 LongPressGestureDetector detector = LongPressGestureDetector::DownCast( handle );
1024 DALI_TEST_CHECK( detector );
1026 // Attach actor to detector
1028 GestureReceivedFunctor functor( data );
1029 detector.Attach(actor);
1031 // Connect to signal through type
1032 handle.ConnectSignal( &application, "long-press-detected", functor );
1034 // Render and notify
1035 application.SendNotification();
1036 application.Render();
1039 application.ProcessEvent(GenerateLongPress(Gesture::Possible, 1u, Vector2(50.0f, 10.0f)));
1040 application.ProcessEvent(GenerateLongPress(Gesture::Started, 1u, Vector2(50.0f, 10.0f)));
1041 application.ProcessEvent(GenerateLongPress(Gesture::Finished, 1u, Vector2(50.0f, 10.0f)));
1042 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1046 int UtcDaliPanGestureDetectorTypeRegistry(void)
1048 TestApplication application;
1050 Actor actor = Actor::New();
1051 actor.SetSize(100.0f, 100.0f);
1052 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1053 Stage::GetCurrent().Add(actor);
1057 type = TypeRegistry::Get().GetTypeInfo( "PanGestureDetector" );
1058 DALI_TEST_CHECK( type );
1059 BaseHandle handle = type.CreateInstance();
1060 DALI_TEST_CHECK( handle );
1061 PanGestureDetector detector = PanGestureDetector::DownCast( handle );
1062 DALI_TEST_CHECK( detector );
1064 // Attach actor to detector
1066 GestureReceivedFunctor functor( data );
1067 detector.Attach(actor);
1069 // Connect to signal through type
1070 handle.ConnectSignal( &application, "pan-detected", functor );
1072 // Render and notify
1073 application.SendNotification();
1074 application.Render();
1077 application.ProcessEvent(GeneratePan(Gesture::Possible, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1078 application.ProcessEvent(GeneratePan(Gesture::Started, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1079 application.ProcessEvent(GeneratePan(Gesture::Finished, Vector2(10.0f, 20.0f), Vector2(20.0f, 20.0f), 10));
1080 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1084 int UtcDaliPinchGestureDetectorTypeRegistry(void)
1086 TestApplication application;
1088 Actor actor = Actor::New();
1089 actor.SetSize(100.0f, 100.0f);
1090 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1091 Stage::GetCurrent().Add(actor);
1095 type = TypeRegistry::Get().GetTypeInfo( "PinchGestureDetector" );
1096 DALI_TEST_CHECK( type );
1097 BaseHandle handle = type.CreateInstance();
1098 DALI_TEST_CHECK( handle );
1099 PinchGestureDetector detector = PinchGestureDetector::DownCast( handle );
1100 DALI_TEST_CHECK( detector );
1102 // Attach actor to detector
1104 GestureReceivedFunctor functor( data );
1105 detector.Attach(actor);
1107 // Connect to signal through type
1108 handle.ConnectSignal( &application, "pinch-detected", functor );
1110 // Render and notify
1111 application.SendNotification();
1112 application.Render();
1115 application.ProcessEvent(GeneratePinch(Gesture::Started, 10.0f, 50.0f, Vector2(20.0f, 10.0f)));
1116 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1120 int UtcDaliTapGestureDetectorTypeRegistry(void)
1122 TestApplication application;
1124 Actor actor = Actor::New();
1125 actor.SetSize(100.0f, 100.0f);
1126 actor.SetAnchorPoint(AnchorPoint::TOP_LEFT);
1127 Stage::GetCurrent().Add(actor);
1131 type = TypeRegistry::Get().GetTypeInfo( "TapGestureDetector" );
1132 DALI_TEST_CHECK( type );
1133 BaseHandle handle = type.CreateInstance();
1134 DALI_TEST_CHECK( handle );
1135 TapGestureDetector detector = TapGestureDetector::DownCast( handle );
1136 DALI_TEST_CHECK( detector );
1138 // Attach actor to detector
1140 GestureReceivedFunctor functor( data );
1141 detector.Attach(actor);
1143 // Connect to signal through type
1144 handle.ConnectSignal( &application, "tap-detected", functor );
1146 // Render and notify
1147 application.SendNotification();
1148 application.Render();
1151 application.ProcessEvent(GenerateTap(Gesture::Possible, 1u, 1u, Vector2(50.0f, 10.0f)));
1152 application.ProcessEvent(GenerateTap(Gesture::Started, 1u, 1u, Vector2(50.0f, 10.0f)));
1153 DALI_TEST_EQUALS(true, data.voidFunctorCalled, TEST_LOCATION);
1157 int UtcDaliTypeRegistryNamedType(void)
1159 TestApplication application;
1160 TypeRegistry typeRegistry = TypeRegistry::Get();
1162 // Create a normal actor
1163 BaseHandle actorHandle = typeRegistry.GetTypeInfo( "Actor" ).CreateInstance();
1164 DALI_TEST_CHECK( actorHandle );
1165 Actor actor( Actor::DownCast( actorHandle ) );
1166 DALI_TEST_CHECK( actor );
1167 unsigned int actorPropertyCount( actor.GetPropertyCount() );
1169 // Create Named Actor Type
1170 BaseHandle namedHandle = typeRegistry.GetTypeInfo( "MyNamedActor" ).CreateInstance();
1171 DALI_TEST_CHECK( namedHandle );
1172 Actor namedActor( Actor::DownCast( namedHandle ) );
1173 DALI_TEST_CHECK( namedActor );
1174 unsigned int namedActorPropertyCount( namedActor.GetPropertyCount() );
1176 DALI_TEST_CHECK( namedActorPropertyCount > actorPropertyCount );