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 bool gPushButtonSelectedState = false;
51 bool PushButtonSelected( Button button )
53 gPushButtonSelectedState = button.IsSelected();
57 static bool gPushButtonPressed = false;
59 static bool PushButtonPressed( Button button )
61 gPushButtonPressed = true;
65 static bool gPushButtonReleased = false;
67 static bool PushButtonReleased( Button button )
69 gPushButtonReleased = true;
73 Dali::Integration::Point GetPointDownInside()
75 Dali::Integration::Point point;
76 point.SetState( PointState::DOWN );
77 point.SetScreenPosition( Vector2( 240, 400 ) );
81 Dali::Integration::Point GetPointUpInside()
83 Dali::Integration::Point point;
84 point.SetState( PointState::UP );
85 point.SetScreenPosition( Vector2( 240, 400 ) );
89 Dali::Integration::Point GetPointLeave()
91 Dali::Integration::Point point;
92 point.SetState( PointState::LEAVE );
93 point.SetScreenPosition( Vector2( 240, 400 ) );
97 Dali::Integration::Point GetPointEnter()
99 Dali::Integration::Point point;
100 point.SetState( PointState::MOTION );
101 point.SetScreenPosition( Vector2( 240, 400 ) );
105 Dali::Integration::Point GetPointDownOutside()
107 Dali::Integration::Point point;
108 point.SetState( PointState::DOWN );
109 point.SetScreenPosition( Vector2( 10, 10 ) );
113 Dali::Integration::Point GetPointUpOutside()
115 Dali::Integration::Point point;
116 point.SetState( PointState::UP );
117 point.SetScreenPosition( Vector2( 10, 10 ) );
123 int UtcDaliPushButtonConstructorP(void)
125 TestApplication application;
129 DALI_TEST_CHECK( !button );
133 int UtcDaliPushButtonCopyConstructorP(void)
135 TestApplication application;
137 // Initialize an object, ref count == 1
138 PushButton button = PushButton::New();
140 PushButton copy( button );
141 DALI_TEST_CHECK( copy );
145 int UtcDaliPushButtonAssignmentOperatorP(void)
147 TestApplication application;
149 PushButton button = PushButton::New();
151 PushButton copy( button );
152 DALI_TEST_CHECK( copy );
154 DALI_TEST_CHECK( button == copy );
158 int UtcDaliPushButtonNewP(void)
160 TestApplication application;
162 PushButton button = PushButton::New();
164 DALI_TEST_CHECK( button );
168 int UtcDaliPushButtonDownCastP(void)
170 TestApplication application;
172 PushButton button = PushButton::New();
174 BaseHandle object(button);
176 PushButton button2 = PushButton::DownCast( object );
177 DALI_TEST_CHECK(button2);
179 PushButton button3 = DownCast< PushButton >(object);
180 DALI_TEST_CHECK(button3);
184 int UtcDaliPushButtonDownCastN(void)
186 TestApplication application;
188 BaseHandle unInitializedObject;
190 PushButton button1 = PushButton::DownCast( unInitializedObject );
191 DALI_TEST_CHECK( !button1 );
193 PushButton button2 = DownCast< PushButton >( unInitializedObject );
194 DALI_TEST_CHECK( !button2 );
198 int UtcDaliPushButtonSetGetAutoRepeating(void)
200 ToolkitTestApplication application;
201 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
203 PushButton pushButton = PushButton::New();
205 pushButton.SetAutoRepeating( true );
207 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
209 pushButton.SetAutoRepeating( false );
211 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
213 pushButton.SetAutoRepeating( true );
215 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
219 int UtcDaliPushButtonSetAutoRepeating(void)
221 ToolkitTestApplication application;
222 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
223 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
224 PushButton pushButton = PushButton::New();
226 const bool INITIAL_TOGGLE_VALUE = true;
227 const bool INITIAL_SELECTED_VALUE = true;
229 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
230 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
232 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
233 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
235 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
237 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
242 int UtcDaliPushButtonSetGetTogglableButton(void)
244 ToolkitTestApplication application;
245 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
247 PushButton pushButton = PushButton::New();
249 pushButton.SetTogglableButton( true );
251 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
253 pushButton.SetTogglableButton( false );
255 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
257 pushButton.SetTogglableButton( true );
259 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
263 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
265 ToolkitTestApplication application;
266 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
268 PushButton pushButton = PushButton::New();
270 pushButton.SetAutoRepeating( true );
271 pushButton.SetTogglableButton( true );
273 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
274 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
276 pushButton.SetTogglableButton( true );
277 pushButton.SetAutoRepeating( true );
279 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
280 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
284 int UtcDaliPushButtonSetGetSelected01(void)
286 ToolkitTestApplication application;
287 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
289 PushButton pushButton = PushButton::New();
291 pushButton.SetTogglableButton( true );
292 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
294 gPushButtonSelectedState = false;
295 pushButton.SetSelected( true );
297 DALI_TEST_CHECK( pushButton.IsSelected() );
298 DALI_TEST_CHECK( gPushButtonSelectedState );
300 pushButton.SetSelected( false );
302 DALI_TEST_CHECK( !pushButton.IsSelected() );
303 DALI_TEST_CHECK( !gPushButtonSelectedState );
305 pushButton.SetSelected( true );
307 DALI_TEST_CHECK( pushButton.IsSelected() );
308 DALI_TEST_CHECK( gPushButtonSelectedState );
312 int UtcDaliPushButtonSetGetSelected02(void)
314 ToolkitTestApplication application;
315 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
317 PushButton pushButton = PushButton::New();
319 pushButton.SetTogglableButton( false );
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 UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
342 ToolkitTestApplication application;
343 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
345 PushButton pushButton = PushButton::New();
347 pushButton.SetAutoRepeating( true );
349 pushButton.SetInitialAutoRepeatingDelay( 1.f );
350 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
352 pushButton.SetNextAutoRepeatingDelay( 1.f );
353 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
357 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
359 ToolkitTestApplication application;
360 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
362 PushButton pushButton = PushButton::New();
364 bool assert1( false );
365 bool assert2( false );
367 pushButton.SetAutoRepeating( true );
371 pushButton.SetInitialAutoRepeatingDelay( -1.f );
373 catch( Dali::DaliException& e )
375 DALI_TEST_PRINT_ASSERT( e );
376 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
382 pushButton.SetNextAutoRepeatingDelay( -1.f );
384 catch( Dali::DaliException& e )
386 DALI_TEST_PRINT_ASSERT( e );
387 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
391 DALI_TEST_CHECK( assert1 && assert2 );
395 int UtcDaliPushButtonSetLabelText(void)
397 ToolkitTestApplication application;
398 tet_infoline(" UtcDaliPushButtonSetLabelText");
400 const std::string STR( "Hola!" );
402 PushButton pushButton = PushButton::New();
404 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
405 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
406 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
409 application.SendNotification();
410 application.Render();
412 pushButton.SetLabelText( STR );
414 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
419 int UtcDaliPushButtonPressed(void)
421 ToolkitTestApplication application;
422 tet_infoline(" UtcDaliPushButtonPressed");
424 PushButton pushButton = PushButton::New();
425 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
426 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
427 pushButton.SetPosition( 240, 400 );
428 pushButton.SetSize( 100, 100 );
430 Stage::GetCurrent().Add( pushButton );
432 application.SendNotification();
433 application.Render();
435 gPushButtonPressed = false;
437 // connect to its touch signal
438 pushButton.PressedSignal().Connect( &PushButtonPressed );
440 Dali::Integration::TouchEvent eventDown;
441 eventDown.AddPoint( GetPointDownInside() );
443 // flush the queue and render once
444 application.SendNotification();
445 application.Render();
446 application.ProcessEvent( eventDown );
448 DALI_TEST_CHECK( gPushButtonPressed );
452 int UtcDaliPushButtonReleased(void)
454 ToolkitTestApplication application;
455 tet_infoline(" UtcDaliPushButtonReleased");
457 PushButton pushButton = PushButton::New();
458 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
459 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
460 pushButton.SetPosition( 240, 400 );
461 pushButton.SetSize( 100, 100 );
463 Stage::GetCurrent().Add( pushButton );
465 application.SendNotification();
466 application.Render();
468 // connect to its touch signal
469 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
471 Dali::Integration::TouchEvent event;
473 // Test1. Touch point down and up inside the button.
475 gPushButtonReleased = false;
476 event = Dali::Integration::TouchEvent();
477 event.AddPoint( GetPointDownInside() );
478 application.ProcessEvent( event );
480 event = Dali::Integration::TouchEvent();
481 event.AddPoint( GetPointUpInside() );
482 application.ProcessEvent( event );
484 DALI_TEST_CHECK( gPushButtonReleased );
486 // Test2. Touch point down and up outside the button.
488 gPushButtonReleased = false;
489 event = Dali::Integration::TouchEvent();
490 event.AddPoint( GetPointDownOutside() );
491 application.ProcessEvent( event );
493 event = Dali::Integration::TouchEvent();
494 event.AddPoint( GetPointUpOutside() );
495 application.ProcessEvent( event );
497 DALI_TEST_CHECK( !gPushButtonReleased );
499 // Test3. Touch point down inside and up outside the button.
501 gPushButtonReleased = false;
502 event = Dali::Integration::TouchEvent();
503 event.AddPoint( GetPointDownInside() );
504 application.ProcessEvent( event );
506 event = Dali::Integration::TouchEvent();
507 event.AddPoint( GetPointLeave() );
508 application.ProcessEvent( event );
510 event = Dali::Integration::TouchEvent();
511 event.AddPoint( GetPointUpOutside() );
512 application.ProcessEvent( event );
514 DALI_TEST_CHECK( gPushButtonReleased );
516 // Test4. Touch point down outside and up inside the button.
518 gPushButtonReleased = false;
519 event = Dali::Integration::TouchEvent();
520 event.AddPoint( GetPointDownOutside() );
521 application.ProcessEvent( event );
523 event = Dali::Integration::TouchEvent();
524 event.AddPoint( GetPointEnter() );
525 application.ProcessEvent( event );
527 event = Dali::Integration::TouchEvent();
528 event.AddPoint( GetPointUpInside() );
529 application.ProcessEvent( event );
531 DALI_TEST_CHECK( !gPushButtonReleased );
535 int UtcDaliPushButtonSelected(void)
537 ToolkitTestApplication application;
538 tet_infoline(" UtcDaliPushButtonSelected");
540 PushButton pushButton = PushButton::New();
541 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
542 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
543 pushButton.SetPosition( 240, 400 );
544 pushButton.SetSize( 100, 100 );
546 Stage::GetCurrent().Add( pushButton );
548 application.SendNotification();
549 application.Render();
551 // connect to its touch signal
552 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
554 Dali::Integration::TouchEvent event;
556 // Test1. No togglable button.
558 gPushButtonSelectedState = false;
559 event = Dali::Integration::TouchEvent();
560 event.AddPoint( GetPointDownInside() );
561 application.ProcessEvent( event );
563 event = Dali::Integration::TouchEvent();
564 event.AddPoint( GetPointUpInside() );
565 application.ProcessEvent( event );
567 DALI_TEST_CHECK( !gPushButtonSelectedState );
569 // Set togglable property.
570 pushButton.SetTogglableButton( true );
572 // Test2. Touch point down and up inside the button twice.
573 gPushButtonSelectedState = false;
574 event = Dali::Integration::TouchEvent();
575 event.AddPoint( GetPointDownInside() );
576 application.ProcessEvent( event );
578 event = Dali::Integration::TouchEvent();
579 event.AddPoint( GetPointUpInside() );
580 application.ProcessEvent( event );
582 DALI_TEST_CHECK( gPushButtonSelectedState );
584 event = Dali::Integration::TouchEvent();
585 event.AddPoint( GetPointDownInside() );
586 application.ProcessEvent( event );
588 event = Dali::Integration::TouchEvent();
589 event.AddPoint( GetPointUpInside() );
590 application.ProcessEvent( event );
592 DALI_TEST_CHECK( !gPushButtonSelectedState );
594 // Test3. Touch point down and up outside the button.
596 gPushButtonSelectedState = false;
597 event = Dali::Integration::TouchEvent();
598 event.AddPoint( GetPointDownOutside() );
599 application.ProcessEvent( event );
601 event = Dali::Integration::TouchEvent();
602 event.AddPoint( GetPointUpOutside() );
603 application.ProcessEvent( event );
605 DALI_TEST_CHECK( !gPushButtonSelectedState );
607 // Test4. Touch point down inside and up outside the button.
608 // State changes on Button down
609 gPushButtonSelectedState = false;
610 event = Dali::Integration::TouchEvent();
611 event.AddPoint( GetPointDownInside() );
612 application.ProcessEvent( event );
614 event = Dali::Integration::TouchEvent();
615 event.AddPoint( GetPointLeave() );
616 application.ProcessEvent( event );
618 event = Dali::Integration::TouchEvent();
619 event.AddPoint( GetPointUpOutside() );
620 application.ProcessEvent( event );
622 DALI_TEST_CHECK( gPushButtonSelectedState );
624 // Test5. Touch point down outside and up inside the button.
625 // Start in unselected state
626 pushButton.SetProperty( Button::Property::SELECTED, false );
627 DALI_TEST_CHECK( !pushButton.IsSelected());
629 gPushButtonSelectedState = false;
630 event = Dali::Integration::TouchEvent();
631 event.AddPoint( GetPointDownOutside() );
632 application.ProcessEvent( event );
634 event = Dali::Integration::TouchEvent();
635 event.AddPoint( GetPointEnter() );
636 application.ProcessEvent( event );
638 event = Dali::Integration::TouchEvent();
639 event.AddPoint( GetPointUpInside() );
640 application.ProcessEvent( event );
642 DALI_TEST_CHECK( !gPushButtonSelectedState );
646 int UtcDaliPushButtonPropertySetIconAlignment(void)
648 ToolkitTestApplication application;
649 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
651 PushButton pushButton = PushButton::New();
652 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
653 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
655 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
656 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
661 int UtcDaliPushButtonPropertySetLabelPadding(void)
663 ToolkitTestApplication application;
664 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
666 PushButton pushButton = PushButton::New();
667 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
668 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 );
670 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
671 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 );
676 int UtcDaliPushButtonPropertySetIconPadding(void)
678 ToolkitTestApplication application;
679 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
681 PushButton pushButton = PushButton::New();
682 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
683 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 );
685 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
686 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 );
691 int UtcDaliPushButtonPaddingLayout(void)
693 ToolkitTestApplication application;
694 tet_infoline(" UtcDaliPushButtonPaddingLayout");
696 // This test creates padding for an icon and a label.
697 // The icon and label are each enabled and disabled to confirm the correct padding is used.
698 PushButton pushButton = PushButton::New();
700 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
701 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f );
702 const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f);
704 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
705 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
706 pushButton.SetPosition( 0.0f, 0.0f );
707 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
709 Stage::GetCurrent().Add( pushButton );
711 application.SendNotification();
712 application.Render();
714 // First test the size is zero.
715 // No padding should be added as there is no label or icon.
716 Vector2 size( Vector2::ZERO );
717 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
718 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
719 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
721 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
723 // Check label only padding
724 pushButton.SetLabelText( "Label" );
726 application.SendNotification();
727 application.Render();
729 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
730 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
731 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
733 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
735 // Add label padding to label
736 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
737 application.SendNotification();
738 application.Render();
740 Vector2 sizeLabelAndPadding( Vector2::ZERO );
741 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
742 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
743 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
745 // If control size has increased beyond size of just label then padding has been applied
746 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
747 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
749 // Re-initialise the button so we can setup icon-only padding.
750 pushButton.Unparent();
751 pushButton = PushButton::New();
753 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
754 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
755 pushButton.SetPosition( 0.0f, 0.0f );
756 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
758 Stage::GetCurrent().Add( pushButton );
760 TestPlatformAbstraction& platform = application.GetPlatform();
761 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
763 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
764 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
765 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
767 application.SendNotification();
768 application.Render();
770 // Size of button with just icon
771 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
772 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
773 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
775 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
777 application.SendNotification();
778 application.Render();
779 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
781 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
782 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
783 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
784 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 );
785 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
787 // Now test padding for both label and icon simultaneously.
788 pushButton.SetLabelText( "Label" );
789 application.SendNotification();
790 application.Render();
792 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
793 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
794 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
796 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
798 application.SendNotification();
799 application.Render();
801 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
802 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
803 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
805 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
806 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.
811 int UtcDaliPushButtonAlignmentLayout(void)
813 ToolkitTestApplication application;
814 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
817 * This test checks different alignments for the icon against the label.
818 * The icon is then moved around the label in each of it's alignments.
819 * The final relayed out size is checked to confirm the layout has been done correctly.
821 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
822 * - Therefore total width and height are both 150.
824 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
825 * - Therefore total width and height are 60+x and 60+y respectively.
826 * Where x & y are the width and height of the text.
828 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
829 * So We use the padding to help us determine the orientation is correct for each alignment.
831 * |<- 150 ->| |<-- 60+x -->|
834 * | | ^ +------------+ -
836 * | Icon | 150 | Label | 60+y
838 * | | v +------------+ -
842 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
843 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
844 const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f);
846 PushButton pushButton = PushButton::New();
848 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
849 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
850 pushButton.SetPosition( 0.0f, 0.0f );
851 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
853 Stage::GetCurrent().Add( pushButton );
855 // Add a label and get size of control
856 pushButton.SetLabelText( "Label" );
857 application.SendNotification();
858 application.Render();
860 // First get the size of control with just label
861 Vector2 justLabelSize( Vector2::ZERO );
862 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
863 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
864 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
866 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
867 application.SendNotification();
868 application.Render();
870 // Size of Label and Padding
871 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
872 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
873 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
875 Vector2 labelAndPaddingSize( Vector2::ZERO );
876 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
877 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
879 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
881 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
882 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
884 TestPlatformAbstraction& platform = application.GetPlatform();
885 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
887 // Add Icon and set its alignment
888 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
889 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
890 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
891 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
893 application.SendNotification();
894 application.Render();
896 Vector2 size( Vector2::ZERO );
897 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
898 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
901 * Test Icon right alignment.
902 * Height grows to largest of Icon or Label (+ padding).
903 * Normally this will be Icons height, except with very large font sizes.
905 * +------------+---------+
911 * +------------+---------+
913 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
914 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
916 // Now test left alignment matches right for size.
917 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
919 application.SendNotification();
920 application.Render();
922 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
923 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
926 * Test Icon left alignment.
927 * Height grows to largest of Icon or Label (+ padding).
928 * Normally this will be Icons height, except with very large font sizes.
930 * +---------+------------+
936 * +---------+------------+
938 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
939 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
941 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
958 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
959 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
961 application.SendNotification();
962 application.Render();
964 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
965 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
967 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
968 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
970 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
971 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
973 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
975 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
978 * Test Icon bottom alignment.
979 * Width grows to largest of Icon or Label (+ padding).
993 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
994 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
996 application.SendNotification();
997 application.Render();
999 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1000 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1002 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 );
1008 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1010 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1011 ToolkitTestApplication application;
1013 PushButton pushButton = PushButton::New();
1014 pushButton.SetSize(100.0f, 100.0f);
1016 Stage::GetCurrent().Add( pushButton );
1018 Property::Map propertyMap;
1019 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1020 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1022 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1024 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1026 application.SendNotification();
1027 application.Render(0);
1029 unsigned int rendererCount = pushButton.GetRendererCount();
1030 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1032 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1034 tet_printf("Remove button from stage\n" );
1036 Stage::GetCurrent().Remove( pushButton );
1038 rendererCount = pushButton.GetRendererCount();
1039 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1041 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1043 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1045 Property::Map propertyMap2;
1046 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1047 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1048 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap2 );
1050 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1052 Stage::GetCurrent().Add( pushButton );
1054 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1056 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1061 int UtcDaliPushButtonSetSelectedVisualN(void)
1063 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1065 ToolkitTestApplication application;
1067 PushButton pushButton = PushButton::New();
1069 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1070 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1071 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1073 Stage::GetCurrent().Add( pushButton );
1074 application.SendNotification();
1075 application.Render(0);
1077 unsigned int preRendererCount = pushButton.GetRendererCount();
1078 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1079 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1081 Stage::GetCurrent().Remove( pushButton );
1082 application.SendNotification();
1083 application.Render(0);
1085 Property::Map colorMap;
1086 const int BROKEN_VISUAL_TYPE = 999999999;
1088 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1089 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1090 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1091 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, colorMap );
1093 Stage::GetCurrent().Add( pushButton );
1094 application.SendNotification();
1095 application.Render(0);
1097 unsigned int postRendererCount = pushButton.GetRendererCount();
1098 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1099 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1104 int UtcDaliPushButtonSetButtonImageP(void)
1106 ToolkitTestApplication application;
1108 PushButton button = PushButton::New();
1109 Stage::GetCurrent().Add( button );
1113 button.SetButtonImage( ImageView::New() );
1114 DALI_TEST_CHECK( true );
1118 DALI_TEST_CHECK( false );
1124 int UtcDaliPushButtonSetBackgroundImageP(void)
1126 ToolkitTestApplication application;
1128 PushButton button = PushButton::New();
1129 Stage::GetCurrent().Add( button );
1133 button.SetBackgroundImage( ImageView::New() );
1134 DALI_TEST_CHECK( true );
1138 DALI_TEST_CHECK( false );
1144 int UtcDaliPushButtonSetSelectedImageP(void)
1146 ToolkitTestApplication application;
1148 PushButton button = PushButton::New();
1149 Stage::GetCurrent().Add( button );
1153 button.SetSelectedImage( ImageView::New() );
1154 DALI_TEST_CHECK( true );
1158 DALI_TEST_CHECK( false );
1164 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1166 ToolkitTestApplication application;
1168 PushButton button = PushButton::New();
1169 Stage::GetCurrent().Add( button );
1173 button.SetSelectedBackgroundImage( ImageView::New() );
1174 DALI_TEST_CHECK( true );
1178 DALI_TEST_CHECK( false );
1184 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1186 ToolkitTestApplication application;
1188 PushButton button = PushButton::New();
1189 Stage::GetCurrent().Add( button );
1193 button.SetDisabledBackgroundImage( ImageView::New() );
1194 DALI_TEST_CHECK( true );
1198 DALI_TEST_CHECK( false );
1205 int UtcDaliPushButtonSetDisabledImageP(void)
1207 ToolkitTestApplication application;
1209 PushButton button = PushButton::New();
1210 Stage::GetCurrent().Add( button );
1214 button.SetDisabledImage( ImageView::New() );
1215 DALI_TEST_CHECK( true );
1219 DALI_TEST_CHECK( false );
1225 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1227 ToolkitTestApplication application;
1229 PushButton button = PushButton::New();
1230 Stage::GetCurrent().Add( button );
1234 button.SetDisabledSelectedImage( ImageView::New() );
1235 DALI_TEST_CHECK( true );
1239 DALI_TEST_CHECK( false );