X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali%2Futc-Dali-Actor.cpp;h=41c8e463effe9aed9d41d4ac07f92de29677dde2;hb=b954037efe7628e1a4b8f121136679778b5a602a;hp=ba048385d7f232c2c13b91024d2afd1aa46c2cc4;hpb=afa7ce29cc34aa631272ce5569b4298aa00490bf;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/automated-tests/src/dali/utc-Dali-Actor.cpp b/automated-tests/src/dali/utc-Dali-Actor.cpp index ba04838..41c8e46 100644 --- a/automated-tests/src/dali/utc-Dali-Actor.cpp +++ b/automated-tests/src/dali/utc-Dali-Actor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -231,6 +231,35 @@ struct VisibilityChangedFunctor VisibilityChangedFunctorData& data; }; + +struct VisibilityChangedVoidFunctor +{ + VisibilityChangedVoidFunctor(bool& signalCalled) + : mSignalCalled( signalCalled ) + { } + + void operator()() + { + mSignalCalled = true; + } + + bool& mSignalCalled; +}; + +struct ChildOrderChangedFunctor +{ + ChildOrderChangedFunctor(bool& signalCalled) + : mSignalCalled( signalCalled ) + { } + + void operator()() + { + mSignalCalled = true; + } + + bool& mSignalCalled; +}; + } // anonymous namespace @@ -623,6 +652,75 @@ int UtcDaliActorGetParent02(void) END_TEST; } +int UtcDaliActorCustomProperty(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); + + float startValue(1.0f); + Property::Index index = actor.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + actor.SetProperty( index, 5.0f ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == 5.0f ); + END_TEST; +} + +int UtcDaliActorCustomPropertyIntToFloat(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); + + float startValue(5.0f); + Property::Index index = actor.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + actor.SetProperty( index, int(1) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == 1.0f ); + END_TEST; +} + +int UtcDaliActorCustomPropertyFloatToInt(void) +{ + TestApplication application; + + Actor actor = Actor::New(); + Stage::GetCurrent().Add( actor ); + + int startValue(5); + Property::Index index = actor.RegisterProperty( "testProperty", startValue ); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == startValue ); + + actor.SetProperty( index, float(1.5) ); + + application.SendNotification(); + application.Render(0); + DALI_TEST_CHECK( actor.GetProperty(index) == 1 ); + END_TEST; +} + int UtcDaliActorSetParentOrigin(void) { TestApplication application; @@ -3947,20 +4045,25 @@ int UtcDaliActorRemoveRendererN(void) } // Clipping test helper functions: -Actor CreateActorWithContent() +Actor CreateActorWithContent( uint32_t width, uint32_t height) { - BufferImage image = BufferImage::New( 16u, 16u ); + BufferImage image = BufferImage::New( width, height ); Actor actor = CreateRenderableActor( image ); // Setup dimensions and position so actor is not skipped by culling. actor.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS ); - actor.SetSize( 16.0f, 16.0f ); + actor.SetSize( width, height ); actor.SetParentOrigin( ParentOrigin::CENTER ); actor.SetAnchorPoint( AnchorPoint::CENTER ); return actor; } +Actor CreateActorWithContent16x16() +{ + return CreateActorWithContent( 16, 16 ); +} + void GenerateTrace( TestApplication& application, TraceCallStack& enabledDisableTrace, TraceCallStack& stencilTrace ) { enabledDisableTrace.Reset(); @@ -4080,7 +4183,7 @@ int UtcDaliActorPropertyClippingActor(void) size_t startIndex = 0u; // Create a clipping actor. - Actor actorDepth1Clip = CreateActorWithContent(); + Actor actorDepth1Clip = CreateActorWithContent16x16(); actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); Stage::GetCurrent().Add( actorDepth1Clip ); @@ -4116,7 +4219,7 @@ int UtcDaliActorPropertyClippingActorEnableThenDisable(void) size_t startIndex = 0u; // Create a clipping actor. - Actor actorDepth1Clip = CreateActorWithContent(); + Actor actorDepth1Clip = CreateActorWithContent16x16(); actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); Stage::GetCurrent().Add( actorDepth1Clip ); @@ -4164,24 +4267,24 @@ int UtcDaliActorPropertyClippingNestedChildren(void) TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace(); // Create a clipping actor. - Actor actorDepth1Clip = CreateActorWithContent(); + Actor actorDepth1Clip = CreateActorWithContent16x16(); actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); Stage::GetCurrent().Add( actorDepth1Clip ); // Create a child actor. - Actor childDepth2 = CreateActorWithContent(); + Actor childDepth2 = CreateActorWithContent16x16(); actorDepth1Clip.Add( childDepth2 ); // Create another clipping actor. - Actor childDepth2Clip = CreateActorWithContent(); + Actor childDepth2Clip = CreateActorWithContent16x16(); childDepth2Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); childDepth2.Add( childDepth2Clip ); // Create another 2 child actors. We do this so 2 nodes will have the same clipping ID. // This tests the sort algorithm. - Actor childDepth3 = CreateActorWithContent(); + Actor childDepth3 = CreateActorWithContent16x16(); childDepth2Clip.Add( childDepth3 ); - Actor childDepth4 = CreateActorWithContent(); + Actor childDepth4 = CreateActorWithContent16x16(); childDepth3.Add( childDepth4 ); // Gather the call trace. @@ -4337,7 +4440,7 @@ int UtcDaliActorPropertyScissorClippingActor(void) const Vector2 imageSize( 16.0f, 16.0f ); // Create a clipping actor. - Actor clippingActorA = CreateActorWithContent(); + Actor clippingActorA = CreateActorWithContent16x16(); // Note: Scissor coords are have flipped Y values compared with DALi's coordinate system. // We choose BOTTOM_LEFT to give us x=0, y=0 starting coordinates for the first test. clippingActorA.SetParentOrigin( ParentOrigin::BOTTOM_LEFT ); @@ -4374,7 +4477,61 @@ int UtcDaliActorPropertyScissorClippingActor(void) END_TEST; } -int UtcDaliActorPropertyScissorClippingActorNested(void) +int UtcDaliActorPropertyScissorClippingActorSiblings(void) +{ + // This test checks that an actor is correctly setup for clipping. + tet_infoline( "Testing Actor::Property::ClippingMode: CLIP_TO_BOUNDING_BOX actors which are siblings" ); + TestApplication application; + + + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace(); + TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace(); + + const Vector2 stageSize( TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT ); + const Vector2 sizeA{ stageSize.width, stageSize.height * 0.25f }; + const Vector2 sizeB{ stageSize.width, stageSize.height * 0.05f }; + + // Create a clipping actors. + Actor clippingActorA = CreateActorWithContent( sizeA.width, sizeA.height ); + Actor clippingActorB = CreateActorWithContent( sizeB.width, sizeB.height ); + + clippingActorA.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + clippingActorA.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + clippingActorA.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + + clippingActorB.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + clippingActorB.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + clippingActorB.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + + clippingActorA.SetPosition( 0.0f, -200.0f, 0.0f ); + clippingActorB.SetPosition( 0.0f, 0.0f, 0.0f ); + + Stage::GetCurrent().Add( clippingActorA ); + Stage::GetCurrent().Add( clippingActorB ); + + // Gather the call trace. + GenerateTrace( application, enabledDisableTrace, scissorTrace ); + + // Check we are writing to the color buffer. + CheckColorMask( glAbstraction, true ); + + // Check scissor test was enabled. + DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST) + + // Check the scissor was set, and the coordinates are correct. + std::stringstream compareParametersString; + + std::string clipA( "0, 500, 480, 200" ); + std::string clipB( "0, 380, 480, 40" ); + + DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", clipA ) ); + DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", clipB ) ); + + END_TEST; +} + +int UtcDaliActorPropertyScissorClippingActorNested01(void) { // This test checks that an actor is correctly setup for clipping. tet_infoline( "Testing Actor::Property::ClippingMode: CLIP_TO_BOUNDING_BOX actor nested" ); @@ -4405,7 +4562,7 @@ int UtcDaliActorPropertyScissorClippingActorNested(void) */ // Create a clipping actor. - Actor clippingActorA = CreateActorWithContent(); + Actor clippingActorA = CreateActorWithContent16x16(); // Note: Scissor coords are have flipped Y values compared with DALi's coordinate system. // We choose BOTTOM_LEFT to give us x=0, y=0 starting coordinates for the first test. clippingActorA.SetParentOrigin( ParentOrigin::CENTER ); @@ -4414,7 +4571,7 @@ int UtcDaliActorPropertyScissorClippingActorNested(void) Stage::GetCurrent().Add( clippingActorA ); // Create a child clipping actor. - Actor clippingActorB = CreateActorWithContent(); + Actor clippingActorB = CreateActorWithContent16x16(); clippingActorB.SetParentOrigin( ParentOrigin::CENTER ); clippingActorB.SetAnchorPoint( AnchorPoint::CENTER ); clippingActorB.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); @@ -4451,6 +4608,95 @@ int UtcDaliActorPropertyScissorClippingActorNested(void) END_TEST; } +int UtcDaliActorPropertyScissorClippingActorNested02(void) +{ + // This test checks that an actor is correctly setup for clipping. + tet_infoline( "Testing Actor::Property::ClippingMode: CLIP_TO_BOUNDING_BOX actor nested" ); + TestApplication application; + + TestGlAbstraction& glAbstraction = application.GetGlAbstraction(); + TraceCallStack& scissorTrace = glAbstraction.GetScissorTrace(); + TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace(); + + /* Create a nest of 2 scissors and siblings of the parent. + + stage + | + ┌─────┐─────┐ + A C D + | | + B E + */ + + const Vector2 stageSize( TestApplication::DEFAULT_SURFACE_WIDTH, TestApplication::DEFAULT_SURFACE_HEIGHT ); + const Vector2 sizeA{ stageSize.width, stageSize.height * 0.25f }; + const Vector2 sizeB{ stageSize.width, stageSize.height * 0.05f }; + const Vector2 sizeC{ stageSize.width, stageSize.height * 0.25f }; + const Vector2 sizeD{ stageSize.width, stageSize.height * 0.25f }; + const Vector2 sizeE{ stageSize.width, stageSize.height * 0.05f }; + + // Create a clipping actors. + Actor clippingActorA = CreateActorWithContent( sizeA.width, sizeA.height ); + Actor clippingActorB = CreateActorWithContent( sizeB.width, sizeB.height ); + Actor clippingActorC = CreateActorWithContent( sizeC.width, sizeC.height ); + Actor clippingActorD = CreateActorWithContent( sizeD.width, sizeD.height ); + Actor clippingActorE = CreateActorWithContent( sizeE.width, sizeE.height ); + + clippingActorA.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + clippingActorA.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + clippingActorA.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + + clippingActorB.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + clippingActorB.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + clippingActorB.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + + clippingActorC.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + clippingActorC.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + clippingActorC.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + + clippingActorD.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + clippingActorD.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + clippingActorD.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_TO_BOUNDING_BOX ); + + clippingActorE.SetParentOrigin( ParentOrigin::CENTER_LEFT ); + clippingActorE.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); + + clippingActorA.SetPosition( 0.0f, -200.0f, 0.0f ); + clippingActorB.SetPosition( 0.0f, 0.0f, 0.0f ); + clippingActorC.SetPosition( 0.0f, 100.0f, 0.0f ); + clippingActorD.SetPosition( 0.0f, 0.0f, 0.0f ); + clippingActorE.SetPosition( 0.0f, 0.0f, 0.0f ); + + Stage::GetCurrent().Add( clippingActorA ); + clippingActorA.Add( clippingActorB ); + Stage::GetCurrent().Add( clippingActorC ); + Stage::GetCurrent().Add( clippingActorD ); + clippingActorD.Add( clippingActorE ); + + // Gather the call trace. + GenerateTrace( application, enabledDisableTrace, scissorTrace ); + + // Check we are writing to the color buffer. + CheckColorMask( glAbstraction, true ); + + // Check scissor test was enabled. + DALI_TEST_CHECK( enabledDisableTrace.FindMethodAndParams( "Enable", "3089" ) ); // 3089 = 0xC11 (GL_SCISSOR_TEST) + + // Check the scissor was set, and the coordinates are correct. + std::string clipA( "0, 500, 480, 200" ); + std::string clipB( "0, 580, 480, 40" ); + std::string clipC( "0, 200, 480, 200" ); + std::string clipD( "0, 300, 480, 200" ); + + DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", clipA ) ); + DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", clipB ) ); + DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", clipC ) ); + DALI_TEST_CHECK( scissorTrace.FindMethodAndParams( "Scissor", clipD ) ); + DALI_TEST_CHECK( scissorTrace.CountMethod( "Scissor" ) == 4 ); // Scissor rect should not be changed in clippingActorE case. So count should be 4. + + END_TEST; +} + int UtcDaliActorPropertyClippingActorWithRendererOverride(void) { // This test checks that an actor with clipping will be ignored if overridden by the Renderer properties. @@ -4462,7 +4708,7 @@ int UtcDaliActorPropertyClippingActorWithRendererOverride(void) TraceCallStack& enabledDisableTrace = glAbstraction.GetEnableDisableTrace(); // Create a clipping actor. - Actor actorDepth1Clip = CreateActorWithContent(); + Actor actorDepth1Clip = CreateActorWithContent16x16(); actorDepth1Clip.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN ); Stage::GetCurrent().Add( actorDepth1Clip ); @@ -4880,6 +5126,10 @@ int UtcDaliActorRaiseAbove(void) actorB.TouchSignal().Connect( TestTouchCallback2 ); actorC.TouchSignal().Connect( TestTouchCallback3 ); + bool orderChangedSignal(false); + ChildOrderChangedFunctor f(orderChangedSignal); + DevelActor::ChildOrderChangedSignal( stage.GetRootLayer() ).Connect( &application, f ) ; + Dali::Integration::Point point; point.SetDeviceId( 1 ); point.SetState( PointState::DOWN ); @@ -4897,10 +5147,12 @@ int UtcDaliActorRaiseAbove(void) tet_printf( "Raise actor B Above Actor C\n" ); + DALI_TEST_EQUALS( orderChangedSignal, false, TEST_LOCATION ); actorB.RaiseAbove( actorC ); + DALI_TEST_EQUALS( orderChangedSignal, true, TEST_LOCATION ); + // Ensure sorting happens at end of Core::ProcessEvents() before next touch application.SendNotification(); - application.ProcessEvent( touchEvent ); DALI_TEST_EQUALS( gTouchCallBackCalled, false, TEST_LOCATION ); @@ -5683,6 +5935,26 @@ int UtcDaliActorGetScreenPosition(void) tet_printf( "Actor World Position ( %f %f ) AnchorPoint::BOTTOM_RIGHT Position x=30 y = 420.0\n", actorWorldPosition.x, actorWorldPosition.y ); tet_printf( "Actor Screen Position( %f %f ) AnchorPoint::BOTTOM_RIGHT Position x=30 y = 420.0 \n", actorScreenPosition.x, actorScreenPosition.y ); + tet_infoline( "UtcDaliActorGetScreenPosition Scale parent and check child's screen position \n" ); + + actorA.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + actorA.SetPosition( 30.0, 30.0 ); + + Actor actorB = Actor::New(); + actorB.SetAnchorPoint( AnchorPoint::TOP_LEFT ); + actorB.SetSize( size2 ); + actorB.SetPosition( 10.f, 10.f ); + actorA.Add( actorB ); + + actorA.SetScale( 2.0f ); + + application.SendNotification(); + application.Render(); + + actorScreenPosition = actorB.GetProperty( DevelActor::Property::SCREEN_POSITION).Get< Vector2 >(); + + DALI_TEST_EQUALS( actorScreenPosition.x, 50lu , TEST_LOCATION ); + DALI_TEST_EQUALS( actorScreenPosition.y, 50lu , TEST_LOCATION ); END_TEST; } @@ -6276,6 +6548,38 @@ int utcDaliActorVisibilityChangeSignalAfterAnimation(void) } +int utcDaliActorVisibilityChangeSignalByName(void) +{ + TestApplication application; + tet_infoline( "Check that the visibility change signal is called when the visibility changes for the actor itself" ); + + Actor actor = Actor::New(); + + bool signalCalled=false; + actor.ConnectSignal( &application, "visibilityChanged", VisibilityChangedVoidFunctor(signalCalled) ); + DALI_TEST_EQUALS( signalCalled, false, TEST_LOCATION ); + actor.SetVisible( false ); + DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION ); + + tet_infoline( "Ensure functor is not called if we attempt to change the visibility to what it already is at" ); + signalCalled = false; + actor.SetVisible( false ); + DALI_TEST_EQUALS( signalCalled, false, TEST_LOCATION ); + + tet_infoline( "Change the visibility using properties, ensure called" ); + actor.SetProperty( Actor::Property::VISIBLE, true ); + DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION ); + + tet_infoline( "Set the visibility to current using properties, ensure not called" ); + signalCalled = false; + + actor.SetProperty( Actor::Property::VISIBLE, true ); + DALI_TEST_EQUALS( signalCalled, false, TEST_LOCATION ); + + END_TEST; +} + + static void LayoutDirectionChanged( Actor actor, LayoutDirection::Type type ) { gLayoutDirectionType = type; @@ -6368,3 +6672,343 @@ int UtcDaliActorLayoutDirectionProperty(void) END_TEST; } + + +struct LayoutDirectionFunctor +{ + LayoutDirectionFunctor(bool& signalCalled) + : mSignalCalled( signalCalled ) + { + } + + LayoutDirectionFunctor(const LayoutDirectionFunctor& rhs) + : mSignalCalled( rhs.mSignalCalled ) + { + } + + void operator()() + { + mSignalCalled = true; + } + + bool& mSignalCalled; +}; + +int UtcDaliActorLayoutDirectionSignal(void) +{ + TestApplication application; + tet_infoline( "Check changing layout direction property sends a signal" ); + + Actor actor = Actor::New(); + DALI_TEST_EQUALS( actor.GetProperty< int >( Actor::Property::LAYOUT_DIRECTION ), static_cast< int >( LayoutDirection::LEFT_TO_RIGHT ), TEST_LOCATION ); + Stage::GetCurrent().Add( actor ); + bool signalCalled = false; + LayoutDirectionFunctor layoutDirectionFunctor(signalCalled); + + actor.ConnectSignal( &application, "layoutDirectionChanged", layoutDirectionFunctor ); + DALI_TEST_EQUALS( signalCalled, false, TEST_LOCATION ); + + // Test that writing the same value doesn't send a signal + actor.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT ); + DALI_TEST_EQUALS( signalCalled, false, TEST_LOCATION ); + + // Test that writing a different value sends the signal + signalCalled = false; + actor.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT ); + DALI_TEST_EQUALS( signalCalled, true, TEST_LOCATION ); + + signalCalled = false; + actor.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT ); + DALI_TEST_EQUALS( signalCalled, false, TEST_LOCATION ); + + END_TEST; +} + +struct ChildAddedSignalCheck +{ + ChildAddedSignalCheck( bool& signalReceived, Actor& childHandle ) + : mSignalReceived( signalReceived ), + mChildHandle( childHandle ) + { + } + + void operator() ( Actor childHandle ) + { + mSignalReceived = true; + mChildHandle = childHandle; + } + void operator() () + { + mSignalReceived = true; + mChildHandle = Actor(); + } + + bool& mSignalReceived; + Actor& mChildHandle; +}; + +int UtcDaliChildAddedSignalP1(void) +{ + TestApplication application; + auto stage = Stage::GetCurrent(); + + bool signalReceived=false; + Actor childActor; + + ChildAddedSignalCheck signal( signalReceived, childActor ); + DevelActor::ChildAddedSignal( stage.GetRootLayer() ).Connect( &application, signal ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + auto actorA = Actor::New(); + stage.Add( actorA ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( childActor, actorA, TEST_LOCATION ); + signalReceived = false; + + auto actorB = Actor::New(); + stage.Add( actorB ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( childActor, actorB, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliChildAddedSignalP2(void) +{ + TestApplication application; + auto stage = Stage::GetCurrent(); + + bool signalReceived=false; + Actor childActor; + + ChildAddedSignalCheck signal( signalReceived, childActor ); + tet_infoline( "Connect to childAdded signal by name" ); + + stage.GetRootLayer().ConnectSignal( &application, "childAdded", signal ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + auto actorA = Actor::New(); + stage.Add( actorA ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + + // Can't test which actor was added; signal signature is void() when connecting via name. + signalReceived = false; + + auto actorB = Actor::New(); + stage.Add( actorB ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliChildAddedSignalN(void) +{ + TestApplication application; + auto stage = Stage::GetCurrent(); + + bool signalReceived=false; + Actor childActor; + + ChildAddedSignalCheck signal( signalReceived, childActor ); + DevelActor::ChildAddedSignal( stage.GetRootLayer() ).Connect( &application, signal ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + auto actorA = Actor::New(); + stage.Add( actorA ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( childActor, actorA, TEST_LOCATION ); + signalReceived = false; + + auto actorB = Actor::New(); + actorA.Add( actorB ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + END_TEST; +} + + +struct ChildRemovedSignalCheck +{ + ChildRemovedSignalCheck( bool& signalReceived, Actor& childHandle ) + : mSignalReceived( signalReceived ), + mChildHandle( childHandle ) + { + } + + void operator() ( Actor childHandle ) + { + mSignalReceived = true; + mChildHandle = childHandle; + } + + void operator() () + { + mSignalReceived = true; + } + + bool& mSignalReceived; + Actor& mChildHandle; +}; + +int UtcDaliChildRemovedSignalP1(void) +{ + TestApplication application; + auto stage = Stage::GetCurrent(); + + bool signalReceived=false; + Actor childActor; + + ChildRemovedSignalCheck signal( signalReceived, childActor ); + DevelActor::ChildRemovedSignal( stage.GetRootLayer() ).Connect( &application, signal ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + auto actorA = Actor::New(); + stage.Add( actorA ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + DALI_TEST_CHECK( !childActor ); + + stage.Remove( actorA ); + DALI_TEST_EQUALS( childActor, actorA, TEST_LOCATION ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + + signalReceived = false; + auto actorB = Actor::New(); + stage.Add( actorB ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + stage.Remove( actorB ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( childActor, actorB, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliChildRemovedSignalP2(void) +{ + TestApplication application; + auto stage = Stage::GetCurrent(); + + bool signalReceived=false; + Actor childActor; + + ChildAddedSignalCheck signal( signalReceived, childActor ); + tet_infoline( "Connect to childRemoved signal by name" ); + + stage.GetRootLayer().ConnectSignal( &application, "childRemoved", signal ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + auto actorA = Actor::New(); + stage.Add( actorA ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + stage.Remove( actorA ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + + signalReceived = false; + auto actorB = Actor::New(); + stage.Add( actorB ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + stage.Remove( actorB ); + DALI_TEST_EQUALS( signalReceived, true, TEST_LOCATION ); + + END_TEST; +} + + +int UtcDaliChildRemovedSignalN(void) +{ + TestApplication application; + auto stage = Stage::GetCurrent(); + + bool signalReceived=false; + Actor childActor; + + ChildRemovedSignalCheck signal( signalReceived, childActor ); + DevelActor::ChildRemovedSignal( stage.GetRootLayer() ).Connect( &application, signal ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + + auto actorA = Actor::New(); + stage.Add( actorA ); + + auto actorB = Actor::New(); + actorA.Add( actorB ); + + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + DALI_TEST_CHECK( ! childActor ); + + actorA.Remove( actorB ); + DALI_TEST_EQUALS( signalReceived, false, TEST_LOCATION ); + END_TEST; +} + + +int UtcDaliChildMovedSignalP(void) +{ + TestApplication application; + auto stage = Stage::GetCurrent(); + + bool addedASignalReceived = false; + bool removedASignalReceived = false; + bool addedBSignalReceived = false; + bool removedBSignalReceived = false; + Actor childActor; + + auto actorA = Actor::New(); + auto actorB = Actor::New(); + stage.Add( actorA ); + stage.Add( actorB ); + + ChildAddedSignalCheck addedSignalA( addedASignalReceived, childActor ); + ChildRemovedSignalCheck removedSignalA( removedASignalReceived, childActor ); + ChildAddedSignalCheck addedSignalB( addedBSignalReceived, childActor ); + ChildRemovedSignalCheck removedSignalB( removedBSignalReceived, childActor ); + + DevelActor::ChildAddedSignal( actorA ).Connect( &application, addedSignalA ); + DevelActor::ChildRemovedSignal( actorA ).Connect( &application, removedSignalA ); + DevelActor::ChildAddedSignal( actorB ).Connect( &application, addedSignalB ); + DevelActor::ChildRemovedSignal( actorB ).Connect( &application, removedSignalB ); + + DALI_TEST_EQUALS( addedASignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( removedASignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( addedBSignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( removedBSignalReceived, false, TEST_LOCATION ); + + // Create a child of A + + auto child = Actor::New(); + actorA.Add( child ); + + DALI_TEST_EQUALS( addedASignalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( removedASignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( addedBSignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( removedBSignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( childActor, child, TEST_LOCATION ); + + // Move child to B: + addedASignalReceived = false; + addedBSignalReceived = false; + removedASignalReceived = false; + removedBSignalReceived = false; + + actorB.Add( child ); // Expect this child to be re-parented + DALI_TEST_EQUALS( addedASignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( removedASignalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( addedBSignalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( removedBSignalReceived, false, TEST_LOCATION ); + + // Move child back to A: + addedASignalReceived = false; + addedBSignalReceived = false; + removedASignalReceived = false; + removedBSignalReceived = false; + + actorA.Add( child ); // Expect this child to be re-parented + DALI_TEST_EQUALS( addedASignalReceived, true, TEST_LOCATION ); + DALI_TEST_EQUALS( removedASignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( addedBSignalReceived, false, TEST_LOCATION ); + DALI_TEST_EQUALS( removedBSignalReceived, true, TEST_LOCATION ); + + + END_TEST; +}