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>
33 #include <dali/devel-api/adaptor-framework/image-loading.h>
36 using namespace Toolkit;
38 void utc_dali_toolkit_pushbutton_startup(void)
40 test_return_value = TET_UNDEF;
43 void utc_dali_toolkit_pushbutton_cleanup(void)
45 test_return_value = TET_PASS;
51 static bool gPushButtonSelectedState = false;
52 bool PushButtonSelected( Button button )
54 gPushButtonSelectedState = button.IsSelected();
58 static bool gPushButtonPressed = false;
60 static bool PushButtonPressed( Button button )
62 gPushButtonPressed = true;
66 static bool gPushButtonReleased = false;
68 static bool PushButtonReleased( Button button )
70 gPushButtonReleased = true;
74 Dali::Integration::Point GetPointDownInside()
76 Dali::Integration::Point point;
77 point.SetState( PointState::DOWN );
78 point.SetScreenPosition( Vector2( 240, 400 ) );
82 Dali::Integration::Point GetPointUpInside()
84 Dali::Integration::Point point;
85 point.SetState( PointState::UP );
86 point.SetScreenPosition( Vector2( 240, 400 ) );
90 Dali::Integration::Point GetPointLeave()
92 Dali::Integration::Point point;
93 point.SetState( PointState::LEAVE );
94 point.SetScreenPosition( Vector2( 240, 400 ) );
98 Dali::Integration::Point GetPointEnter()
100 Dali::Integration::Point point;
101 point.SetState( PointState::MOTION );
102 point.SetScreenPosition( Vector2( 240, 400 ) );
106 Dali::Integration::Point GetPointDownOutside()
108 Dali::Integration::Point point;
109 point.SetState( PointState::DOWN );
110 point.SetScreenPosition( Vector2( 10, 10 ) );
114 Dali::Integration::Point GetPointUpOutside()
116 Dali::Integration::Point point;
117 point.SetState( PointState::UP );
118 point.SetScreenPosition( Vector2( 10, 10 ) );
124 int UtcDaliPushButtonConstructorP(void)
126 TestApplication application;
130 DALI_TEST_CHECK( !button );
134 int UtcDaliPushButtonCopyConstructorP(void)
136 TestApplication application;
138 // Initialize an object, ref count == 1
139 PushButton button = PushButton::New();
141 PushButton copy( button );
142 DALI_TEST_CHECK( copy );
146 int UtcDaliPushButtonAssignmentOperatorP(void)
148 TestApplication application;
150 PushButton button = PushButton::New();
152 PushButton copy( button );
153 DALI_TEST_CHECK( copy );
155 DALI_TEST_CHECK( button == copy );
159 int UtcDaliPushButtonNewP(void)
161 TestApplication application;
163 PushButton button = PushButton::New();
165 DALI_TEST_CHECK( button );
169 int UtcDaliPushButtonDownCastP(void)
171 TestApplication application;
173 PushButton button = PushButton::New();
175 BaseHandle object(button);
177 PushButton button2 = PushButton::DownCast( object );
178 DALI_TEST_CHECK(button2);
180 PushButton button3 = DownCast< PushButton >(object);
181 DALI_TEST_CHECK(button3);
185 int UtcDaliPushButtonDownCastN(void)
187 TestApplication application;
189 BaseHandle unInitializedObject;
191 PushButton button1 = PushButton::DownCast( unInitializedObject );
192 DALI_TEST_CHECK( !button1 );
194 PushButton button2 = DownCast< PushButton >( unInitializedObject );
195 DALI_TEST_CHECK( !button2 );
199 int UtcDaliPushButtonSetGetAutoRepeating(void)
201 ToolkitTestApplication application;
202 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
204 PushButton pushButton = PushButton::New();
206 pushButton.SetAutoRepeating( true );
208 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
210 pushButton.SetAutoRepeating( false );
212 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
214 pushButton.SetAutoRepeating( true );
216 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
220 int UtcDaliPushButtonSetGetTogglableButton(void)
222 ToolkitTestApplication application;
223 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
225 PushButton pushButton = PushButton::New();
227 pushButton.SetTogglableButton( true );
229 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
231 pushButton.SetTogglableButton( false );
233 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
235 pushButton.SetTogglableButton( true );
237 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
241 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
243 ToolkitTestApplication application;
244 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
246 PushButton pushButton = PushButton::New();
248 pushButton.SetAutoRepeating( true );
249 pushButton.SetTogglableButton( true );
251 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
252 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
254 pushButton.SetTogglableButton( true );
255 pushButton.SetAutoRepeating( true );
257 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
258 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
262 int UtcDaliPushButtonSetGetSelected01(void)
264 ToolkitTestApplication application;
265 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
267 PushButton pushButton = PushButton::New();
269 pushButton.SetTogglableButton( true );
270 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
272 gPushButtonSelectedState = false;
273 pushButton.SetSelected( true );
275 DALI_TEST_CHECK( pushButton.IsSelected() );
276 DALI_TEST_CHECK( gPushButtonSelectedState );
278 pushButton.SetSelected( false );
280 DALI_TEST_CHECK( !pushButton.IsSelected() );
281 DALI_TEST_CHECK( !gPushButtonSelectedState );
283 pushButton.SetSelected( true );
285 DALI_TEST_CHECK( pushButton.IsSelected() );
286 DALI_TEST_CHECK( gPushButtonSelectedState );
290 int UtcDaliPushButtonSetGetSelected02(void)
292 ToolkitTestApplication application;
293 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
295 PushButton pushButton = PushButton::New();
297 pushButton.SetTogglableButton( false );
298 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
300 gPushButtonSelectedState = false;
301 pushButton.SetSelected( true );
303 DALI_TEST_CHECK( !pushButton.IsSelected() );
304 DALI_TEST_CHECK( !gPushButtonSelectedState );
306 pushButton.SetSelected( false );
308 DALI_TEST_CHECK( !pushButton.IsSelected() );
309 DALI_TEST_CHECK( !gPushButtonSelectedState );
311 pushButton.SetSelected( true );
313 DALI_TEST_CHECK( !pushButton.IsSelected() );
314 DALI_TEST_CHECK( !gPushButtonSelectedState );
318 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
320 ToolkitTestApplication application;
321 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
323 PushButton pushButton = PushButton::New();
325 pushButton.SetAutoRepeating( true );
327 pushButton.SetInitialAutoRepeatingDelay( 1.f );
328 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
330 pushButton.SetNextAutoRepeatingDelay( 1.f );
331 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
335 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
337 ToolkitTestApplication application;
338 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
340 PushButton pushButton = PushButton::New();
342 bool assert1( false );
343 bool assert2( false );
345 pushButton.SetAutoRepeating( true );
349 pushButton.SetInitialAutoRepeatingDelay( -1.f );
351 catch( Dali::DaliException& e )
353 DALI_TEST_PRINT_ASSERT( e );
354 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
360 pushButton.SetNextAutoRepeatingDelay( -1.f );
362 catch( Dali::DaliException& e )
364 DALI_TEST_PRINT_ASSERT( e );
365 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
369 DALI_TEST_CHECK( assert1 && assert2 );
373 int UtcDaliPushButtonSetLabelText(void)
375 ToolkitTestApplication application;
376 tet_infoline(" UtcDaliPushButtonSetLabelText");
378 const std::string STR( "Hola!" );
380 PushButton pushButton = PushButton::New();
382 application.SendNotification();
383 application.Render();
385 pushButton.SetLabelText( STR );
387 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
392 int UtcDaliPushButtonPressed(void)
394 ToolkitTestApplication application;
395 tet_infoline(" UtcDaliPushButtonPressed");
397 PushButton pushButton = PushButton::New();
398 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
399 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
400 pushButton.SetPosition( 240, 400 );
401 pushButton.SetSize( 100, 100 );
403 Stage::GetCurrent().Add( pushButton );
405 application.SendNotification();
406 application.Render();
408 gPushButtonPressed = false;
410 // connect to its touch signal
411 pushButton.PressedSignal().Connect( &PushButtonPressed );
413 Dali::Integration::TouchEvent eventDown;
414 eventDown.AddPoint( GetPointDownInside() );
416 // flush the queue and render once
417 application.SendNotification();
418 application.Render();
419 application.ProcessEvent( eventDown );
421 DALI_TEST_CHECK( gPushButtonPressed );
425 int UtcDaliPushButtonReleased(void)
427 ToolkitTestApplication application;
428 tet_infoline(" UtcDaliPushButtonReleased");
430 PushButton pushButton = PushButton::New();
431 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
432 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
433 pushButton.SetPosition( 240, 400 );
434 pushButton.SetSize( 100, 100 );
436 Stage::GetCurrent().Add( pushButton );
438 application.SendNotification();
439 application.Render();
441 // connect to its touch signal
442 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
444 Dali::Integration::TouchEvent event;
446 // Test1. Touch point down and up inside the button.
448 gPushButtonReleased = false;
449 event = Dali::Integration::TouchEvent();
450 event.AddPoint( GetPointDownInside() );
451 application.ProcessEvent( event );
453 event = Dali::Integration::TouchEvent();
454 event.AddPoint( GetPointUpInside() );
455 application.ProcessEvent( event );
457 DALI_TEST_CHECK( gPushButtonReleased );
459 // Test2. Touch point down and up outside the button.
461 gPushButtonReleased = false;
462 event = Dali::Integration::TouchEvent();
463 event.AddPoint( GetPointDownOutside() );
464 application.ProcessEvent( event );
466 event = Dali::Integration::TouchEvent();
467 event.AddPoint( GetPointUpOutside() );
468 application.ProcessEvent( event );
470 DALI_TEST_CHECK( !gPushButtonReleased );
472 // Test3. Touch point down inside and up outside 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( GetPointLeave() );
481 application.ProcessEvent( event );
483 event = Dali::Integration::TouchEvent();
484 event.AddPoint( GetPointUpOutside() );
485 application.ProcessEvent( event );
487 DALI_TEST_CHECK( gPushButtonReleased );
489 // Test4. Touch point down outside and up inside the button.
491 gPushButtonReleased = false;
492 event = Dali::Integration::TouchEvent();
493 event.AddPoint( GetPointDownOutside() );
494 application.ProcessEvent( event );
496 event = Dali::Integration::TouchEvent();
497 event.AddPoint( GetPointEnter() );
498 application.ProcessEvent( event );
500 event = Dali::Integration::TouchEvent();
501 event.AddPoint( GetPointUpInside() );
502 application.ProcessEvent( event );
504 DALI_TEST_CHECK( !gPushButtonReleased );
508 int UtcDaliPushButtonSelected(void)
510 ToolkitTestApplication application;
511 tet_infoline(" UtcDaliPushButtonSelected");
513 PushButton pushButton = PushButton::New();
514 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
515 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
516 pushButton.SetPosition( 240, 400 );
517 pushButton.SetSize( 100, 100 );
519 Stage::GetCurrent().Add( pushButton );
521 application.SendNotification();
522 application.Render();
524 // connect to its touch signal
525 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
527 Dali::Integration::TouchEvent event;
529 // Test1. No togglable button.
531 gPushButtonSelectedState = false;
532 event = Dali::Integration::TouchEvent();
533 event.AddPoint( GetPointDownInside() );
534 application.ProcessEvent( event );
536 event = Dali::Integration::TouchEvent();
537 event.AddPoint( GetPointUpInside() );
538 application.ProcessEvent( event );
540 DALI_TEST_CHECK( !gPushButtonSelectedState );
542 // Set togglable property.
543 pushButton.SetTogglableButton( true );
545 // Test2. Touch point down and up inside the button twice.
546 gPushButtonSelectedState = false;
547 event = Dali::Integration::TouchEvent();
548 event.AddPoint( GetPointDownInside() );
549 application.ProcessEvent( event );
551 event = Dali::Integration::TouchEvent();
552 event.AddPoint( GetPointUpInside() );
553 application.ProcessEvent( event );
555 DALI_TEST_CHECK( gPushButtonSelectedState );
557 event = Dali::Integration::TouchEvent();
558 event.AddPoint( GetPointDownInside() );
559 application.ProcessEvent( event );
561 event = Dali::Integration::TouchEvent();
562 event.AddPoint( GetPointUpInside() );
563 application.ProcessEvent( event );
565 DALI_TEST_CHECK( !gPushButtonSelectedState );
567 // Test3. Touch point down and up outside the button.
569 gPushButtonSelectedState = false;
570 event = Dali::Integration::TouchEvent();
571 event.AddPoint( GetPointDownOutside() );
572 application.ProcessEvent( event );
574 event = Dali::Integration::TouchEvent();
575 event.AddPoint( GetPointUpOutside() );
576 application.ProcessEvent( event );
578 DALI_TEST_CHECK( !gPushButtonSelectedState );
580 // Test4. Touch point down inside and up outside the button.
582 gPushButtonSelectedState = false;
583 event = Dali::Integration::TouchEvent();
584 event.AddPoint( GetPointDownInside() );
585 application.ProcessEvent( event );
587 event = Dali::Integration::TouchEvent();
588 event.AddPoint( GetPointLeave() );
589 application.ProcessEvent( event );
591 event = Dali::Integration::TouchEvent();
592 event.AddPoint( GetPointUpOutside() );
593 application.ProcessEvent( event );
595 DALI_TEST_CHECK( !gPushButtonSelectedState );
597 // Test5. Touch point down outside and up inside the button.
599 gPushButtonSelectedState = false;
600 event = Dali::Integration::TouchEvent();
601 event.AddPoint( GetPointDownOutside() );
602 application.ProcessEvent( event );
604 event = Dali::Integration::TouchEvent();
605 event.AddPoint( GetPointEnter() );
606 application.ProcessEvent( event );
608 event = Dali::Integration::TouchEvent();
609 event.AddPoint( GetPointUpInside() );
610 application.ProcessEvent( event );
612 DALI_TEST_CHECK( !gPushButtonSelectedState );
616 int UtcDaliPushButtonPropertySetIconAlignment(void)
618 ToolkitTestApplication application;
619 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
621 PushButton pushButton = PushButton::New();
622 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
623 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
625 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
626 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
631 int UtcDaliPushButtonPropertySetLabelPadding(void)
633 ToolkitTestApplication application;
634 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
636 PushButton pushButton = PushButton::New();
637 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
638 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 );
640 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
641 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 );
646 int UtcDaliPushButtonPropertySetIconPadding(void)
648 ToolkitTestApplication application;
649 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
651 PushButton pushButton = PushButton::New();
652 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
653 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 );
655 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
656 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 );
661 int UtcDaliPushButtonPaddingLayout(void)
663 ToolkitTestApplication application;
664 tet_infoline(" UtcDaliPushButtonPaddingLayout");
666 // This test creates padding for an icon and a label.
667 // The icon and label are each enabled and disabled to confirm the correct padding is used.
668 PushButton pushButton = PushButton::New();
671 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
672 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
674 // Get actual size of test image
675 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
676 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
678 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
679 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
680 pushButton.SetPosition( 0.0f, 0.0f );
681 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
683 Stage::GetCurrent().Add( pushButton );
685 application.SendNotification();
686 application.Render();
688 // First test the size is zero.
689 // No padding should be added as there is no label or icon.
690 Vector2 size( Vector2::ZERO );
691 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
692 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
694 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
696 // Check label only padding.
697 pushButton.SetLabelText( "Label" );
699 application.SendNotification();
700 application.Render();
702 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
703 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
705 // We should not test against the exact label size, we just make sure it is larger than our label padding so we know the padding has been applied.
706 DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION );
707 DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION );
709 // Re-initialise the button so we can setup icon-only padding.
710 pushButton.Unparent();
711 pushButton = PushButton::New();
713 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
714 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
716 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
717 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
718 pushButton.SetPosition( 0.0f, 0.0f );
719 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
721 Stage::GetCurrent().Add( pushButton );
725 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
726 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
727 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
729 application.SendNotification();
730 application.Render();
732 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
733 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
736 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
738 application.SendNotification();
739 application.Render();
740 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
742 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
743 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
744 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
745 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 );
746 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
748 // Now test padding for both label and icon simultaneously.
749 pushButton.SetLabelText( "Label" );
751 application.SendNotification();
752 application.Render();
754 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
755 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
758 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
759 // Test height of control is same as icon and padding, as Text is smaller than icon
760 DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
765 int UtcDaliPushButtonAlignmentLayout(void)
767 ToolkitTestApplication application;
768 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
771 * This test checks different alignments for the icon against the label.
772 * The icon is then moved around the label in each of it's alignments.
773 * The final relayed out size is checked to confirm the layout has been done correctly.
775 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
776 * - Therefore total width and height are both 150.
778 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
779 * - Therefore total width and height are 60+x and 60+y respectively.
780 * Where x & y are the width and height of the text.
782 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
783 * So We use the padding to help us determine the orientation is correct for each alignment.
785 * |<- 150 ->| |<-- 60+x -->|
788 * | | ^ +------------+ -
790 * | Icon | 150 | Label | 60+y
792 * | | v +------------+ -
797 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
798 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
800 // Get actual size of test image
801 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
802 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
804 PushButton pushButton = PushButton::New();
806 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) );
807 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) );
809 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
810 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
811 pushButton.SetPosition( 0.0f, 0.0f );
812 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
814 Stage::GetCurrent().Add( pushButton );
816 const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
817 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
818 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
819 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
821 application.SendNotification();
822 application.Render();
824 // First get the base size (without label).
825 Vector2 baseSize( Vector2::ZERO );
826 baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
827 baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
829 DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
832 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
834 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
835 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
837 // Add Icon and set its alignment
838 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
839 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
840 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
841 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
843 application.SendNotification();
844 application.Render();
846 Vector2 size( Vector2::ZERO );
847 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
848 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
852 * Test Icon right alignment.
853 * Height grows to largest of Icon or Label (+ padding).
854 * Normally this will be Icons height, except with very large font sizes.
856 * +------------+---------+
862 * +------------+---------+
864 DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION );
865 DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
867 // Now test left alignment matches right for size.
868 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
870 application.SendNotification();
871 application.Render();
873 Vector2 compareSize( Vector2::ZERO );
874 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
875 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
878 * Test Icon left alignment.
879 * Height grows to largest of Icon or Label (+ padding).
880 * Normally this will be Icons height, except with very large font sizes.
882 * +---------+------------+
888 * +---------+------------+
890 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
892 // Test top alignment.
893 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
895 application.SendNotification();
896 application.Render();
898 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
899 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
902 * Test Icon top alignment.
903 * Width grows to largest of Icon or Label (+ padding).
917 * Note: We subtract a small number as we want to do a >= test.
919 DALI_TEST_GREATER( size.width, 150.0f - Math::MACHINE_EPSILON_1000, TEST_LOCATION );
920 DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION );
922 // Test bottom alignment.
923 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
925 application.SendNotification();
926 application.Render();
928 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
929 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
932 * Test Icon bottom alignment.
933 * Width grows to largest of Icon or Label (+ padding).
947 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
952 int UtcDaliPushButtonSetButtonImageP(void)
954 ToolkitTestApplication application;
956 PushButton button = PushButton::New();
957 Stage::GetCurrent().Add( button );
961 button.SetButtonImage( ImageView::New() );
962 DALI_TEST_CHECK( true );
966 DALI_TEST_CHECK( false );
972 int UtcDaliPushButtonSetButtonImageN(void)
974 ToolkitTestApplication application;
980 button.SetSelectedImage( ImageView::New() );
981 DALI_TEST_CHECK( false );
985 DALI_TEST_CHECK( true );
991 int UtcDaliPushButtonSetBackgroundImageP(void)
993 ToolkitTestApplication application;
995 PushButton button = PushButton::New();
996 Stage::GetCurrent().Add( button );
1000 button.SetBackgroundImage( ImageView::New() );
1001 DALI_TEST_CHECK( true );
1005 DALI_TEST_CHECK( false );
1011 int UtcDaliPushButtonSetBackgroundImageN(void)
1013 ToolkitTestApplication application;
1019 button.SetBackgroundImage( ImageView::New() );
1020 DALI_TEST_CHECK( false );
1024 DALI_TEST_CHECK( true );
1030 int UtcDaliPushButtonSetSelectedImageP(void)
1032 ToolkitTestApplication application;
1034 PushButton button = PushButton::New();
1035 Stage::GetCurrent().Add( button );
1039 button.SetSelectedImage( ImageView::New() );
1040 DALI_TEST_CHECK( true );
1044 DALI_TEST_CHECK( false );
1050 int UtcDaliPushButtonSetSelectedImageN(void)
1052 ToolkitTestApplication application;
1058 button.SetSelectedImage( ImageView::New() );
1059 DALI_TEST_CHECK( false );
1063 DALI_TEST_CHECK( true );
1069 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1071 ToolkitTestApplication application;
1073 PushButton button = PushButton::New();
1074 Stage::GetCurrent().Add( button );
1078 button.SetSelectedBackgroundImage( ImageView::New() );
1079 DALI_TEST_CHECK( true );
1083 DALI_TEST_CHECK( false );
1089 int UtcDaliPushButtonSetSelectedBackgroundImageN(void)
1091 ToolkitTestApplication application;
1097 button.SetSelectedBackgroundImage( ImageView::New() );
1098 DALI_TEST_CHECK( false );
1102 DALI_TEST_CHECK( true );
1108 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1110 ToolkitTestApplication application;
1112 PushButton button = PushButton::New();
1113 Stage::GetCurrent().Add( button );
1117 button.SetDisabledBackgroundImage( ImageView::New() );
1118 DALI_TEST_CHECK( true );
1122 DALI_TEST_CHECK( false );
1128 int UtcDaliPushButtonSetDisabledBackgroundImageN(void)
1130 ToolkitTestApplication application;
1136 button.SetDisabledBackgroundImage( ImageView::New() );
1137 DALI_TEST_CHECK( false );
1141 DALI_TEST_CHECK( true );
1147 int UtcDaliPushButtonSetDisabledImageP(void)
1149 ToolkitTestApplication application;
1151 PushButton button = PushButton::New();
1152 Stage::GetCurrent().Add( button );
1156 button.SetDisabledImage( ImageView::New() );
1157 DALI_TEST_CHECK( true );
1161 DALI_TEST_CHECK( false );
1167 int UtcDaliPushButtonSetDisabledImageN(void)
1169 ToolkitTestApplication application;
1175 button.SetDisabledImage( ImageView::New() );
1176 DALI_TEST_CHECK( false );
1180 DALI_TEST_CHECK( true );
1186 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1188 ToolkitTestApplication application;
1190 PushButton button = PushButton::New();
1191 Stage::GetCurrent().Add( button );
1195 button.SetDisabledSelectedImage( ImageView::New() );
1196 DALI_TEST_CHECK( true );
1200 DALI_TEST_CHECK( false );
1206 int UtcDaliPushButtonSetDisabledSelectedImageN(void)
1208 ToolkitTestApplication application;
1214 button.SetDisabledSelectedImage( ImageView::New() );
1215 DALI_TEST_CHECK( false );
1219 DALI_TEST_CHECK( true );