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/visuals/visual-properties-devel.h>
30 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
33 using namespace Toolkit;
35 void utc_dali_toolkit_pushbutton_startup(void)
37 test_return_value = TET_UNDEF;
40 void utc_dali_toolkit_pushbutton_cleanup(void)
42 test_return_value = TET_PASS;
47 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
49 static bool gPushButtonSelectedState = false;
50 bool PushButtonSelected( Button button )
52 gPushButtonSelectedState = button.IsSelected();
56 static bool gPushButtonPressed = false;
58 static bool PushButtonPressed( Button button )
60 gPushButtonPressed = true;
64 static bool gPushButtonReleased = false;
66 static bool PushButtonReleased( Button button )
68 gPushButtonReleased = true;
72 Dali::Integration::Point GetPointDownInside()
74 Dali::Integration::Point point;
75 point.SetState( PointState::DOWN );
76 point.SetScreenPosition( Vector2( 240, 400 ) );
80 Dali::Integration::Point GetPointUpInside()
82 Dali::Integration::Point point;
83 point.SetState( PointState::UP );
84 point.SetScreenPosition( Vector2( 240, 400 ) );
88 Dali::Integration::Point GetPointLeave()
90 Dali::Integration::Point point;
91 point.SetState( PointState::LEAVE );
92 point.SetScreenPosition( Vector2( 240, 400 ) );
96 Dali::Integration::Point GetPointEnter()
98 Dali::Integration::Point point;
99 point.SetState( PointState::MOTION );
100 point.SetScreenPosition( Vector2( 240, 400 ) );
104 Dali::Integration::Point GetPointDownOutside()
106 Dali::Integration::Point point;
107 point.SetState( PointState::DOWN );
108 point.SetScreenPosition( Vector2( 10, 10 ) );
112 Dali::Integration::Point GetPointUpOutside()
114 Dali::Integration::Point point;
115 point.SetState( PointState::UP );
116 point.SetScreenPosition( Vector2( 10, 10 ) );
122 int UtcDaliPushButtonConstructorP(void)
124 TestApplication application;
128 DALI_TEST_CHECK( !button );
132 int UtcDaliPushButtonCopyConstructorP(void)
134 TestApplication application;
136 // Initialize an object, ref count == 1
137 PushButton button = PushButton::New();
139 PushButton copy( button );
140 DALI_TEST_CHECK( copy );
144 int UtcDaliPushButtonAssignmentOperatorP(void)
146 TestApplication application;
148 PushButton button = PushButton::New();
150 PushButton copy( button );
151 DALI_TEST_CHECK( copy );
153 DALI_TEST_CHECK( button == copy );
157 int UtcDaliPushButtonNewP(void)
159 TestApplication application;
161 PushButton button = PushButton::New();
163 DALI_TEST_CHECK( button );
167 int UtcDaliPushButtonDownCastP(void)
169 TestApplication application;
171 PushButton button = PushButton::New();
173 BaseHandle object(button);
175 PushButton button2 = PushButton::DownCast( object );
176 DALI_TEST_CHECK(button2);
178 PushButton button3 = DownCast< PushButton >(object);
179 DALI_TEST_CHECK(button3);
183 int UtcDaliPushButtonDownCastN(void)
185 TestApplication application;
187 BaseHandle unInitializedObject;
189 PushButton button1 = PushButton::DownCast( unInitializedObject );
190 DALI_TEST_CHECK( !button1 );
192 PushButton button2 = DownCast< PushButton >( unInitializedObject );
193 DALI_TEST_CHECK( !button2 );
197 int UtcDaliPushButtonSetGetAutoRepeating(void)
199 ToolkitTestApplication application;
200 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
202 PushButton pushButton = PushButton::New();
204 pushButton.SetAutoRepeating( true );
206 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
208 pushButton.SetAutoRepeating( false );
210 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
212 pushButton.SetAutoRepeating( true );
214 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
218 int UtcDaliPushButtonSetAutoRepeating(void)
220 ToolkitTestApplication application;
221 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
222 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
223 PushButton pushButton = PushButton::New();
225 const bool INITIAL_TOGGLE_VALUE = true;
226 const bool INITIAL_SELECTED_VALUE = true;
228 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
229 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
231 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
232 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
234 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
236 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
241 int UtcDaliPushButtonSetGetTogglableButton(void)
243 ToolkitTestApplication application;
244 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
246 PushButton pushButton = PushButton::New();
248 pushButton.SetTogglableButton( true );
250 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
252 pushButton.SetTogglableButton( false );
254 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
256 pushButton.SetTogglableButton( true );
258 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
262 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
264 ToolkitTestApplication application;
265 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
267 PushButton pushButton = PushButton::New();
269 pushButton.SetAutoRepeating( true );
270 pushButton.SetTogglableButton( true );
272 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
273 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
275 pushButton.SetTogglableButton( true );
276 pushButton.SetAutoRepeating( true );
278 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
279 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
283 int UtcDaliPushButtonSetGetSelected01(void)
285 ToolkitTestApplication application;
286 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
288 PushButton pushButton = PushButton::New();
290 pushButton.SetTogglableButton( true );
291 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
293 gPushButtonSelectedState = false;
294 pushButton.SetSelected( true );
296 DALI_TEST_CHECK( pushButton.IsSelected() );
297 DALI_TEST_CHECK( gPushButtonSelectedState );
299 pushButton.SetSelected( false );
301 DALI_TEST_CHECK( !pushButton.IsSelected() );
302 DALI_TEST_CHECK( !gPushButtonSelectedState );
304 pushButton.SetSelected( true );
306 DALI_TEST_CHECK( pushButton.IsSelected() );
307 DALI_TEST_CHECK( gPushButtonSelectedState );
311 int UtcDaliPushButtonSetGetSelected02(void)
313 ToolkitTestApplication application;
314 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
316 PushButton pushButton = PushButton::New();
318 pushButton.SetTogglableButton( false );
319 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
321 gPushButtonSelectedState = false;
322 pushButton.SetSelected( true );
324 DALI_TEST_CHECK( !pushButton.IsSelected() );
325 DALI_TEST_CHECK( !gPushButtonSelectedState );
327 pushButton.SetSelected( false );
329 DALI_TEST_CHECK( !pushButton.IsSelected() );
330 DALI_TEST_CHECK( !gPushButtonSelectedState );
332 pushButton.SetSelected( true );
334 DALI_TEST_CHECK( !pushButton.IsSelected() );
335 DALI_TEST_CHECK( !gPushButtonSelectedState );
339 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
341 ToolkitTestApplication application;
342 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
344 PushButton pushButton = PushButton::New();
346 pushButton.SetAutoRepeating( true );
348 pushButton.SetInitialAutoRepeatingDelay( 1.f );
349 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
351 pushButton.SetNextAutoRepeatingDelay( 1.f );
352 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
356 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
358 ToolkitTestApplication application;
359 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
361 PushButton pushButton = PushButton::New();
363 bool assert1( false );
364 bool assert2( false );
366 pushButton.SetAutoRepeating( true );
370 pushButton.SetInitialAutoRepeatingDelay( -1.f );
372 catch( Dali::DaliException& e )
374 DALI_TEST_PRINT_ASSERT( e );
375 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
381 pushButton.SetNextAutoRepeatingDelay( -1.f );
383 catch( Dali::DaliException& e )
385 DALI_TEST_PRINT_ASSERT( e );
386 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
390 DALI_TEST_CHECK( assert1 && assert2 );
394 int UtcDaliPushButtonSetLabelText(void)
396 ToolkitTestApplication application;
397 tet_infoline(" UtcDaliPushButtonSetLabelText");
399 const std::string STR( "Hola!" );
401 PushButton pushButton = PushButton::New();
403 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
404 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
405 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
408 application.SendNotification();
409 application.Render();
411 pushButton.SetLabelText( STR );
413 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
418 int UtcDaliPushButtonPressed(void)
420 ToolkitTestApplication application;
421 tet_infoline(" UtcDaliPushButtonPressed");
423 PushButton pushButton = PushButton::New();
424 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
425 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
426 pushButton.SetPosition( 240, 400 );
427 pushButton.SetSize( 100, 100 );
429 Stage::GetCurrent().Add( pushButton );
431 application.SendNotification();
432 application.Render();
434 gPushButtonPressed = false;
436 // connect to its touch signal
437 pushButton.PressedSignal().Connect( &PushButtonPressed );
439 Dali::Integration::TouchEvent eventDown;
440 eventDown.AddPoint( GetPointDownInside() );
442 // flush the queue and render once
443 application.SendNotification();
444 application.Render();
445 application.ProcessEvent( eventDown );
447 DALI_TEST_CHECK( gPushButtonPressed );
451 int UtcDaliPushButtonReleased(void)
453 ToolkitTestApplication application;
454 tet_infoline(" UtcDaliPushButtonReleased");
456 PushButton pushButton = PushButton::New();
457 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
458 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
459 pushButton.SetPosition( 240, 400 );
460 pushButton.SetSize( 100, 100 );
462 Stage::GetCurrent().Add( pushButton );
464 application.SendNotification();
465 application.Render();
467 // connect to its touch signal
468 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
470 Dali::Integration::TouchEvent event;
472 // Test1. Touch point down and up inside the button.
474 gPushButtonReleased = false;
475 event = Dali::Integration::TouchEvent();
476 event.AddPoint( GetPointDownInside() );
477 application.ProcessEvent( event );
479 event = Dali::Integration::TouchEvent();
480 event.AddPoint( GetPointUpInside() );
481 application.ProcessEvent( event );
483 DALI_TEST_CHECK( gPushButtonReleased );
485 // Test2. Touch point down and up outside the button.
487 gPushButtonReleased = false;
488 event = Dali::Integration::TouchEvent();
489 event.AddPoint( GetPointDownOutside() );
490 application.ProcessEvent( event );
492 event = Dali::Integration::TouchEvent();
493 event.AddPoint( GetPointUpOutside() );
494 application.ProcessEvent( event );
496 DALI_TEST_CHECK( !gPushButtonReleased );
498 // Test3. Touch point down inside and up outside the button.
500 gPushButtonReleased = false;
501 event = Dali::Integration::TouchEvent();
502 event.AddPoint( GetPointDownInside() );
503 application.ProcessEvent( event );
505 event = Dali::Integration::TouchEvent();
506 event.AddPoint( GetPointLeave() );
507 application.ProcessEvent( event );
509 event = Dali::Integration::TouchEvent();
510 event.AddPoint( GetPointUpOutside() );
511 application.ProcessEvent( event );
513 DALI_TEST_CHECK( gPushButtonReleased );
515 // Test4. Touch point down outside and up inside the button.
517 gPushButtonReleased = false;
518 event = Dali::Integration::TouchEvent();
519 event.AddPoint( GetPointDownOutside() );
520 application.ProcessEvent( event );
522 event = Dali::Integration::TouchEvent();
523 event.AddPoint( GetPointEnter() );
524 application.ProcessEvent( event );
526 event = Dali::Integration::TouchEvent();
527 event.AddPoint( GetPointUpInside() );
528 application.ProcessEvent( event );
530 DALI_TEST_CHECK( !gPushButtonReleased );
534 int UtcDaliPushButtonSelected(void)
536 ToolkitTestApplication application;
537 tet_infoline(" UtcDaliPushButtonSelected");
539 PushButton pushButton = PushButton::New();
540 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
541 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
542 pushButton.SetPosition( 240, 400 );
543 pushButton.SetSize( 100, 100 );
545 Stage::GetCurrent().Add( pushButton );
547 application.SendNotification();
548 application.Render();
550 // connect to its touch signal
551 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
553 Dali::Integration::TouchEvent event;
555 // Test1. No togglable button.
557 gPushButtonSelectedState = false;
558 event = Dali::Integration::TouchEvent();
559 event.AddPoint( GetPointDownInside() );
560 application.ProcessEvent( event );
562 event = Dali::Integration::TouchEvent();
563 event.AddPoint( GetPointUpInside() );
564 application.ProcessEvent( event );
566 DALI_TEST_CHECK( !gPushButtonSelectedState );
568 // Set togglable property.
569 pushButton.SetTogglableButton( true );
571 // Test2. Touch point down and up inside the button twice.
572 gPushButtonSelectedState = false;
573 event = Dali::Integration::TouchEvent();
574 event.AddPoint( GetPointDownInside() );
575 application.ProcessEvent( event );
577 event = Dali::Integration::TouchEvent();
578 event.AddPoint( GetPointUpInside() );
579 application.ProcessEvent( event );
581 DALI_TEST_CHECK( gPushButtonSelectedState );
583 event = Dali::Integration::TouchEvent();
584 event.AddPoint( GetPointDownInside() );
585 application.ProcessEvent( event );
587 event = Dali::Integration::TouchEvent();
588 event.AddPoint( GetPointUpInside() );
589 application.ProcessEvent( event );
591 DALI_TEST_CHECK( !gPushButtonSelectedState );
593 // Test3. Touch point down and up outside the button.
595 gPushButtonSelectedState = false;
596 event = Dali::Integration::TouchEvent();
597 event.AddPoint( GetPointDownOutside() );
598 application.ProcessEvent( event );
600 event = Dali::Integration::TouchEvent();
601 event.AddPoint( GetPointUpOutside() );
602 application.ProcessEvent( event );
604 DALI_TEST_CHECK( !gPushButtonSelectedState );
606 // Test4. Touch point down inside and up outside the button.
607 // State changes on Button down
608 gPushButtonSelectedState = false;
609 event = Dali::Integration::TouchEvent();
610 event.AddPoint( GetPointDownInside() );
611 application.ProcessEvent( event );
613 event = Dali::Integration::TouchEvent();
614 event.AddPoint( GetPointLeave() );
615 application.ProcessEvent( event );
617 event = Dali::Integration::TouchEvent();
618 event.AddPoint( GetPointUpOutside() );
619 application.ProcessEvent( event );
621 DALI_TEST_CHECK( gPushButtonSelectedState );
623 // Test5. Touch point down outside and up inside the button.
624 // Start in unselected state
625 pushButton.SetProperty( Button::Property::SELECTED, false );
626 DALI_TEST_CHECK( !pushButton.IsSelected());
628 gPushButtonSelectedState = false;
629 event = Dali::Integration::TouchEvent();
630 event.AddPoint( GetPointDownOutside() );
631 application.ProcessEvent( event );
633 event = Dali::Integration::TouchEvent();
634 event.AddPoint( GetPointEnter() );
635 application.ProcessEvent( event );
637 event = Dali::Integration::TouchEvent();
638 event.AddPoint( GetPointUpInside() );
639 application.ProcessEvent( event );
641 DALI_TEST_CHECK( !gPushButtonSelectedState );
645 int UtcDaliPushButtonPropertySetIconAlignment(void)
647 ToolkitTestApplication application;
648 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
650 PushButton pushButton = PushButton::New();
651 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
652 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
654 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
655 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
660 int UtcDaliPushButtonPropertySetLabelPadding(void)
662 ToolkitTestApplication application;
663 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
665 PushButton pushButton = PushButton::New();
666 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
667 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 );
669 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
670 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 );
675 int UtcDaliPushButtonPropertySetIconPadding(void)
677 ToolkitTestApplication application;
678 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
680 PushButton pushButton = PushButton::New();
681 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
682 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 );
684 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
685 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 );
690 int UtcDaliPushButtonPaddingLayout(void)
692 ToolkitTestApplication application;
693 tet_infoline(" UtcDaliPushButtonPaddingLayout");
695 // This test creates padding for an icon and a label.
696 // The icon and label are each enabled and disabled to confirm the correct padding is used.
697 PushButton pushButton = PushButton::New();
699 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
700 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f );
701 const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f);
703 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
704 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
705 pushButton.SetPosition( 0.0f, 0.0f );
706 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
708 Stage::GetCurrent().Add( pushButton );
710 application.SendNotification();
711 application.Render();
713 // First test the size is zero.
714 // No padding should be added as there is no label or icon.
715 Vector2 size( Vector2::ZERO );
716 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
717 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
718 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
720 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
722 // Check label only padding
723 pushButton.SetLabelText( "Label" );
725 application.SendNotification();
726 application.Render();
728 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
729 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
730 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
732 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
734 // Add label padding to label
735 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
736 application.SendNotification();
737 application.Render();
739 Vector2 sizeLabelAndPadding( Vector2::ZERO );
740 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
741 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
742 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
744 // If control size has increased beyond size of just label then padding has been applied
745 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
746 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
748 // Re-initialise the button so we can setup icon-only padding.
749 pushButton.Unparent();
750 pushButton = PushButton::New();
752 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
753 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
754 pushButton.SetPosition( 0.0f, 0.0f );
755 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
757 Stage::GetCurrent().Add( pushButton );
759 TestPlatformAbstraction& platform = application.GetPlatform();
760 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
762 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
763 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
764 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
766 application.SendNotification();
767 application.Render();
769 // Size of button with just icon
770 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
771 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
772 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
774 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
776 application.SendNotification();
777 application.Render();
778 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
780 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
781 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
782 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
783 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 );
784 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
786 // Now test padding for both label and icon simultaneously.
787 pushButton.SetLabelText( "Label" );
788 application.SendNotification();
789 application.Render();
791 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
792 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
793 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
795 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
797 application.SendNotification();
798 application.Render();
800 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
801 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
802 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
804 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
805 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.
810 int UtcDaliPushButtonAlignmentLayout(void)
812 ToolkitTestApplication application;
813 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
816 * This test checks different alignments for the icon against the label.
817 * The icon is then moved around the label in each of it's alignments.
818 * The final relayed out size is checked to confirm the layout has been done correctly.
820 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
821 * - Therefore total width and height are both 150.
823 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
824 * - Therefore total width and height are 60+x and 60+y respectively.
825 * Where x & y are the width and height of the text.
827 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
828 * So We use the padding to help us determine the orientation is correct for each alignment.
830 * |<- 150 ->| |<-- 60+x -->|
833 * | | ^ +------------+ -
835 * | Icon | 150 | Label | 60+y
837 * | | v +------------+ -
841 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
842 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
843 const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f);
845 PushButton pushButton = PushButton::New();
847 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
848 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
849 pushButton.SetPosition( 0.0f, 0.0f );
850 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
852 Stage::GetCurrent().Add( pushButton );
854 // Add a label and get size of control
855 pushButton.SetLabelText( "Label" );
856 application.SendNotification();
857 application.Render();
859 // First get the size of control with just label
860 Vector2 justLabelSize( Vector2::ZERO );
861 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
862 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
863 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
865 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
866 application.SendNotification();
867 application.Render();
869 // Size of Label and Padding
870 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
871 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
872 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
874 Vector2 labelAndPaddingSize( Vector2::ZERO );
875 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
876 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
878 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
880 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
881 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
883 TestPlatformAbstraction& platform = application.GetPlatform();
884 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
886 // Add Icon and set its alignment
887 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
888 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
889 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
890 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
892 application.SendNotification();
893 application.Render();
895 Vector2 size( Vector2::ZERO );
896 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
897 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
900 * Test Icon right alignment.
901 * Height grows to largest of Icon or Label (+ padding).
902 * Normally this will be Icons height, except with very large font sizes.
904 * +------------+---------+
910 * +------------+---------+
912 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
913 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
915 // Now test left alignment matches right for size.
916 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
918 application.SendNotification();
919 application.Render();
921 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
922 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
925 * Test Icon left alignment.
926 * Height grows to largest of Icon or Label (+ padding).
927 * Normally this will be Icons height, except with very large font sizes.
929 * +---------+------------+
935 * +---------+------------+
937 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
938 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
940 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
957 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
958 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
960 application.SendNotification();
961 application.Render();
963 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
964 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
966 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
967 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
969 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
970 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
972 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
974 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
977 * Test Icon bottom alignment.
978 * Width grows to largest of Icon or Label (+ padding).
992 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
993 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
995 application.SendNotification();
996 application.Render();
998 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
999 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1001 DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1002 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1007 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1009 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1010 ToolkitTestApplication application;
1012 PushButton pushButton = PushButton::New();
1013 pushButton.SetSize(100.0f, 100.0f);
1015 Stage::GetCurrent().Add( pushButton );
1017 Property::Map propertyMap;
1018 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1019 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1021 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1023 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1025 application.SendNotification();
1026 application.Render(0);
1028 unsigned int rendererCount = pushButton.GetRendererCount();
1029 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1031 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1033 tet_printf("Remove button from stage\n" );
1035 Stage::GetCurrent().Remove( pushButton );
1037 rendererCount = pushButton.GetRendererCount();
1038 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1040 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1042 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1044 Property::Map propertyMap2;
1045 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1046 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1047 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap2 );
1049 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1051 Stage::GetCurrent().Add( pushButton );
1053 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1055 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1060 int UtcDaliPushButtonSetSelectedVisualN(void)
1062 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1064 ToolkitTestApplication application;
1066 PushButton pushButton = PushButton::New();
1068 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1069 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1070 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1072 Stage::GetCurrent().Add( pushButton );
1073 application.SendNotification();
1074 application.Render(0);
1076 unsigned int preRendererCount = pushButton.GetRendererCount();
1077 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1078 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1080 Stage::GetCurrent().Remove( pushButton );
1081 application.SendNotification();
1082 application.Render(0);
1084 Property::Map colorMap;
1085 const int BROKEN_VISUAL_TYPE = 999999999;
1087 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1088 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1089 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1090 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, colorMap );
1092 Stage::GetCurrent().Add( pushButton );
1093 application.SendNotification();
1094 application.Render(0);
1096 unsigned int postRendererCount = pushButton.GetRendererCount();
1097 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1098 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1103 int UtcDaliPushButtonSetButtonImageP(void)
1105 ToolkitTestApplication application;
1107 PushButton button = PushButton::New();
1108 Stage::GetCurrent().Add( button );
1112 button.SetButtonImage( ImageView::New() );
1113 DALI_TEST_CHECK( true );
1117 DALI_TEST_CHECK( false );
1123 int UtcDaliPushButtonSetBackgroundImageP(void)
1125 ToolkitTestApplication application;
1127 PushButton button = PushButton::New();
1128 Stage::GetCurrent().Add( button );
1132 button.SetBackgroundImage( ImageView::New() );
1133 DALI_TEST_CHECK( true );
1137 DALI_TEST_CHECK( false );
1143 int UtcDaliPushButtonSetSelectedImageP(void)
1145 ToolkitTestApplication application;
1147 PushButton button = PushButton::New();
1148 Stage::GetCurrent().Add( button );
1152 button.SetSelectedImage( ImageView::New() );
1153 DALI_TEST_CHECK( true );
1157 DALI_TEST_CHECK( false );
1163 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1165 ToolkitTestApplication application;
1167 PushButton button = PushButton::New();
1168 Stage::GetCurrent().Add( button );
1172 button.SetSelectedBackgroundImage( ImageView::New() );
1173 DALI_TEST_CHECK( true );
1177 DALI_TEST_CHECK( false );
1183 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1185 ToolkitTestApplication application;
1187 PushButton button = PushButton::New();
1188 Stage::GetCurrent().Add( button );
1192 button.SetDisabledBackgroundImage( ImageView::New() );
1193 DALI_TEST_CHECK( true );
1197 DALI_TEST_CHECK( false );
1204 int UtcDaliPushButtonSetDisabledImageP(void)
1206 ToolkitTestApplication application;
1208 PushButton button = PushButton::New();
1209 Stage::GetCurrent().Add( button );
1213 button.SetDisabledImage( ImageView::New() );
1214 DALI_TEST_CHECK( true );
1218 DALI_TEST_CHECK( false );
1224 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1226 ToolkitTestApplication application;
1228 PushButton button = PushButton::New();
1229 Stage::GetCurrent().Add( button );
1233 button.SetDisabledSelectedImage( ImageView::New() );
1234 DALI_TEST_CHECK( true );
1238 DALI_TEST_CHECK( false );