X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-Button.cpp;h=ead898d941a48be1f0a39d0227ee10998547596e;hp=990be9cfb8def9ebb0b5c17cbdea9e9cf9c27b79;hb=afe38927f068846eaa02c374430da05f6209a6f9;hpb=06e563f8a982e25a0efe2d91c794657dc8e4bc4a diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp index 990be9c..ead898d 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Button.cpp @@ -50,33 +50,68 @@ static bool ButtonCallback( Button button ) return false; } -Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height ) +struct CallbackFunctor { - BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 ); + CallbackFunctor(bool* callbackFlag) + : mCallbackFlag( callbackFlag ) + { + } + + void operator()() + { + *mCallbackFlag = true; + } + bool* mCallbackFlag; +}; + +Dali::Integration::Point GetPointDownInside() +{ + Dali::Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 240, 400 ) ); + return point; +} + +Dali::Integration::Point GetPointUpInside() +{ + Dali::Integration::Point point; + point.SetState( PointState::UP ); + point.SetScreenPosition( Vector2( 240, 400 ) ); + return point; +} - // Create the image - PixelBuffer* pixbuf = imageData.GetBuffer(); - unsigned int size = width * height; +Dali::Integration::Point GetPointLeave() +{ + Dali::Integration::Point point; + point.SetState( PointState::LEAVE ); + point.SetScreenPosition( Vector2( 240, 400 ) ); + return point; +} - for( size_t i = 0; i < size; i++ ) - { - pixbuf[i*4+0] = 0xFF * color.r; - pixbuf[i*4+1] = 0xFF * color.g; - pixbuf[i*4+2] = 0xFF * color.b; - pixbuf[i*4+3] = 0xFF * color.a; - } +Dali::Integration::Point GetPointEnter() +{ + Dali::Integration::Point point; + point.SetState( PointState::MOTION ); + point.SetScreenPosition( Vector2( 240, 400 ) ); + return point; +} - imageData.Update(); +Dali::Integration::Point GetPointDownOutside() +{ + Dali::Integration::Point point; + point.SetState( PointState::DOWN ); + point.SetScreenPosition( Vector2( 10, 10 ) ); + return point; +} - return imageData; +Dali::Integration::Point GetPointUpOutside() +{ + Dali::Integration::Point point; + point.SetState( PointState::UP ); + point.SetScreenPosition( Vector2( 10, 10 ) ); + return point; } -const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 ); -const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 ); -const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 ); -const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 ); -const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 ); -const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 ); static float ANIMATION_TIME( 0.5f ); } // namespace @@ -346,7 +381,6 @@ int UtcDaliButtonSetUnselectedImageP(void) application.Render(); Vector3 size = pushButton.GetCurrentSize(); - tet_printf( "todor: size: %f,%f", size.width, size.height ); DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION ); DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION ); @@ -396,8 +430,13 @@ int UtcDaliButtonPressedSignalP(void) application.Render(); // connect to its touch signal + ConnectionTracker* testTracker = new ConnectionTracker(); button.PressedSignal().Connect( &ButtonCallback ); button.ReleasedSignal().Connect( &ButtonCallback ); + bool pressedSignal = false; + bool releasedSignal = false; + button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) ); + button.ConnectSignal( testTracker, "released", CallbackFunctor(&releasedSignal) ); Dali::Integration::TouchEvent event; @@ -405,50 +444,56 @@ int UtcDaliButtonPressedSignalP(void) gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownInside ); + event.AddPoint( GetPointDownInside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( gIsCalledButtonCallback ); + DALI_TEST_CHECK( pressedSignal ); gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpInside ); + event.AddPoint( GetPointUpInside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( gIsCalledButtonCallback ); + DALI_TEST_CHECK( releasedSignal ); // Test2. Touch point down and up outside the button. + pressedSignal = false; + releasedSignal = false; gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownOutside ); + event.AddPoint( GetPointDownOutside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( !gIsCalledButtonCallback ); + DALI_TEST_CHECK( !pressedSignal ); gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpOutside ); + event.AddPoint( GetPointUpOutside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( !gIsCalledButtonCallback ); + DALI_TEST_CHECK( !releasedSignal ); // Test3. Touch point down inside and up outside the button. gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownInside ); + event.AddPoint( GetPointDownInside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( gIsCalledButtonCallback ); gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointLeave ); + event.AddPoint( GetPointLeave() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpOutside ); + event.AddPoint( GetPointUpOutside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( gIsCalledButtonCallback ); @@ -457,18 +502,18 @@ int UtcDaliButtonPressedSignalP(void) gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownOutside ); + event.AddPoint( GetPointDownOutside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( !gIsCalledButtonCallback ); gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointEnter ); + event.AddPoint( GetPointEnter() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpInside ); + event.AddPoint( GetPointUpInside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( !gIsCalledButtonCallback ); @@ -493,6 +538,9 @@ int UtcDaliButtonClickedSignalP(void) // connect to its touch signal button.ClickedSignal().Connect( &ButtonCallback ); + bool clickedSignal = false; + ConnectionTracker* testTracker = new ConnectionTracker(); + button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) ); Dali::Integration::TouchEvent event; @@ -500,61 +548,68 @@ int UtcDaliButtonClickedSignalP(void) gIsCalledButtonCallback = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownInside ); + event.AddPoint( GetPointDownInside() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpInside ); + event.AddPoint( GetPointUpInside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( gIsCalledButtonCallback ); + DALI_TEST_CHECK( clickedSignal ); // Test2. Touch point down and up outside the button. gIsCalledButtonCallback = false; + clickedSignal = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownOutside ); + event.AddPoint( GetPointDownOutside() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpOutside ); + event.AddPoint( GetPointUpOutside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( !gIsCalledButtonCallback ); + DALI_TEST_CHECK( !clickedSignal ); // Test3. Touch point down inside and up outside the button. gIsCalledButtonCallback = false; + clickedSignal = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownInside ); + event.AddPoint( GetPointDownInside() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointLeave ); + event.AddPoint( GetPointLeave() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpOutside ); + event.AddPoint( GetPointUpOutside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( !gIsCalledButtonCallback ); + DALI_TEST_CHECK( !clickedSignal ); // Test4. Touch point down outside and up inside the button. gIsCalledButtonCallback = false; + clickedSignal = false; event = Dali::Integration::TouchEvent(); - event.AddPoint( pointDownOutside ); + event.AddPoint( GetPointDownOutside() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointEnter ); + event.AddPoint( GetPointEnter() ); application.ProcessEvent( event ); event = Dali::Integration::TouchEvent(); - event.AddPoint( pointUpInside ); + event.AddPoint( GetPointUpInside() ); application.ProcessEvent( event ); DALI_TEST_CHECK( !gIsCalledButtonCallback ); + DALI_TEST_CHECK( !clickedSignal ); END_TEST; } @@ -573,16 +628,23 @@ int UtcDaliButtonStateChangedSignalP(void) // connect to its signal button.StateChangedSignal().Connect( &ButtonCallback ); + bool stateChangedSignal = false; + ConnectionTracker* testTracker = new ConnectionTracker(); + button.ConnectSignal( testTracker, "stateChanged", CallbackFunctor(&stateChangedSignal) ); gIsCalledButtonCallback = false; button.SetSelected( true ); DALI_TEST_CHECK( gIsCalledButtonCallback ); + DALI_TEST_CHECK( stateChangedSignal ); gIsCalledButtonCallback = false; + stateChangedSignal = false; + button.SetSelected( false ); DALI_TEST_CHECK( gIsCalledButtonCallback ); + DALI_TEST_CHECK( stateChangedSignal ); END_TEST; } @@ -623,3 +685,325 @@ int UtcDaliButtonSize(void) DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION ); END_TEST; } + +int UtcDaliButtonSetSelectedBackgroundImageP(void) +{ + ToolkitTestApplication application; + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + try + { + button.SetSelectedBackgroundImage( "TestImage.jpg"); + DALI_TEST_CHECK( true ); + } + catch(...) + { + DALI_TEST_CHECK( false ); + } + + END_TEST; +} + +int UtcDaliButtonSetSelectedBackgroundImageN(void) +{ + ToolkitTestApplication application; + + PushButton button; + + try + { + button.SetSelectedBackgroundImage( "TestImage.jpg"); + DALI_TEST_CHECK( false ); + } + catch(...) + { + DALI_TEST_CHECK( true ); + } + + END_TEST; +} + +int UtcDaliButtonSetDisabledImageP(void) +{ + ToolkitTestApplication application; + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + try + { + button.SetDisabledImage( "TestImage.jpg"); + DALI_TEST_CHECK( true ); + } + catch(...) + { + DALI_TEST_CHECK( false ); + } + + END_TEST; +} + +int UtcDaliButtonSetDisabledImageN(void) +{ + ToolkitTestApplication application; + + PushButton button; + + try + { + button.SetDisabledImage( "TestImage.jpg"); + DALI_TEST_CHECK( false ); + } + catch(...) + { + DALI_TEST_CHECK( true ); + } + + END_TEST; +} + +int UtcDaliButtonSetDisabledSelectedImageP(void) +{ + ToolkitTestApplication application; + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + try + { + button.SetDisabledSelectedImage( "TestImage.jpg"); + DALI_TEST_CHECK( true ); + } + catch(...) + { + DALI_TEST_CHECK( false ); + } + + END_TEST; +} + +int UtcDaliButtonSetDisabledSelectedImageN(void) +{ + ToolkitTestApplication application; + + PushButton button; + + try + { + button.SetDisabledSelectedImage( "TestImage.jpg"); + DALI_TEST_CHECK( false ); + } + catch(...) + { + DALI_TEST_CHECK( true ); + } + + END_TEST; +} + +int UtcDaliButtonSetLabelP(void) +{ + ToolkitTestApplication application; + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + try + { + button.SetLabel( TextLabel::New("Hello") ); + DALI_TEST_CHECK( true ); + } + catch(...) + { + DALI_TEST_CHECK( false ); + } + + END_TEST; +} + +int UtcDaliButtonSetLabelN(void) +{ + ToolkitTestApplication application; + + PushButton button; + + try + { + button.SetLabel( TextLabel::New("Hello") ); + DALI_TEST_CHECK( false ); + } + catch(...) + { + DALI_TEST_CHECK( true ); + } + + END_TEST; +} + +int UtcDaliButtonSetButtonImageP(void) +{ + ToolkitTestApplication application; + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + try + { + button.SetButtonImage( CreateBufferImage( 10, 10, Color::WHITE ) ); + DALI_TEST_CHECK( ImageView::DownCast( button.GetButtonImage() ) ); + } + catch(...) + { + DALI_TEST_CHECK( false ); + } + + END_TEST; +} + +int UtcDaliButtonSetButtonImageN(void) +{ + ToolkitTestApplication application; + + PushButton button; + + try + { + button.SetButtonImage( CreateBufferImage( 10, 10, Color::WHITE ) ); + DALI_TEST_CHECK( false ); + } + catch(...) + { + DALI_TEST_CHECK( true ); + } + + END_TEST; +} + +int UtcDaliButtonSetSelectedImageWithImageP(void) +{ + ToolkitTestApplication application; + + PushButton button = PushButton::New(); + Stage::GetCurrent().Add( button ); + + try + { + button.SetSelectedImage( CreateBufferImage( 10, 10, Color::WHITE ) ); + DALI_TEST_CHECK( ImageView::DownCast( button.GetSelectedImage() ) ); + } + catch(...) + { + DALI_TEST_CHECK( false ); + } + + END_TEST; +} + +int UtcDaliButtonSetSelectedImageWithImageN(void) +{ + ToolkitTestApplication application; + + PushButton button; + + try + { + button.SetSelectedImage( CreateBufferImage( 10, 10, Color::WHITE ) ); + DALI_TEST_CHECK( false ); + } + catch(...) + { + DALI_TEST_CHECK( true ); + } + + END_TEST; +} + +int UtcDaliButtonSetSelectedColorP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetSelectedColorP"); + + PushButton pushButton = PushButton::New(); + Stage::GetCurrent().Add( pushButton ); + + application.SendNotification(); + application.Render(); + + const Vector4 SET_COLOR = Color::BLUE; + + pushButton.SetSize( Vector2( 20.0f, 20.0f ) ); + pushButton.SetProperty( Button::Property::SELECTED_COLOR, SET_COLOR ); + + application.SendNotification(); + application.Render(); + + Vector4 color = pushButton.GetProperty( Button::Property::SELECTED_COLOR ); + + DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliButtonSetUnSelectedColorP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetUnSelectedColorP"); + + PushButton pushButton = PushButton::New(); + Stage::GetCurrent().Add( pushButton ); + + application.SendNotification(); + application.Render(); + + const Vector4 SET_COLOR = Color::BLUE; + + pushButton.SetSize( Vector2( 20.0f, 20.0f ) ); + pushButton.SetProperty( Button::Property::UNSELECTED_COLOR, SET_COLOR ); + + application.SendNotification(); + application.Render(); + + Vector4 color = pushButton.GetProperty( Button::Property::UNSELECTED_COLOR ); + + DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliButtonResetSelectedColorP(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliButtonSetSelectedColorP"); + + PushButton pushButton = PushButton::New(); + Stage::GetCurrent().Add( pushButton ); + + application.SendNotification(); + application.Render(); + + const Vector4 FIRST_COLOR = Color::BLUE; + const Vector4 SECOND_COLOR = Color::BLUE; + + pushButton.SetSize( Vector2( 20.0f, 20.0f ) ); + pushButton.SetProperty( Button::Property::SELECTED_COLOR, FIRST_COLOR ); + + application.SendNotification(); + application.Render(); + + Vector4 color = pushButton.GetProperty( Button::Property::SELECTED_COLOR ); + + DALI_TEST_EQUALS( color, FIRST_COLOR, TEST_LOCATION ); + + pushButton.SetProperty( Button::Property::SELECTED_COLOR, SECOND_COLOR ); + + application.SendNotification(); + application.Render(); + + color = pushButton.GetProperty( Button::Property::SELECTED_COLOR ); + + DALI_TEST_EQUALS( color, SECOND_COLOR, TEST_LOCATION ); + + END_TEST; +}