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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali-toolkit/dali-toolkit.h>
29 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
34 using namespace Toolkit;
36 void utc_dali_toolkit_pushbutton_startup(void)
38 test_return_value = TET_UNDEF;
41 void utc_dali_toolkit_pushbutton_cleanup(void)
43 test_return_value = TET_PASS;
48 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
50 static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2( 240, 400 );
51 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3( 200, 360, 0 );
52 static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size( 100, 100 );
54 static bool gPushButtonSelectedState = false;
55 bool PushButtonSelected( Button button )
57 gPushButtonSelectedState = button.IsSelected();
61 static bool gPushButtonPressed = false;
63 static bool PushButtonPressed( Button button )
65 gPushButtonPressed = true;
69 static bool gPushButtonReleased = false;
71 static bool PushButtonReleased( Button button )
73 gPushButtonReleased = true;
77 static bool gPushButtonClicked = false;
79 static bool PushButtonClicked( Button button )
81 gPushButtonClicked = true;
82 return gPushButtonClicked;
85 Dali::Integration::Point GetPointDownInside()
87 Dali::Integration::Point point;
88 point.SetState( PointState::DOWN );
89 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
93 Dali::Integration::Point GetPointUpInside()
95 Dali::Integration::Point point;
96 point.SetState( PointState::UP );
97 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
101 Dali::Integration::Point GetPointLeave()
103 Dali::Integration::Point point;
104 point.SetState( PointState::LEAVE );
105 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
109 Dali::Integration::Point GetPointEnter()
111 Dali::Integration::Point point;
112 point.SetState( PointState::MOTION );
113 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
117 Dali::Integration::Point GetPointDownOutside()
119 Dali::Integration::Point point;
120 point.SetState( PointState::DOWN );
121 point.SetScreenPosition( Vector2( 10, 10 ) );
125 Dali::Integration::Point GetPointUpOutside()
127 Dali::Integration::Point point;
128 point.SetState( PointState::UP );
129 point.SetScreenPosition( Vector2( 10, 10 ) );
133 // Set up the position of the button for the default test events
134 void SetupButtonForTestTouchEvents( ToolkitTestApplication& application, Button& button, bool useDefaultImages )
136 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
137 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
138 button.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
139 if ( useDefaultImages )
141 const Vector2 TEST_IMAGE_SIZE = Vector2( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
142 TestPlatformAbstraction& platform = application.GetPlatform();
143 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
144 button.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
145 button.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
151 int UtcDaliPushButtonConstructorP(void)
153 TestApplication application;
157 DALI_TEST_CHECK( !button );
161 int UtcDaliPushButtonCopyConstructorP(void)
163 TestApplication application;
165 // Initialize an object, ref count == 1
166 PushButton button = PushButton::New();
168 PushButton copy( button );
169 DALI_TEST_CHECK( copy );
173 int UtcDaliPushButtonAssignmentOperatorP(void)
175 TestApplication application;
177 PushButton button = PushButton::New();
179 PushButton copy( button );
180 DALI_TEST_CHECK( copy );
182 DALI_TEST_CHECK( button == copy );
186 int UtcDaliPushButtonNewP(void)
188 TestApplication application;
190 PushButton button = PushButton::New();
192 DALI_TEST_CHECK( button );
196 int UtcDaliPushButtonDownCastP(void)
198 TestApplication application;
200 PushButton button = PushButton::New();
202 BaseHandle object(button);
204 PushButton button2 = PushButton::DownCast( object );
205 DALI_TEST_CHECK(button2);
207 PushButton button3 = DownCast< PushButton >(object);
208 DALI_TEST_CHECK(button3);
212 int UtcDaliPushButtonDownCastN(void)
214 TestApplication application;
216 BaseHandle unInitializedObject;
218 PushButton button1 = PushButton::DownCast( unInitializedObject );
219 DALI_TEST_CHECK( !button1 );
221 PushButton button2 = DownCast< PushButton >( unInitializedObject );
222 DALI_TEST_CHECK( !button2 );
226 int UtcDaliPushButtonSetGetAutoRepeating(void)
228 ToolkitTestApplication application;
229 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
231 PushButton pushButton = PushButton::New();
233 pushButton.SetAutoRepeating( true );
235 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
237 pushButton.SetAutoRepeating( false );
239 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
241 pushButton.SetAutoRepeating( true );
243 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
247 int UtcDaliPushButtonSetAutoRepeating(void)
249 ToolkitTestApplication application;
250 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
251 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
252 PushButton pushButton = PushButton::New();
254 const bool INITIAL_TOGGLE_VALUE = true;
255 const bool INITIAL_SELECTED_VALUE = true;
257 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
258 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
260 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
261 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
263 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
265 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
270 int UtcDaliPushButtonSetGetTogglableButton(void)
272 ToolkitTestApplication application;
273 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
275 PushButton pushButton = PushButton::New();
277 pushButton.SetTogglableButton( true );
279 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
281 pushButton.SetTogglableButton( false );
283 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
285 pushButton.SetTogglableButton( true );
287 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
291 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
293 ToolkitTestApplication application;
294 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
296 PushButton pushButton = PushButton::New();
298 pushButton.SetAutoRepeating( true );
299 pushButton.SetTogglableButton( true );
301 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
302 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
304 pushButton.SetTogglableButton( true );
305 pushButton.SetAutoRepeating( true );
307 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
308 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
312 int UtcDaliPushButtonSetGetSelected01(void)
314 ToolkitTestApplication application;
315 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
317 PushButton pushButton = PushButton::New();
319 pushButton.SetTogglableButton( true );
320 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
322 gPushButtonSelectedState = false;
323 pushButton.SetSelected( true );
325 DALI_TEST_CHECK( pushButton.IsSelected() );
326 DALI_TEST_CHECK( gPushButtonSelectedState );
328 pushButton.SetSelected( false );
330 DALI_TEST_CHECK( !pushButton.IsSelected() );
331 DALI_TEST_CHECK( !gPushButtonSelectedState );
333 pushButton.SetSelected( true );
335 DALI_TEST_CHECK( pushButton.IsSelected() );
336 DALI_TEST_CHECK( gPushButtonSelectedState );
340 int UtcDaliPushButtonSetGetSelected02(void)
342 ToolkitTestApplication application;
343 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
345 PushButton pushButton = PushButton::New();
347 pushButton.SetTogglableButton( false );
348 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
350 gPushButtonSelectedState = false;
351 pushButton.SetSelected( true );
353 DALI_TEST_CHECK( !pushButton.IsSelected() );
354 DALI_TEST_CHECK( !gPushButtonSelectedState );
356 pushButton.SetSelected( false );
358 DALI_TEST_CHECK( !pushButton.IsSelected() );
359 DALI_TEST_CHECK( !gPushButtonSelectedState );
361 pushButton.SetSelected( true );
363 DALI_TEST_CHECK( !pushButton.IsSelected() );
364 DALI_TEST_CHECK( !gPushButtonSelectedState );
368 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
370 ToolkitTestApplication application;
371 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
373 PushButton pushButton = PushButton::New();
375 pushButton.SetAutoRepeating( true );
377 pushButton.SetInitialAutoRepeatingDelay( 1.f );
378 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
380 pushButton.SetNextAutoRepeatingDelay( 1.f );
381 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
385 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
387 ToolkitTestApplication application;
388 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
390 PushButton pushButton = PushButton::New();
392 bool assert1( false );
393 bool assert2( false );
395 pushButton.SetAutoRepeating( true );
399 pushButton.SetInitialAutoRepeatingDelay( -1.f );
401 catch( Dali::DaliException& e )
403 DALI_TEST_PRINT_ASSERT( e );
404 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
410 pushButton.SetNextAutoRepeatingDelay( -1.f );
412 catch( Dali::DaliException& e )
414 DALI_TEST_PRINT_ASSERT( e );
415 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
419 DALI_TEST_CHECK( assert1 && assert2 );
423 int UtcDaliPushButtonSetLabelText(void)
425 ToolkitTestApplication application;
426 tet_infoline(" UtcDaliPushButtonSetLabelText");
428 const std::string STR( "Hola!" );
430 PushButton pushButton = PushButton::New();
432 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
433 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
434 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
437 application.SendNotification();
438 application.Render();
440 pushButton.SetLabelText( STR );
442 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
447 int UtcDaliPushButtonPressed(void)
449 ToolkitTestApplication application;
450 tet_infoline(" UtcDaliPushButtonPressed");
452 PushButton pushButton = PushButton::New();
453 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
454 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
455 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
456 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
458 Stage::GetCurrent().Add( pushButton );
460 application.SendNotification();
461 application.Render();
463 gPushButtonPressed = false;
465 // connect to its touch signal
466 pushButton.PressedSignal().Connect( &PushButtonPressed );
468 Dali::Integration::TouchEvent eventDown;
469 eventDown.AddPoint( GetPointDownInside() );
471 // flush the queue and render once
472 application.SendNotification();
473 application.Render();
474 application.ProcessEvent( eventDown );
476 DALI_TEST_CHECK( gPushButtonPressed );
480 int UtcDaliPushButtonReleased(void)
482 ToolkitTestApplication application;
483 tet_infoline(" UtcDaliPushButtonReleased");
485 PushButton pushButton = PushButton::New();
486 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
487 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
488 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
489 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
491 Stage::GetCurrent().Add( pushButton );
493 application.SendNotification();
494 application.Render();
496 // connect to its touch signal
497 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
499 Dali::Integration::TouchEvent event;
501 // Test1. Touch point down and up inside the button.
503 gPushButtonReleased = false;
504 event = Dali::Integration::TouchEvent();
505 event.AddPoint( GetPointDownInside() );
506 application.ProcessEvent( event );
508 event = Dali::Integration::TouchEvent();
509 event.AddPoint( GetPointUpInside() );
510 application.ProcessEvent( event );
512 DALI_TEST_CHECK( gPushButtonReleased );
514 // Test2. Touch point down and up outside the button.
516 gPushButtonReleased = false;
517 event = Dali::Integration::TouchEvent();
518 event.AddPoint( GetPointDownOutside() );
519 application.ProcessEvent( event );
521 event = Dali::Integration::TouchEvent();
522 event.AddPoint( GetPointUpOutside() );
523 application.ProcessEvent( event );
525 DALI_TEST_CHECK( !gPushButtonReleased );
527 // Test3. Touch point down inside and up outside the button.
529 gPushButtonReleased = false;
530 event = Dali::Integration::TouchEvent();
531 event.AddPoint( GetPointDownInside() );
532 application.ProcessEvent( event );
534 event = Dali::Integration::TouchEvent();
535 event.AddPoint( GetPointLeave() );
536 application.ProcessEvent( event );
538 event = Dali::Integration::TouchEvent();
539 event.AddPoint( GetPointUpOutside() );
540 application.ProcessEvent( event );
542 DALI_TEST_CHECK( gPushButtonReleased );
544 // Test4. Touch point down outside and up inside the button.
546 gPushButtonReleased = false;
547 event = Dali::Integration::TouchEvent();
548 event.AddPoint( GetPointDownOutside() );
549 application.ProcessEvent( event );
551 event = Dali::Integration::TouchEvent();
552 event.AddPoint( GetPointEnter() );
553 application.ProcessEvent( event );
555 event = Dali::Integration::TouchEvent();
556 event.AddPoint( GetPointUpInside() );
557 application.ProcessEvent( event );
559 DALI_TEST_CHECK( !gPushButtonReleased );
563 int UtcDaliPushButtonSelected(void)
565 ToolkitTestApplication application;
566 tet_infoline(" UtcDaliPushButtonSelected");
568 PushButton pushButton = PushButton::New();
569 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
570 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
571 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
572 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
574 Stage::GetCurrent().Add( pushButton );
576 application.SendNotification();
577 application.Render();
579 // connect to its touch signal
580 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
582 Dali::Integration::TouchEvent event;
584 // Test1. No togglable button.
586 gPushButtonSelectedState = false;
587 event = Dali::Integration::TouchEvent();
588 event.AddPoint( GetPointDownInside() );
589 application.ProcessEvent( event );
591 event = Dali::Integration::TouchEvent();
592 event.AddPoint( GetPointUpInside() );
593 application.ProcessEvent( event );
595 DALI_TEST_CHECK( !gPushButtonSelectedState );
597 // Set togglable property.
598 pushButton.SetTogglableButton( true );
600 // Test2. Touch point down and up inside the button twice.
601 gPushButtonSelectedState = false;
602 event = Dali::Integration::TouchEvent();
603 event.AddPoint( GetPointDownInside() );
604 application.ProcessEvent( event );
606 event = Dali::Integration::TouchEvent();
607 event.AddPoint( GetPointUpInside() );
608 application.ProcessEvent( event );
610 DALI_TEST_CHECK( gPushButtonSelectedState );
612 event = Dali::Integration::TouchEvent();
613 event.AddPoint( GetPointDownInside() );
614 application.ProcessEvent( event );
616 event = Dali::Integration::TouchEvent();
617 event.AddPoint( GetPointUpInside() );
618 application.ProcessEvent( event );
620 DALI_TEST_CHECK( !gPushButtonSelectedState );
622 // Test3. Touch point down and up outside the button.
624 gPushButtonSelectedState = false;
625 event = Dali::Integration::TouchEvent();
626 event.AddPoint( GetPointDownOutside() );
627 application.ProcessEvent( event );
629 event = Dali::Integration::TouchEvent();
630 event.AddPoint( GetPointUpOutside() );
631 application.ProcessEvent( event );
633 DALI_TEST_CHECK( !gPushButtonSelectedState );
635 // Test4. Touch point down inside and up outside the button.
636 // State changes on Button down
637 gPushButtonSelectedState = false;
638 event = Dali::Integration::TouchEvent();
639 event.AddPoint( GetPointDownInside() );
640 application.ProcessEvent( event );
642 event = Dali::Integration::TouchEvent();
643 event.AddPoint( GetPointLeave() );
644 application.ProcessEvent( event );
646 event = Dali::Integration::TouchEvent();
647 event.AddPoint( GetPointUpOutside() );
648 application.ProcessEvent( event );
650 DALI_TEST_CHECK( gPushButtonSelectedState );
652 // Test5. Touch point down outside and up inside the button.
653 // Start in unselected state
654 pushButton.SetProperty( Button::Property::SELECTED, false );
655 DALI_TEST_CHECK( !pushButton.IsSelected());
657 gPushButtonSelectedState = false;
658 event = Dali::Integration::TouchEvent();
659 event.AddPoint( GetPointDownOutside() );
660 application.ProcessEvent( event );
662 event = Dali::Integration::TouchEvent();
663 event.AddPoint( GetPointEnter() );
664 application.ProcessEvent( event );
666 event = Dali::Integration::TouchEvent();
667 event.AddPoint( GetPointUpInside() );
668 application.ProcessEvent( event );
670 DALI_TEST_CHECK( !gPushButtonSelectedState );
674 int UtcDaliPushButtonPropertySetIconAlignment(void)
676 ToolkitTestApplication application;
677 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
679 PushButton pushButton = PushButton::New();
680 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
681 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
683 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
684 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
689 int UtcDaliPushButtonPropertySetLabelPadding(void)
691 ToolkitTestApplication application;
692 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
694 PushButton pushButton = PushButton::New();
695 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
696 DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::LABEL_PADDING ), Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
698 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
699 DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::LABEL_PADDING ), Vector4( 10.0f, 10.0f, 10.0f, 10.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
704 int UtcDaliPushButtonPropertySetIconPadding(void)
706 ToolkitTestApplication application;
707 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
709 PushButton pushButton = PushButton::New();
710 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
711 DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::ICON_PADDING ), Vector4( 1.0f, 1.0f, 1.0f, 1.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
713 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
714 DALI_TEST_EQUALS( pushButton.GetProperty<Vector4>( Toolkit::PushButton::Property::ICON_PADDING ), Vector4( 10.0f, 10.0f, 10.0f, 10.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
719 int UtcDaliPushButtonPaddingLayout(void)
721 ToolkitTestApplication application;
722 tet_infoline(" UtcDaliPushButtonPaddingLayout");
724 // This test creates padding for an icon and a label.
725 // The icon and label are each enabled and disabled to confirm the correct padding is used.
726 PushButton pushButton = PushButton::New();
728 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
729 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f );
730 const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f);
732 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
733 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
734 pushButton.SetPosition( 0.0f, 0.0f );
735 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
737 Stage::GetCurrent().Add( pushButton );
739 application.SendNotification();
740 application.Render();
742 // First test the size is zero.
743 // No padding should be added as there is no label or icon.
744 Vector2 size( Vector2::ZERO );
745 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
746 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
747 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
749 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
751 // Check label only padding
752 pushButton.SetLabelText( "Label" );
754 application.SendNotification();
755 application.Render();
757 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
758 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
759 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
761 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
763 // Add label padding to label
764 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
765 application.SendNotification();
766 application.Render();
768 Vector2 sizeLabelAndPadding( Vector2::ZERO );
769 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
770 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
771 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
773 // If control size has increased beyond size of just label then padding has been applied
774 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
775 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
777 // Re-initialise the button so we can setup icon-only padding.
778 pushButton.Unparent();
779 pushButton = PushButton::New();
781 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
782 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
783 pushButton.SetPosition( 0.0f, 0.0f );
784 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
786 Stage::GetCurrent().Add( pushButton );
788 TestPlatformAbstraction& platform = application.GetPlatform();
789 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
791 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
792 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
793 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
795 application.SendNotification();
796 application.Render();
798 // Size of button with just icon
799 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
800 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
801 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
803 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
805 application.SendNotification();
806 application.Render();
807 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
809 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
810 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
811 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
812 const Vector2 expectedIconAndPaddingSize( TEST_ICON_PADDING.x+TEST_ICON_PADDING.y+TEST_IMAGE_SIZE.width, TEST_ICON_PADDING.w+TEST_ICON_PADDING.z +TEST_IMAGE_SIZE.height );
813 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
815 // Now test padding for both label and icon simultaneously.
816 pushButton.SetLabelText( "Label" );
817 application.SendNotification();
818 application.Render();
820 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
821 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
822 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
824 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
826 application.SendNotification();
827 application.Render();
829 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
830 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
831 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
833 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
834 DALI_TEST_GREATER( size.height, expectedIconAndPaddingSize.width, TEST_LOCATION ); // Test height of control is greater than icon and padding. As Text set to larger values.
839 int UtcDaliPushButtonAlignmentLayout(void)
841 ToolkitTestApplication application;
842 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
845 * This test checks different alignments for the icon against the label.
846 * The icon is then moved around the label in each of it's alignments.
847 * The final relayed out size is checked to confirm the layout has been done correctly.
849 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
850 * - Therefore total width and height are both 150.
852 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
853 * - Therefore total width and height are 60+x and 60+y respectively.
854 * Where x & y are the width and height of the text.
856 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
857 * So We use the padding to help us determine the orientation is correct for each alignment.
859 * |<- 150 ->| |<-- 60+x -->|
862 * | | ^ +------------+ -
864 * | Icon | 150 | Label | 60+y
866 * | | v +------------+ -
870 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
871 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
872 const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f);
874 PushButton pushButton = PushButton::New();
876 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
877 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
878 pushButton.SetPosition( 0.0f, 0.0f );
879 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
881 Stage::GetCurrent().Add( pushButton );
883 // Add a label and get size of control
884 pushButton.SetLabelText( "Label" );
885 application.SendNotification();
886 application.Render();
888 // First get the size of control with just label
889 Vector2 justLabelSize( Vector2::ZERO );
890 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
891 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
892 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
894 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
895 application.SendNotification();
896 application.Render();
898 // Size of Label and Padding
899 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
900 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
901 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
903 Vector2 labelAndPaddingSize( Vector2::ZERO );
904 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
905 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
907 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
909 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
910 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
912 TestPlatformAbstraction& platform = application.GetPlatform();
913 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
915 // Add Icon and set its alignment
916 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
917 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
918 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
919 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
921 application.SendNotification();
922 application.Render();
924 Vector2 size( Vector2::ZERO );
925 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
926 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
929 * Test Icon right alignment.
930 * Height grows to largest of Icon or Label (+ padding).
931 * Normally this will be Icons height, except with very large font sizes.
933 * +------------+---------+
939 * +------------+---------+
941 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
942 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
944 // Now test left alignment matches right for size.
945 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
947 application.SendNotification();
948 application.Render();
950 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
951 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
954 * Test Icon left alignment.
955 * Height grows to largest of Icon or Label (+ padding).
956 * Normally this will be Icons height, except with very large font sizes.
958 * +---------+------------+
964 * +---------+------------+
966 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
967 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
969 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
986 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
987 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
989 application.SendNotification();
990 application.Render();
992 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
993 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
995 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
996 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
998 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
999 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
1001 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
1003 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1006 * Test Icon bottom alignment.
1007 * Width grows to largest of Icon or Label (+ padding).
1021 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1022 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
1024 application.SendNotification();
1025 application.Render();
1027 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1028 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1030 DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1031 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1036 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1038 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1039 ToolkitTestApplication application;
1041 PushButton pushButton = PushButton::New();
1042 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
1044 Stage::GetCurrent().Add( pushButton );
1046 Property::Map propertyMap;
1047 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1048 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1050 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1052 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1054 application.SendNotification();
1055 application.Render(0);
1057 unsigned int rendererCount = pushButton.GetRendererCount();
1058 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1060 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1062 tet_printf("Remove button from stage\n" );
1064 Stage::GetCurrent().Remove( pushButton );
1066 rendererCount = pushButton.GetRendererCount();
1067 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1069 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1071 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1073 Property::Map propertyMap2;
1074 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1075 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1076 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap2 );
1078 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1080 Stage::GetCurrent().Add( pushButton );
1082 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1084 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1089 int UtcDaliPushButtonSetSelectedVisualN(void)
1091 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1093 ToolkitTestApplication application;
1095 PushButton pushButton = PushButton::New();
1097 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1098 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1099 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1101 Stage::GetCurrent().Add( pushButton );
1102 application.SendNotification();
1103 application.Render(0);
1105 unsigned int preRendererCount = pushButton.GetRendererCount();
1106 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1107 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1109 Stage::GetCurrent().Remove( pushButton );
1110 application.SendNotification();
1111 application.Render(0);
1113 Property::Map colorMap;
1114 const int BROKEN_VISUAL_TYPE = 999999999;
1116 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1117 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1118 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1119 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, colorMap );
1121 Stage::GetCurrent().Add( pushButton );
1122 application.SendNotification();
1123 application.Render(0);
1125 unsigned int postRendererCount = pushButton.GetRendererCount();
1126 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1127 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1132 int UtcDaliPushButtonSetButtonImageP(void)
1134 ToolkitTestApplication application;
1136 PushButton button = PushButton::New();
1137 Stage::GetCurrent().Add( button );
1141 button.SetButtonImage( ImageView::New() );
1142 DALI_TEST_CHECK( true );
1146 DALI_TEST_CHECK( false );
1152 int UtcDaliPushButtonSetBackgroundImageP(void)
1154 ToolkitTestApplication application;
1156 PushButton button = PushButton::New();
1157 Stage::GetCurrent().Add( button );
1161 button.SetBackgroundImage( ImageView::New() );
1162 DALI_TEST_CHECK( true );
1166 DALI_TEST_CHECK( false );
1172 int UtcDaliPushButtonSetSelectedImageP(void)
1174 ToolkitTestApplication application;
1176 PushButton button = PushButton::New();
1177 Stage::GetCurrent().Add( button );
1181 button.SetSelectedImage( ImageView::New() );
1182 DALI_TEST_CHECK( true );
1186 DALI_TEST_CHECK( false );
1192 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1194 ToolkitTestApplication application;
1196 PushButton button = PushButton::New();
1197 Stage::GetCurrent().Add( button );
1201 button.SetSelectedBackgroundImage( ImageView::New() );
1202 DALI_TEST_CHECK( true );
1206 DALI_TEST_CHECK( false );
1212 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1214 ToolkitTestApplication application;
1216 PushButton button = PushButton::New();
1217 Stage::GetCurrent().Add( button );
1221 button.SetDisabledBackgroundImage( ImageView::New() );
1222 DALI_TEST_CHECK( true );
1226 DALI_TEST_CHECK( false );
1233 int UtcDaliPushButtonSetDisabledImageP(void)
1235 ToolkitTestApplication application;
1237 PushButton button = PushButton::New();
1238 Stage::GetCurrent().Add( button );
1242 button.SetDisabledImage( ImageView::New() );
1243 DALI_TEST_CHECK( true );
1247 DALI_TEST_CHECK( false );
1253 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1255 ToolkitTestApplication application;
1257 PushButton button = PushButton::New();
1258 Stage::GetCurrent().Add( button );
1262 button.SetDisabledSelectedImage( ImageView::New() );
1263 DALI_TEST_CHECK( true );
1267 DALI_TEST_CHECK( false );
1273 int UtcDaliPushButtonToggleSignalP(void)
1275 ToolkitTestApplication application;
1276 tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1278 PushButton button = PushButton::New();
1279 button.SetProperty( Button::Property::TOGGLABLE, true);
1281 SetupButtonForTestTouchEvents( application, button, true );
1283 Stage::GetCurrent().Add( button );
1285 application.SendNotification();
1286 application.Render();
1288 // connect to its signal
1289 button.ClickedSignal().Connect( &PushButtonClicked );
1290 gPushButtonClicked = false;
1292 tet_infoline(" Touch down and up within button");
1293 Dali::Integration::TouchEvent event;
1294 event = Dali::Integration::TouchEvent();
1295 event.AddPoint( GetPointDownInside() );
1296 application.ProcessEvent( event );
1298 event = Dali::Integration::TouchEvent();
1299 event.AddPoint( GetPointUpInside() );
1300 application.ProcessEvent( event );
1302 DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION );