X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-CustomActor.cpp;h=c32c8e7c024a362e679aabaf4661a3236b1e7404;hb=refs%2Fchanges%2F35%2F100235%2F2;hp=3feb24894820c3fae639033c21173ce199d16420;hpb=a417708746ec455d37c85a4bf71368a3982235c6;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-CustomActor.cpp b/automated-tests/src/dali/utc-Dali-CustomActor.cpp index 3feb248..c32c8e7 100644 --- a/automated-tests/src/dali/utc-Dali-CustomActor.cpp +++ b/automated-tests/src/dali/utc-Dali-CustomActor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,8 @@ #include #include -#include +#include +#include #include #include "dali-test-suite-utils/dali-test-suite-utils.h" @@ -42,6 +43,7 @@ namespace { std::vector< std::string > MasterCallStack; +bool gOnRelayout = false; } // anon namespace @@ -55,14 +57,23 @@ struct TestCustomActor : public CustomActorImpl * Constructor */ TestCustomActor() - : CustomActorImpl( true ), // requires touch + : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS | DISABLE_SIZE_NEGOTIATION ) ), mDaliProperty( Property::INVALID_INDEX ), mSizeSet( Vector3::ZERO ), - mTargetSize( Vector3::ZERO ) + mTargetSize( Vector3::ZERO ), + mNego( false ), + mDepth(0u) { - SetRequiresMouseWheelEvents(true); } + TestCustomActor(bool nego) + : CustomActorImpl( ActorFlags( REQUIRES_TOUCH_EVENTS | REQUIRES_WHEEL_EVENTS | REQUIRES_HOVER_EVENTS ) ), + mDaliProperty( Property::INVALID_INDEX ), + mSizeSet( Vector3::ZERO ), + mTargetSize( Vector3::ZERO ), + mNego( nego ) + { + } /** * Destructor */ @@ -109,9 +120,10 @@ struct TestCustomActor : public CustomActorImpl } // From CustomActorImpl - virtual void OnStageConnection() + virtual void OnStageConnection( int depth ) { AddToCallStacks("OnStageConnection"); + mDepth = depth; } virtual void OnStageDisconnection() { @@ -144,9 +156,14 @@ struct TestCustomActor : public CustomActorImpl AddToCallStacks("OnTouchEvent"); return true; } - virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) + virtual bool OnHoverEvent(const HoverEvent& event) + { + AddToCallStacks("OnHoverEvent"); + return true; + } + virtual bool OnWheelEvent(const WheelEvent& event) { - AddToCallStacks("OnMouseWheelEvent"); + AddToCallStacks("OnWheelEvent"); return true; } virtual bool OnKeyEvent(const KeyEvent& event) @@ -162,29 +179,83 @@ struct TestCustomActor : public CustomActorImpl { AddToCallStacks("OnKeyInputFocusLost"); } - virtual Actor GetChildByAlias(const std::string& actorAlias) + virtual Vector3 GetNaturalSize() { - AddToCallStacks("GetChildByAlias"); + return Vector3( 0.0f, 0.0f, 0.0f ); + } - if ("found" == actorAlias) - { - return Actor::New(); - } - else - { - return Actor(); - } + virtual float GetHeightForWidth( float width ) + { + return 0.0f; + } + + virtual float GetWidthForHeight( float height ) + { + return 0.0f; + } + + virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) + { + gOnRelayout = true; + } + + virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) + { + } + + virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) + { + } + + virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension ) + { + return 0.0f; + } + + virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) + { + } + + virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) + { + return false; } void SetDaliProperty(std::string s) { - Self().SetProperty(mDaliProperty, s) ; + Self().SetProperty(mDaliProperty, s); + } + void TestRelayoutRequest() + { + RelayoutRequest(); + } + + float TestGetHeightForWidthBase( float width ) + { + return GetHeightForWidthBase( width ); + } + + float TestGetWidthForHeightBase( float height ) + { + return GetWidthForHeightBase( height ); + } + + float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension ) + { + return CalculateChildSizeBase( child, dimension ); + } + + bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension ) + { + return RelayoutDependentOnChildrenBase( dimension ); } Property::Index mDaliProperty; std::vector< std::string > mMethodsCalled; Vector3 mSizeSet; Vector3 mTargetSize; + bool mNego; + unsigned int mDepth; }; /** @@ -201,10 +272,10 @@ struct TestCustomActorVariant1 : public TestCustomActor } // From CustomActorImpl - virtual void OnStageConnection() + virtual void OnStageConnection( int depth ) { // Chain up first - TestCustomActor::OnStageConnection(); + TestCustomActor::OnStageConnection( depth ); // Add the child Self().Add( mChildToAdd ); @@ -226,10 +297,10 @@ struct TestCustomActorVariant2 : public TestCustomActor } // From CustomActorImpl - virtual void OnStageConnection() + virtual void OnStageConnection( int depth ) { // Chain up first - TestCustomActor::OnStageConnection(); + TestCustomActor::OnStageConnection( depth ); // Remove all the children for( unsigned int i=0, num=Self().GetChildCount(); iInitialize(); + + return custom; + } + static TestCustomActor NewVariant1( Actor childToAdd ) { Impl::TestCustomActor* impl = new Impl::TestCustomActorVariant1( childToAdd ); @@ -609,6 +731,62 @@ public: return GetImpl().mTargetSize; } + virtual Vector3 GetNaturalSize() + { + return Vector3( 0.0f, 0.0f, 0.0f ); + } + + virtual float GetHeightForWidth( float width ) + { + return 0.0f; + } + + virtual float GetWidthForHeight( float height ) + { + return 0.0f; + } + + virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) + { + } + + virtual void OnLayoutNegotiated( float size, Dimension::Type dimension ) + { + } + + virtual void OnCalculateRelayoutSize( Dimension::Type dimension ) + { + } + + void TestRelayoutRequest() + { + GetImpl().TestRelayoutRequest(); + } + + float TestGetHeightForWidthBase( float width ) + { + return GetImpl().TestGetHeightForWidthBase( width ); + } + + float TestGetWidthForHeightBase( float height ) + { + return GetImpl().TestGetWidthForHeightBase( height ); + } + + float TestCalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension ) + { + return GetImpl().TestCalculateChildSizeBase( child, dimension ); + } + + bool TestRelayoutDependentOnChildrenBase( Dimension::Type dimension ) + { + return GetImpl().TestRelayoutDependentOnChildrenBase( dimension ); + } + + unsigned int GetDepth() + { + return GetImpl().mDepth; + } private: TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl ) @@ -617,11 +795,16 @@ private: }; + +using namespace Dali; + BaseHandle CreateActor() { return TestCustomActor::New(); } +Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor ); + } // anon namespace @@ -640,7 +823,7 @@ int UtcDaliCustomActorImplDestructor(void) { TestApplication application; CustomActorImpl* actor = new Impl::TestCustomActor(); - delete actor; + CustomActor customActor( *actor ); // Will automatically unref at the end of this function DALI_TEST_CHECK( true ); END_TEST; @@ -1384,17 +1567,21 @@ int UtcDaliCustomActorRemoveDuringOnChildRemove(void) DALI_TEST_EQUALS( "OnChildRemove", actorA.GetMethodsCalled()[ 2 ], TEST_LOCATION ); // The actorB added to actorA // mContainer will then receive OnChildAdd - DALI_TEST_EQUALS( 2, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION ); + DALI_TEST_EQUALS( 3, (int)(actorB.GetMethodsCalled().size()), TEST_LOCATION ); DALI_TEST_EQUALS( "OnStageConnection", actorB.GetMethodsCalled()[ 0 ], TEST_LOCATION ); - DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION ); + // The derived class are always notified, no matter the child is successfully removed or not + DALI_TEST_EQUALS( "OnChildRemove", actorB.GetMethodsCalled()[ 1 ], TEST_LOCATION ); + DALI_TEST_EQUALS( "OnChildAdd", actorB.GetMethodsCalled()[ 2 ], TEST_LOCATION ); - DALI_TEST_EQUALS( 5, (int)(MasterCallStack.size()), TEST_LOCATION ); + DALI_TEST_EQUALS( 6, (int)(MasterCallStack.size()), TEST_LOCATION ); DALI_TEST_EQUALS( "ActorB: OnStageConnection", MasterCallStack[ 0 ], TEST_LOCATION ); DALI_TEST_EQUALS( "ActorA: OnStageConnection", MasterCallStack[ 1 ], TEST_LOCATION ); DALI_TEST_EQUALS( "ActorA: OnChildAdd", MasterCallStack[ 2 ], TEST_LOCATION ); DALI_TEST_EQUALS( "ActorA: OnChildRemove", MasterCallStack[ 3 ], TEST_LOCATION ); - DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 4 ], TEST_LOCATION ); + // The derived class are always notified, no matter the child is successfully removed or not + DALI_TEST_EQUALS( "ActorB: OnChildRemove", MasterCallStack[ 4 ], TEST_LOCATION ); + DALI_TEST_EQUALS( "ActorB: OnChildAdd", MasterCallStack[ 5 ], TEST_LOCATION ); // Excercise the message passing to Update thread @@ -1412,7 +1599,7 @@ int UtcDaliCustomActorOnPropertySet(void) TestCustomActor custom = TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); - custom.SetDaliProperty("yes") ; + custom.SetDaliProperty("yes"); DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); DALI_TEST_EQUALS( "OnPropertySet", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION ); @@ -1451,18 +1638,12 @@ int UtcDaliCustomActorOnSizeAnimation(void) DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); Animation anim = Animation::New( 1.0f ); - anim.Resize( custom, Vector3( 8.0f, 9.0f, 10.0f ) ); + anim.AnimateTo( Property( custom, Actor::Property::SIZE ), Vector3( 8.0f, 9.0f, 10.0f ) ); DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION ); DALI_TEST_EQUALS( 8.0f, custom.GetTargetSize().width, TEST_LOCATION ); DALI_TEST_EQUALS( 9.0f, custom.GetTargetSize().height, TEST_LOCATION ); DALI_TEST_EQUALS( 10.0f, custom.GetTargetSize().depth, TEST_LOCATION ); - - anim.Resize( custom, 1.0f, 2.0f ); - DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); - DALI_TEST_EQUALS( "OnSizeAnimation", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION ); - DALI_TEST_EQUALS( 1.0f, custom.GetTargetSize().width, TEST_LOCATION ); - DALI_TEST_EQUALS( 2.0f, custom.GetTargetSize().height, TEST_LOCATION ); END_TEST; } @@ -1487,7 +1668,9 @@ int UtcDaliCustomActorOnTouchEvent(void) application.Render(); // simulate a touch event - Dali::TouchPoint point( 0, TouchPoint::Down, 1, 1 ); + Dali::Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 1, 1 ) ); Dali::Integration::TouchEvent event; event.AddPoint( point ); application.ProcessEvent( event ); @@ -1497,10 +1680,10 @@ int UtcDaliCustomActorOnTouchEvent(void) END_TEST; } -int UtcDaliCustomActorOnMouseWheelEvent(void) +int UtcDaliCustomActorOnHoverEvent(void) { TestApplication application; - tet_infoline("Testing Dali::CustomActor::OnMouseWheelEvent()"); + tet_infoline("Testing Dali::CustomActor::OnHoverEvent()"); TestCustomActor custom = TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); @@ -1517,34 +1700,46 @@ int UtcDaliCustomActorOnMouseWheelEvent(void) application.SendNotification(); application.Render(); - // simulate a mouse wheel event - Vector2 screenCoordinates( 10.0f, 10.0f ); - Integration::MouseWheelEvent event(0, 0u, screenCoordinates, 1, 1000u); + // simulate a hover event + Dali::Integration::Point point; + point.SetState( PointState::MOTION ); + point.SetScreenPosition( Vector2( 1, 1 ) ); + Dali::Integration::HoverEvent event; + event.AddPoint( point ); application.ProcessEvent( event ); DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); - DALI_TEST_EQUALS( "OnMouseWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION ); + DALI_TEST_EQUALS( "OnHoverEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION ); END_TEST; } -int UtcDaliCustomActorFindChildByAlias(void) +int UtcDaliCustomActorOnWheelEvent(void) { TestApplication application; - tet_infoline("Testing Dali::CustomActor::GetChildByAlias()"); + tet_infoline("Testing Dali::CustomActor::OnWheelEvent()"); TestCustomActor custom = TestCustomActor::New(); DALI_TEST_EQUALS( 0, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); - custom.Add(Actor::New()); - - DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); + // set size for custom actor + custom.SetSize( 100, 100 ); + // add the custom actor to stage + Stage::GetCurrent().Add( custom ); + custom.ResetCallStack(); - DALI_TEST_CHECK( !custom.FindChildByAlias("not-found") ); + // Render and notify a couple of times + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); - DALI_TEST_EQUALS( 2, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); - DALI_TEST_EQUALS( "GetChildByAlias", custom.GetMethodsCalled()[ 1 ], TEST_LOCATION ); + // simulate a wheel event + Vector2 screenCoordinates( 10.0f, 10.0f ); + Integration::WheelEvent event( Integration::WheelEvent::MOUSE_WHEEL, 0, 0u, screenCoordinates, 1, 1000u ); + application.ProcessEvent( event ); - DALI_TEST_CHECK( custom.FindChildByAlias("found") ); + DALI_TEST_EQUALS( 1, (int)(custom.GetMethodsCalled().size()), TEST_LOCATION ); + DALI_TEST_EQUALS( "OnWheelEvent", custom.GetMethodsCalled()[ 0 ], TEST_LOCATION ); END_TEST; } @@ -1552,12 +1747,12 @@ int UtcDaliCustomActorImplOnPropertySet(void) { TestApplication application; CustomActorImpl* impl = new Impl::SimpleTestCustomActor(); + CustomActor customActor( *impl ); // Will automatically unref at the end of this function impl->OnPropertySet( 0, 0 ); DALI_TEST_CHECK( true ); - delete impl; END_TEST; } @@ -1576,3 +1771,249 @@ int UtcDaliCustomActorGetImplementation(void) DALI_TEST_CHECK( true ); END_TEST; } + +int UtcDaliCustomActorDoAction(void) +{ + TestApplication application; + tet_infoline("Testing Dali::CustomActor::DoAction()"); + + TestCustomActor custom = TestCustomActor::New(); + + BaseHandle customActorObject = custom; + + DALI_TEST_CHECK(customActorObject); + + Property::Map attributes; + + // Check that an invalid command is not performed + DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false); + + // Check that the custom actor is visible + custom.SetVisible(true); + DALI_TEST_CHECK(custom.IsVisible() == true); + + // Check the custom actor performed an action to hide itself + DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + // Check that the custom actor is now invisible + DALI_TEST_CHECK(custom.IsVisible() == false); + + // Check the custom actor performed an action to show itself + DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true); + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + // Check that the custom actor is now visible + DALI_TEST_CHECK(custom.IsVisible() == true); + END_TEST; +} + +int UtcDaliCustomActorCustomActor(void) +{ + Dali::CustomActor customA; + Dali::CustomActor customB( customA ); + + DALI_TEST_CHECK( customA == customB ); + + END_TEST; +} + +int UtcDaliCustomActorImplRelayoutRequest(void) +{ + TestApplication application; + + DALI_TEST_CHECK( gOnRelayout == false ); + + TestCustomActor custom = TestCustomActor::NewNegoSize(); + Stage::GetCurrent().Add(custom); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( gOnRelayout == true ); + gOnRelayout = false; + + custom.TestRelayoutRequest(); + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( gOnRelayout == true ); + + END_TEST; +} + +int UtcDaliCustomActorImplGetHeightForWidthBase(void) +{ + TestApplication application; + TestCustomActor custom = TestCustomActor::NewNegoSize(); + + float width = 300.0f; + float v = 0.0f; + + application.SendNotification(); + application.Render(); + + v = custom.TestGetHeightForWidthBase( width ); + + DALI_TEST_CHECK( v == width ); + + END_TEST; +} + +int UtcDaliCustomActorImplGetWidthForHeightBase(void) +{ + TestApplication application; + TestCustomActor custom = TestCustomActor::NewNegoSize(); + + float height = 300.0f; + float v = 0.0f; + + application.SendNotification(); + application.Render(); + + v = custom.TestGetWidthForHeightBase( height ); + + DALI_TEST_CHECK( v == height ); + + END_TEST; +} + +int UtcDaliCustomActorImplCalculateChildSizeBase(void) +{ + TestApplication application; + TestCustomActor custom = TestCustomActor::NewNegoSize(); + + Actor child = Actor::New(); + child.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS); + child.SetSize(150, 150); + + application.SendNotification(); + application.Render(); + + float v = 9.99f; + v = custom.TestCalculateChildSizeBase( child, Dali::Dimension::ALL_DIMENSIONS ); + DALI_TEST_CHECK( v == 0.0f ); + + END_TEST; +} + +int UtcDaliCustomActorImplRelayoutDependentOnChildrenBase(void) +{ + TestApplication application; + TestCustomActor custom = TestCustomActor::NewNegoSize(); + custom.SetResizePolicy(Dali::ResizePolicy::FIT_TO_CHILDREN, Dali::Dimension::ALL_DIMENSIONS); + + bool v = false; + + v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::ALL_DIMENSIONS ); + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( v == true ); + + custom.SetResizePolicy(Dali::ResizePolicy::FIXED, Dali::Dimension::ALL_DIMENSIONS); + v = custom.TestRelayoutDependentOnChildrenBase( Dali::Dimension::WIDTH ); + application.SendNotification(); + application.Render(); + DALI_TEST_CHECK( v == false ); + + END_TEST; +} + +int UtcDaliCustomActorTypeRegistry(void) +{ + TestApplication application; + + // Register Type + TypeInfo type; + type = TypeRegistry::Get().GetTypeInfo( "CustomActor" ); + DALI_TEST_CHECK( type ); + BaseHandle handle = type.CreateInstance(); + + std::string name; + std::string exception; + + try + { + name = handle.GetTypeName(); + tet_result(TET_FAIL); + } + catch( DaliException& e ) + { + exception = e.condition; + DALI_TEST_EQUALS( exception, "handle && \"BaseObject handle is empty\"", TEST_LOCATION ); + } + + END_TEST; +} + + +int UtcDaliCustomActorGetExtensionP(void) +{ + TestApplication application; + + TestCustomActor custom = TestCustomActor::NewVariant5(); + + DALI_TEST_CHECK( NULL == custom.GetImplementation().GetExtension() ); + + END_TEST; +} + +int UtcDaliCustomActorOnConnectionDepth(void) +{ + TestApplication application; + tet_infoline("Testing Dali::CustomActor::OnStageConnection() hierarchy depth"); + + Stage stage = Stage::GetCurrent(); + + /* Build tree of actors: + * + * Depth + * + * A (parent) 1 + * / \ + * B C 2 + * / \ \ + * D E F 3 + * + * OnStageConnection should return 1 for A, 2 for B and C, and 3 for D, E and F. + */ + + TestCustomActor actorA = TestCustomActor::New(); + stage.Add( actorA ); + + TestCustomActor actorB = TestCustomActor::New(); + actorA.Add( actorB ); + + TestCustomActor actorC = TestCustomActor::New(); + actorA.Add( actorC ); + + TestCustomActor actorD = TestCustomActor::New(); + actorB.Add( actorD ); + + TestCustomActor actorE = TestCustomActor::New(); + actorB.Add( actorE ); + + TestCustomActor actorF = TestCustomActor::New(); + actorC.Add( actorF ); + + // Excercise the message passing to Update thread + application.SendNotification(); + application.Render(); + application.Render(); + + DALI_TEST_EQUALS( 1u, actorA.GetDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 2u, actorB.GetDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 2u, actorC.GetDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 3u, actorD.GetDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 3u, actorE.GetDepth(), TEST_LOCATION ); + DALI_TEST_EQUALS( 3u, actorF.GetDepth(), TEST_LOCATION ); + + END_TEST; +}