X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-Popup.cpp;h=990c20abbb72936afc03e266fc2bc283fb8c034f;hb=91b8f5bbaa7d68f5ca8fc94287b8c181a10ba894;hp=29fca22770303ca372228c8ed58d9a3622d3070b;hpb=24b3e26d147f772b0396937442484ff75b327aa7;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Popup.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Popup.cpp index 29fca22..990c20a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Popup.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Popup.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Copyright (c) 2015 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. @@ -15,16 +15,18 @@ * */ -#include #include // Need to override adaptor classes for toolkit test harness, so include // test harness headers before dali headers. #include +#include "dali-toolkit-test-utils/toolkit-timer.h" #include #include +#include #include +#include using namespace Dali; using namespace Toolkit; @@ -49,18 +51,18 @@ static void TestCallback(BaseHandle handle) } const int RENDER_FRAME_INTERVAL = 10; ///< Duration of each frame in ms. -const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation +const int RENDER_ANIMATION_TEST_DURATION_MS = 2000; ///< 2000ms to test animation. const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames. const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f); const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f ); const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f ); /** - * Counts how many descendents root Actor has, including + * Counts how many descendants root Actor has, including * itself. * * @param[in] root The root actor to count from. - * @return The number of descendents including root actor itself. + * @return The number of descendants including root actor itself. */ int DescendentCount(const Actor& root) { @@ -86,30 +88,65 @@ bool HasAncestor(Actor child, Actor ancestor) return (child == ancestor); } +static Toolkit::Popup::DisplayState gPopupState = Toolkit::Popup::HIDDEN; +static bool gTouchedOutside; -static bool gHidden = false; +// Signal callbacks -static void OnPopupHidden() +static void OnPopupTouchedOutside() { - gHidden = true; + gTouchedOutside = true; } -static bool gTouchedOutside; +static void OnPopupShowing() +{ + gPopupState = Toolkit::Popup::SHOWING; +} -static void OnPopupTouchedOutside() +static void OnPopupShown() { - gTouchedOutside = true; + gPopupState = Toolkit::Popup::SHOWN; +} + +static void OnPopupHiding() +{ + gPopupState = Toolkit::Popup::HIDING; } +static void OnPopupHidden() +{ + gPopupState = Toolkit::Popup::HIDDEN; +} + +void ConnectStateSignals( Toolkit::Popup popup ) +{ + popup.ShowingSignal().Connect( &OnPopupShowing ); + popup.ShownSignal().Connect( &OnPopupShown ); + popup.HidingSignal().Connect( &OnPopupHiding ); + popup.HiddenSignal().Connect( &OnPopupHidden ); +} + +void WaitAnimation( ToolkitTestApplication& application ) +{ + // Wait for a while (allow animation to complete), and then check state. + for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ ) + { + application.SendNotification(); + application.Render( RENDER_FRAME_INTERVAL ); + } +} -} // anon namespace +} // Anonymous namespace -int UtcDaliPopupNew(void) +/* + * This test checks popup creation. + */ +int UtcDaliPopupNewP( void ) { ToolkitTestApplication application; - tet_infoline(" UtcDaliPopupNew"); + tet_infoline( " UtcDaliPopupNewP" ); - // Create the Popup actor + // Create the Popup actor. Popup popup; DALI_TEST_CHECK( !popup ); @@ -118,11 +155,11 @@ int UtcDaliPopupNew(void) DALI_TEST_CHECK( popup ); - Popup popup2(popup); + Popup popup2( popup ); DALI_TEST_CHECK( popup2 == popup ); - //Additional check to ensure object is created by checking if it's registered + // Additional check to ensure object is created by checking if it's registered. ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry(); DALI_TEST_CHECK( registry ); @@ -135,9 +172,13 @@ int UtcDaliPopupNew(void) END_TEST; } -int UtcDaliPopupDestructor(void) +/* + * This test checks popup destruction. + */ +int UtcDaliPopupDestructorP( void ) { ToolkitTestApplication application; + tet_infoline( " UtcDaliPopupDestructorP" ); Popup* popup = new Popup(); delete popup; @@ -146,9 +187,10 @@ int UtcDaliPopupDestructor(void) END_TEST; } -int UtcDaliPopupDownCast(void) +int UtcDaliPopupDownCastP(void) { ToolkitTestApplication application; + tet_infoline( " UtcDaliPopupDownCastP" ); Handle handle = Popup::New(); @@ -158,122 +200,292 @@ int UtcDaliPopupDownCast(void) END_TEST; } -int UtcDaliPopoupSetProperty(void) +int UtcDaliPopupSetPropertyP(void) { - tet_infoline("UtcDaliPopoupSetProperty: "); ToolkitTestApplication application; + tet_infoline( " UtcDaliPopupSetProperty" ); Popup popup = Popup::New(); //Test properties std::string testString = "Hello World"; - popup.SetProperty(popup.GetPropertyIndex("title"), testString); - DALI_TEST_EQUALS( testString, popup.GetTitle(), TEST_LOCATION ); + + TextLabel textActorIn = TextLabel::New( testString ); + Property::Map map; + Scripting::CreatePropertyMap( textActorIn, map ); + popup.SetProperty( popup.GetPropertyIndex( "title" ), map ); + TextLabel textActorOut = TextLabel::DownCast( popup.GetTitle() ); + std::string resultText; + DALI_TEST_CHECK( textActorOut.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) ); + DALI_TEST_EQUALS( testString, resultText, TEST_LOCATION ); + END_TEST; } +int UtcDaliPopupSetTitleP(void) +{ + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline( " UtcDaliPopupSetTitleP" ); + + // Create the Popup actor + Popup popup = Popup::New(); + + // Put in show state so it's layer is connected to popup (for ancestor check). + popup.SetDisplayState( Popup::SHOWN ); + + TextLabel titleActor = TextLabel::New(); + titleActor.SetProperty( Toolkit::TextLabel::Property::TEXT, "title" ); + + DALI_TEST_CHECK( !popup.GetTitle() ); + popup.SetTitle( titleActor ); + TextLabel textActor = TextLabel::DownCast( popup.GetTitle() ); + DALI_TEST_CHECK( textActor == titleActor ); + + std::string resultText; + DALI_TEST_CHECK( textActor.GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) ); + + DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "title" ) ); + // verify titleActor is actually inside popup, and not elsewhere on stage, or off even. + DALI_TEST_CHECK( HasAncestor( titleActor, popup ) ); + + TextLabel titleActor2 = TextLabel::New(); + titleActor2.SetProperty( Toolkit::TextLabel::Property::TEXT, "anothertitle" ); + popup.SetTitle( titleActor2 ); + DALI_TEST_CHECK( popup.GetTitle() != titleActor ); + DALI_TEST_CHECK( popup.GetTitle() == titleActor2 ); + DALI_TEST_CHECK( TextLabel::DownCast( popup.GetTitle() ).GetProperty( Toolkit::TextLabel::Property::TEXT ).Get( resultText ) ); + + DALI_TEST_CHECK( ( popup.GetTitle() ) && ( resultText == "anothertitle" ) ); -int UtcDaliPopupSetBackgroundImage(void) + // verify titleActor is actually inside popup, and not elsewhere on stage, or off even. + DALI_TEST_CHECK( HasAncestor( titleActor2, popup ) ); + END_TEST; +} + +int UtcDaliPopupSetTitleN(void) { ToolkitTestApplication application; // Exceptions require ToolkitTestApplication - tet_infoline(" UtcDaliPopupSetBackgroundImage"); + tet_infoline( " UtcDaliPopupSetTitleN" ); + + // Create the Popup actor + Popup popup = Popup::New(); + + TextLabel titleActor = TextLabel::New( "text" ); + popup.SetTitle( titleActor ); + + DALI_TEST_CHECK( popup.GetTitle() ); + + // Set a bad title value. + // Confirm this has disabled the title. + Actor badActor; + popup.SetTitle( badActor ); + + DALI_TEST_CHECK( !popup.GetTitle() ); + + END_TEST; +} + +int UtcDaliPopupSetContentP(void) +{ + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline( " UtcDaliPopupSetContentP" ); // Create the Popup actor Popup popup = Popup::New(); Stage::GetCurrent().Add( popup ); + popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f ); + + // Put in show state so it's layer is connected to popup (for ancestor check). + popup.SetDisplayState( Popup::SHOWN ); - ImageActor image = CreateSolidColorActor( Color::RED ); - DALI_TEST_CHECK( !image.GetParent() ); - popup.SetBackgroundImage(image); - DALI_TEST_CHECK( image.GetParent() ); + PushButton button = PushButton::New(); + DALI_TEST_CHECK( !HasAncestor( button, popup ) ); + popup.SetFooter( button ); + // Hide and then re-show popup to cause button to be rearranged and added to popup. + popup.SetDisplayState( Popup::HIDDEN ); + popup.SetDisplayState( Popup::SHOWN ); + DALI_TEST_CHECK( HasAncestor( button, popup ) ); END_TEST; } -int UtcDaliPopupSetTitle(void) +int UtcDaliPopupSetContentN(void) { - // TODO + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline( " UtcDaliPopupSetContentN" ); + + // Create the Popup actor + Popup popup = Popup::New(); + + TextLabel content = TextLabel::New( "text" ); + popup.SetContent( content ); + + DALI_TEST_CHECK( popup.GetContent() ); + + // Set a bad title value. + Actor badActor; + popup.SetContent( badActor ); + + DALI_TEST_CHECK( !popup.GetContent() ); + END_TEST; } -int UtcDaliPopupAddButton(void) +int UtcDaliPopupSetFooterP(void) { ToolkitTestApplication application; // Exceptions require ToolkitTestApplication - tet_infoline(" UtcDaliPopupAddButton"); + tet_infoline(" UtcDaliPopupSetFooterP"); // Create the Popup actor Popup popup = Popup::New(); Stage::GetCurrent().Add( popup ); + popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f ); // Put in show state so it's layer is connected to popup (for ancestor check). - popup.SetState(Popup::POPUP_SHOW, 0.0f); + popup.SetDisplayState( Popup::SHOWN ); PushButton button = PushButton::New(); DALI_TEST_CHECK( !HasAncestor(button, popup) ); - popup.AddButton(button); + popup.SetFooter( button ); // Hide and then re-show popup to cause button to be rearranged and added to popup. - popup.SetState( Popup::POPUP_HIDE, 0.0f ); - popup.SetState( Popup::POPUP_SHOW, 0.0f ); - DALI_TEST_CHECK( HasAncestor(button, popup) ); + popup.SetDisplayState( Popup::HIDDEN ); + popup.SetDisplayState( Popup::SHOWN ); + DALI_TEST_CHECK( HasAncestor( button, popup ) ); END_TEST; } -int UtcDaliPopupSetState(void) +int UtcDaliPopupSetFooterN(void) { ToolkitTestApplication application; // Exceptions require ToolkitTestApplication - tet_infoline(" UtcDaliPopupSetState"); + tet_infoline(" UtcDaliPopupSetFooterN"); // Create the Popup actor Popup popup = Popup::New(); - Stage::GetCurrent().Add( popup ); - ImageActor backgroundImage = CreateSolidColorActor( Color::RED ); - popup.SetBackgroundImage(backgroundImage); - - // Showing/Hiding popup, results in all child Actors being - // connected/disconnected from the stage. - DALI_TEST_CHECK( !backgroundImage.OnStage() ); - popup.SetState(Popup::POPUP_SHOW, 0.0f); - DALI_TEST_CHECK( backgroundImage.OnStage() ); - DALI_TEST_EQUALS( Popup::POPUP_SHOW, popup.GetState(), TEST_LOCATION ); - popup.SetState(Popup::POPUP_HIDE, 0.0f); - DALI_TEST_CHECK( !backgroundImage.OnStage() ); - DALI_TEST_EQUALS( Popup::POPUP_HIDE, popup.GetState(), TEST_LOCATION ); + PushButton button = PushButton::New(); + popup.SetFooter( button ); + + DALI_TEST_CHECK( popup.GetFooter() ); + + // Set a bad title value. + Actor badActor; + popup.SetFooter( badActor ); + + DALI_TEST_CHECK( !popup.GetFooter() ); + END_TEST; } -int UtcDaliPopupSetStateSlow(void) +int UtcDaliPopupSetControlFooterMultiple(void) { ToolkitTestApplication application; // Exceptions require ToolkitTestApplication - tet_infoline(" UtcDaliPopupSetStateSlow"); + tet_infoline(" UtcDaliPopupSetControlFooterMultiple"); // Create the Popup actor Popup popup = Popup::New(); Stage::GetCurrent().Add( popup ); + popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f ); + // Put in show state so it's layer is connected to popup (for ancestor check). + popup.SetDisplayState( Popup::SHOWN ); + + Actor container = Actor::New(); + PushButton button1 = PushButton::New(); + PushButton button2 = PushButton::New(); + DALI_TEST_CHECK( !HasAncestor( button1, popup ) ); + DALI_TEST_CHECK( !HasAncestor( button2, popup ) ); + container.Add( button1 ); + container.Add( button2 ); + popup.SetFooter( container ); + + // Hide and then re-show popup to cause button to be rearranged and added to popup. + popup.SetDisplayState( Popup::HIDDEN ); + popup.SetDisplayState( Popup::SHOWN ); + DALI_TEST_CHECK( HasAncestor( button1, popup ) ); + DALI_TEST_CHECK( HasAncestor( button2, popup ) ); + END_TEST; +} + +int UtcDaliPopupSetStateP(void) +{ + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline(" UtcDaliPopupSetStateP"); + + // Create the Popup actor + Popup popup = Popup::New(); + + popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 0.0f ); + + DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION ); + + popup.SetDisplayState( Popup::SHOWN ); + DALI_TEST_EQUALS( Popup::SHOWN, popup.GetDisplayState(), TEST_LOCATION ); + + popup.SetDisplayState( Popup::HIDDEN ); + DALI_TEST_EQUALS( Popup::HIDDEN, popup.GetDisplayState(), TEST_LOCATION ); + END_TEST; +} + +int UtcDaliPopupSetStateN(void) +{ + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline(" UtcDaliPopupSetStateN"); + + // Create the Popup actor + Popup popup = Popup::New(); + + popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 1.0f ); + + DALI_TEST_EQUALS( popup.GetDisplayState(), Popup::HIDDEN, TEST_LOCATION ); + + popup.SetDisplayState( Popup::SHOWN ); + DALI_TEST_EQUALS( Popup::SHOWING, popup.GetDisplayState(), TEST_LOCATION ); + + // Test cancelling a show before it has finished. + popup.SetDisplayState( Popup::HIDDEN ); + DALI_TEST_EQUALS( Popup::HIDING, popup.GetDisplayState(), TEST_LOCATION ); + END_TEST; +} + +int UtcDaliPopupDisplayStateSignal(void) +{ + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline( " UtcDaliPopupDisplayStateSignal" ); + + // Create the Popup actor + Popup popup = Popup::New(); + ConnectStateSignals( popup ); + + popup.SetProperty( Toolkit::Popup::Property::ANIMATION_DURATION, 1.0f ); + popup.SetDisplayState( Popup::SHOWN ); + DALI_TEST_EQUALS( Popup::SHOWING, popup.GetDisplayState(), TEST_LOCATION ); + DALI_TEST_EQUALS( gPopupState, Popup::SHOWING, TEST_LOCATION ); - ImageActor backgroundImage = CreateSolidColorActor( Color::RED ); - popup.SetBackgroundImage(backgroundImage); + // Wait for a while (allow animation to complete), and then check state. + for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++) + { + application.SendNotification(); + application.Render( RENDER_FRAME_INTERVAL ); + } - // Showing/Hiding popup, results in all child Actors being - // connected/disconnected from the stage. - DALI_TEST_CHECK( !backgroundImage.OnStage() ); - popup.SetState(Popup::POPUP_SHOW, 0.0f); - DALI_TEST_CHECK( backgroundImage.OnStage() ); + DALI_TEST_EQUALS( Popup::SHOWN, popup.GetDisplayState(), TEST_LOCATION ); + DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION ); // Hide slowly - popup.SetState(Popup::POPUP_HIDE); + popup.SetDisplayState( Popup::HIDDEN ); + DALI_TEST_EQUALS( Popup::HIDING, popup.GetDisplayState(), TEST_LOCATION ); + DALI_TEST_EQUALS( gPopupState, Popup::HIDING, TEST_LOCATION ); // Wait for a while (allow animation to complete), and then check state. - for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++) + for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++) { application.SendNotification(); - application.Render(RENDER_FRAME_INTERVAL); + application.Render( RENDER_FRAME_INTERVAL ); } - DALI_TEST_CHECK( !backgroundImage.OnStage() ); + DALI_TEST_EQUALS( Popup::HIDDEN, popup.GetDisplayState(), TEST_LOCATION ); + DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION ); + END_TEST; } - - int UtcDaliPopupShowHide(void) { ToolkitTestApplication application; // Exceptions require ToolkitTestApplication @@ -281,41 +493,32 @@ int UtcDaliPopupShowHide(void) // Create the Popup actor Popup popup = Popup::New(); - Stage::GetCurrent().Add( popup ); - popup.HiddenSignal().Connect( &OnPopupHidden ); - - ImageActor backgroundImage = CreateSolidColorActor( Color::RED ); - popup.SetBackgroundImage(backgroundImage); + ConnectStateSignals( popup ); + Actor container = Actor::New(); PushButton button1 = PushButton::New(); PushButton button2 = PushButton::New(); - button1.SetSize(DEFAULT_BUTTON_SIZE); - popup.AddButton(button1); - button2.SetSize(DEFAULT_BUTTON_SIZE); - popup.AddButton(button2); - - // Showing/Hiding popup, results in all child Actors being - // connected/disconnected from the stage. - DALI_TEST_CHECK( !backgroundImage.OnStage() ); + button1.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() ); + button2.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() ); + container.Add( button1 ); + container.Add( button2 ); + popup.SetFooter( container ); // Show // Note: in most popup animation implementations show would result in // popup being onstage immediately following Show(). However we can't // assume for all. e.g. If one creates a animation with a delay. - popup.Show(); + popup.SetDisplayState( Popup::SHOWN ); // Wait for a while (allow animation to complete), and then check state. for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++) { application.SendNotification(); - application.Render(RENDER_FRAME_INTERVAL); + application.Render( RENDER_FRAME_INTERVAL ); } - DALI_TEST_CHECK( backgroundImage.OnStage() ); - // Hide - gHidden = false; - popup.Hide(); + popup.SetDisplayState( Popup::HIDDEN ); // Wait for a while (allow animation to complete), and then check state. for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++) @@ -324,12 +527,11 @@ int UtcDaliPopupShowHide(void) application.Render(RENDER_FRAME_INTERVAL); } - DALI_TEST_CHECK( !backgroundImage.OnStage() ); - DALI_TEST_CHECK( gHidden ); + DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION ); END_TEST; } -int UtcDaliPopupShowHideTail(void) +int UtcDaliPopupPropertyTailVisibility(void) { ToolkitTestApplication application; // Exceptions require ToolkitTestApplication tet_infoline(" UtcDaliPopupShowHideTail"); @@ -337,37 +539,48 @@ int UtcDaliPopupShowHideTail(void) // Create the Popup actor Popup popup = Popup::New(); Stage::GetCurrent().Add( popup ); - popup.SetState(Popup::POPUP_SHOW, 0.0f); - popup.HideTail(); - int withoutTailCount = DescendentCount(popup); + popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false ); + popup.SetDisplayState( Popup::SHOWN ); + + int withoutTailCount = DescendentCount( popup ); + + popup.SetDisplayState( Popup::HIDDEN ); - popup.ShowTail(ParentOrigin::BOTTOM_CENTER); - int withTailCount = DescendentCount(popup); + popup.SetProperty( Popup::Property::TAIL_POSITION, "BOTTOM_CENTER" ); + popup.SetProperty( Popup::Property::TAIL_VISIBILITY, true ); + popup.SetDisplayState( Popup::SHOWN ); + + int withTailCount = DescendentCount( popup ); // There should be more actors if the Tail has been added. DALI_TEST_CHECK( withTailCount > withoutTailCount ); // Hide again - popup.HideTail(); + popup.SetDisplayState( Popup::HIDDEN ); + popup.SetProperty( Popup::Property::TAIL_VISIBILITY, false ); + popup.SetDisplayState( Popup::SHOWN ); int withoutTailCount2 = DescendentCount(popup); DALI_TEST_CHECK( withTailCount > withoutTailCount2 ); END_TEST; } -int UtcDaliPopupOnTouchedOutside(void) +int UtcDaliPopupOnTouchedOutsideSignal(void) { ToolkitTestApplication application; // Exceptions require ToolkitTestApplication tet_infoline(" UtcDaliPopupOnTouchedOutside"); // Create the Popup actor Popup popup = Popup::New(); + popup.SetParentOrigin( ParentOrigin::CENTER ); + popup.SetAnchorPoint( ParentOrigin::CENTER ); + popup.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); + popup.SetSize( 50.0f, 50.0f ); + popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f ); Stage::GetCurrent().Add( popup ); - popup.SetParentOrigin(ParentOrigin::CENTER); - popup.SetAnchorPoint(ParentOrigin::CENTER); - popup.SetState(Popup::POPUP_SHOW, 0.0f); popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside ); + popup.SetDisplayState( Popup::SHOWN ); application.SendNotification(); application.Render(); @@ -389,6 +602,113 @@ int UtcDaliPopupOnTouchedOutside(void) application.SendNotification(); application.Render(); - DALI_TEST_CHECK(gTouchedOutside); + DALI_TEST_CHECK( gTouchedOutside ); END_TEST; } + +int UtcDaliPopupPropertyAutoHide(void) +{ + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline( " UtcDaliPopupPropertyAutoHide" ); + + // Create the Popup actor + Popup popup = Popup::New(); + ConnectStateSignals( popup ); + + Actor container = Actor::New(); + PushButton button1 = PushButton::New(); + button1.SetSize( DEFAULT_BUTTON_SIZE.GetVectorXY() ); + container.Add( button1 ); + popup.SetFooter( container ); + + popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f ); + popup.SetProperty( Popup::Property::AUTO_HIDE_DELAY, 200 ); + + Stage::GetCurrent().Add( popup ); + + DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION ); + + // Show + // Note: in most popup animation implementations show would result in + // popup being onstage immediately following Show(). However we can't + // assume for all. e.g. If one creates a animation with a delay. + popup.SetDisplayState( Popup::SHOWN ); + + DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION ); + + for( int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++ ) + { + application.SendNotification(); + application.Render( RENDER_FRAME_INTERVAL ); + } + + // Force the timer used by the popup to expire, + // this will cause the popup to hide automatically. + Dali::Timer timer = Timer::New( 0 ); + timer.MockEmitSignal(); + + DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION ); + + END_TEST; +} + +/* + * This test checks all animation modes to confirm they all trigger all display states at the expected times. + */ +int UtcDaliPopupPropertyAnimationMode(void) +{ + ToolkitTestApplication application; // Exceptions require ToolkitTestApplication + tet_infoline( " UtcDaliPopupPropertyAnimationMode" ); + + // Create the Popup actor + Popup popup = Popup::New(); + ConnectStateSignals( popup ); + popup.SetTitle( TextLabel::New( "Title" ) ); + Stage::GetCurrent().Add( popup ); + + std::string animationModes[] = { "NONE", "ZOOM", "FADE", "CUSTOM" }; + + // Try both default and zero animation duration, as zero has a special case for some animation types. + for( int j = 0; j <= 1; j++ ) + { + // On the second loop, set duration to zero. + if( j == 1 ) + { + popup.SetProperty( Popup::Property::ANIMATION_DURATION, 0.0f ); + } + + // Loop through 4 animation modes. + for( int i = 0; i < 4; i++ ) + { + popup.SetProperty( Popup::Property::ANIMATION_MODE, animationModes[i] ); + + std::string checkMode; + DALI_TEST_CHECK( popup.GetProperty( Popup::Property::ANIMATION_MODE ).Get( checkMode ) ) + + DALI_TEST_EQUALS( checkMode, animationModes[i], TEST_LOCATION ); + + popup.SetDisplayState( Popup::SHOWN ); + + // Only wait for animation if it isn't instant. + if( j == 0 ) + { + DALI_TEST_EQUALS( gPopupState, Popup::SHOWING, TEST_LOCATION ); + WaitAnimation( application ); + } + + DALI_TEST_EQUALS( gPopupState, Popup::SHOWN, TEST_LOCATION ); + popup.SetDisplayState( Popup::HIDDEN ); + + if( j == 0 ) + { + DALI_TEST_EQUALS( gPopupState, Popup::HIDING, TEST_LOCATION ); + WaitAnimation( application ); + } + + DALI_TEST_EQUALS( gPopupState, Popup::HIDDEN, TEST_LOCATION ); + } + } + + END_TEST; +} +