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>
30 using namespace Toolkit;
32 void utc_dali_toolkit_pushbutton_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_pushbutton_cleanup(void)
39 test_return_value = TET_PASS;
45 static bool gPushButtonSelectedState = false;
46 bool PushButtonSelected( Button button )
48 gPushButtonSelectedState = button.IsSelected();
52 static bool gPushButtonPressed = false;
54 static bool PushButtonPressed( Button button )
56 gPushButtonPressed = true;
60 static bool gPushButtonReleased = false;
62 static bool PushButtonReleased( Button button )
64 gPushButtonReleased = true;
68 Dali::Integration::Point GetPointDownInside()
70 Dali::Integration::Point point;
71 point.SetState( PointState::DOWN );
72 point.SetScreenPosition( Vector2( 240, 400 ) );
76 Dali::Integration::Point GetPointUpInside()
78 Dali::Integration::Point point;
79 point.SetState( PointState::UP );
80 point.SetScreenPosition( Vector2( 240, 400 ) );
84 Dali::Integration::Point GetPointLeave()
86 Dali::Integration::Point point;
87 point.SetState( PointState::LEAVE );
88 point.SetScreenPosition( Vector2( 240, 400 ) );
92 Dali::Integration::Point GetPointEnter()
94 Dali::Integration::Point point;
95 point.SetState( PointState::MOTION );
96 point.SetScreenPosition( Vector2( 240, 400 ) );
100 Dali::Integration::Point GetPointDownOutside()
102 Dali::Integration::Point point;
103 point.SetState( PointState::DOWN );
104 point.SetScreenPosition( Vector2( 10, 10 ) );
108 Dali::Integration::Point GetPointUpOutside()
110 Dali::Integration::Point point;
111 point.SetState( PointState::UP );
112 point.SetScreenPosition( Vector2( 10, 10 ) );
116 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
118 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
121 PixelBuffer* pixbuf = imageData.GetBuffer();
122 unsigned int size = width * height;
124 for( size_t i = 0; i < size; i++ )
126 pixbuf[i*4+0] = 0xFF * color.r;
127 pixbuf[i*4+1] = 0xFF * color.g;
128 pixbuf[i*4+2] = 0xFF * color.b;
129 pixbuf[i*4+3] = 0xFF * color.a;
139 int UtcDaliPushButtonConstructorP(void)
141 TestApplication application;
145 DALI_TEST_CHECK( !button );
149 int UtcDaliPushButtonCopyConstructorP(void)
151 TestApplication application;
153 // Initialize an object, ref count == 1
154 PushButton button = PushButton::New();
156 PushButton copy( button );
157 DALI_TEST_CHECK( copy );
161 int UtcDaliPushButtonAssignmentOperatorP(void)
163 TestApplication application;
165 PushButton button = PushButton::New();
167 PushButton copy( button );
168 DALI_TEST_CHECK( copy );
170 DALI_TEST_CHECK( button == copy );
174 int UtcDaliPushButtonNewP(void)
176 TestApplication application;
178 PushButton button = PushButton::New();
180 DALI_TEST_CHECK( button );
184 int UtcDaliPushButtonDownCastP(void)
186 TestApplication application;
188 PushButton button = PushButton::New();
190 BaseHandle object(button);
192 PushButton button2 = PushButton::DownCast( object );
193 DALI_TEST_CHECK(button2);
195 PushButton button3 = DownCast< PushButton >(object);
196 DALI_TEST_CHECK(button3);
200 int UtcDaliPushButtonDownCastN(void)
202 TestApplication application;
204 BaseHandle unInitializedObject;
206 PushButton button1 = PushButton::DownCast( unInitializedObject );
207 DALI_TEST_CHECK( !button1 );
209 PushButton button2 = DownCast< PushButton >( unInitializedObject );
210 DALI_TEST_CHECK( !button2 );
214 int UtcDaliPushButtonSetGetAutoRepeating(void)
216 ToolkitTestApplication application;
217 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
219 PushButton pushButton = PushButton::New();
221 pushButton.SetAutoRepeating( true );
223 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
225 pushButton.SetAutoRepeating( false );
227 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
229 pushButton.SetAutoRepeating( true );
231 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
235 int UtcDaliPushButtonSetGetTogglableButton(void)
237 ToolkitTestApplication application;
238 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
240 PushButton pushButton = PushButton::New();
242 pushButton.SetTogglableButton( true );
244 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
246 pushButton.SetTogglableButton( false );
248 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
250 pushButton.SetTogglableButton( true );
252 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
256 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
258 ToolkitTestApplication application;
259 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
261 PushButton pushButton = PushButton::New();
263 pushButton.SetAutoRepeating( true );
264 pushButton.SetTogglableButton( true );
266 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
267 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
269 pushButton.SetTogglableButton( true );
270 pushButton.SetAutoRepeating( true );
272 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
273 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
277 int UtcDaliPushButtonSetGetSelected01(void)
279 ToolkitTestApplication application;
280 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
282 PushButton pushButton = PushButton::New();
284 pushButton.SetTogglableButton( true );
285 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
287 gPushButtonSelectedState = false;
288 pushButton.SetSelected( true );
290 DALI_TEST_CHECK( pushButton.IsSelected() );
291 DALI_TEST_CHECK( gPushButtonSelectedState );
293 pushButton.SetSelected( false );
295 DALI_TEST_CHECK( !pushButton.IsSelected() );
296 DALI_TEST_CHECK( !gPushButtonSelectedState );
298 pushButton.SetSelected( true );
300 DALI_TEST_CHECK( pushButton.IsSelected() );
301 DALI_TEST_CHECK( gPushButtonSelectedState );
305 int UtcDaliPushButtonSetGetSelected02(void)
307 ToolkitTestApplication application;
308 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
310 PushButton pushButton = PushButton::New();
312 pushButton.SetTogglableButton( false );
313 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
315 gPushButtonSelectedState = false;
316 pushButton.SetSelected( true );
318 DALI_TEST_CHECK( !pushButton.IsSelected() );
319 DALI_TEST_CHECK( !gPushButtonSelectedState );
321 pushButton.SetSelected( false );
323 DALI_TEST_CHECK( !pushButton.IsSelected() );
324 DALI_TEST_CHECK( !gPushButtonSelectedState );
326 pushButton.SetSelected( true );
328 DALI_TEST_CHECK( !pushButton.IsSelected() );
329 DALI_TEST_CHECK( !gPushButtonSelectedState );
333 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
335 ToolkitTestApplication application;
336 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
338 PushButton pushButton = PushButton::New();
340 pushButton.SetAutoRepeating( true );
342 pushButton.SetInitialAutoRepeatingDelay( 1.f );
343 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
345 pushButton.SetNextAutoRepeatingDelay( 1.f );
346 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
350 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
352 ToolkitTestApplication application;
353 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
355 PushButton pushButton = PushButton::New();
357 bool assert1( false );
358 bool assert2( false );
360 pushButton.SetAutoRepeating( true );
364 pushButton.SetInitialAutoRepeatingDelay( -1.f );
366 catch( Dali::DaliException& e )
368 DALI_TEST_PRINT_ASSERT( e );
369 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
375 pushButton.SetNextAutoRepeatingDelay( -1.f );
377 catch( Dali::DaliException& e )
379 DALI_TEST_PRINT_ASSERT( e );
380 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
384 DALI_TEST_CHECK( assert1 && assert2 );
388 int UtcDaliPushButtonSetLabelText(void)
390 ToolkitTestApplication application;
391 tet_infoline(" UtcDaliPushButtonSetLabelText");
393 const std::string STR( "Hola!" );
395 PushButton pushButton = PushButton::New();
397 application.SendNotification();
398 application.Render();
400 pushButton.SetLabelText( STR );
402 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
407 int UtcDaliPushButtonPressed(void)
409 ToolkitTestApplication application;
410 tet_infoline(" UtcDaliPushButtonPressed");
412 PushButton pushButton = PushButton::New();
413 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
414 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
415 pushButton.SetPosition( 240, 400 );
416 pushButton.SetSize( 100, 100 );
418 Stage::GetCurrent().Add( pushButton );
420 application.SendNotification();
421 application.Render();
423 gPushButtonPressed = false;
425 // connect to its touch signal
426 pushButton.PressedSignal().Connect( &PushButtonPressed );
428 Dali::Integration::TouchEvent eventDown;
429 eventDown.AddPoint( GetPointDownInside() );
431 // flush the queue and render once
432 application.SendNotification();
433 application.Render();
434 application.ProcessEvent( eventDown );
436 DALI_TEST_CHECK( gPushButtonPressed );
440 int UtcDaliPushButtonReleased(void)
442 ToolkitTestApplication application;
443 tet_infoline(" UtcDaliPushButtonReleased");
445 PushButton pushButton = PushButton::New();
446 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
447 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
448 pushButton.SetPosition( 240, 400 );
449 pushButton.SetSize( 100, 100 );
451 Stage::GetCurrent().Add( pushButton );
453 application.SendNotification();
454 application.Render();
456 // connect to its touch signal
457 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
459 Dali::Integration::TouchEvent event;
461 // Test1. Touch point down and up inside the button.
463 gPushButtonReleased = false;
464 event = Dali::Integration::TouchEvent();
465 event.AddPoint( GetPointDownInside() );
466 application.ProcessEvent( event );
468 event = Dali::Integration::TouchEvent();
469 event.AddPoint( GetPointUpInside() );
470 application.ProcessEvent( event );
472 DALI_TEST_CHECK( gPushButtonReleased );
474 // Test2. Touch point down and up outside the button.
476 gPushButtonReleased = false;
477 event = Dali::Integration::TouchEvent();
478 event.AddPoint( GetPointDownOutside() );
479 application.ProcessEvent( event );
481 event = Dali::Integration::TouchEvent();
482 event.AddPoint( GetPointUpOutside() );
483 application.ProcessEvent( event );
485 DALI_TEST_CHECK( !gPushButtonReleased );
487 // Test3. Touch point down inside and up outside the button.
489 gPushButtonReleased = false;
490 event = Dali::Integration::TouchEvent();
491 event.AddPoint( GetPointDownInside() );
492 application.ProcessEvent( event );
494 event = Dali::Integration::TouchEvent();
495 event.AddPoint( GetPointLeave() );
496 application.ProcessEvent( event );
498 event = Dali::Integration::TouchEvent();
499 event.AddPoint( GetPointUpOutside() );
500 application.ProcessEvent( event );
502 DALI_TEST_CHECK( gPushButtonReleased );
504 // Test4. Touch point down outside and up inside the button.
506 gPushButtonReleased = false;
507 event = Dali::Integration::TouchEvent();
508 event.AddPoint( GetPointDownOutside() );
509 application.ProcessEvent( event );
511 event = Dali::Integration::TouchEvent();
512 event.AddPoint( GetPointEnter() );
513 application.ProcessEvent( event );
515 event = Dali::Integration::TouchEvent();
516 event.AddPoint( GetPointUpInside() );
517 application.ProcessEvent( event );
519 DALI_TEST_CHECK( !gPushButtonReleased );
523 int UtcDaliPushButtonSelected(void)
525 ToolkitTestApplication application;
526 tet_infoline(" UtcDaliPushButtonSelected");
528 PushButton pushButton = PushButton::New();
529 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
530 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
531 pushButton.SetPosition( 240, 400 );
532 pushButton.SetSize( 100, 100 );
534 Stage::GetCurrent().Add( pushButton );
536 application.SendNotification();
537 application.Render();
539 // connect to its touch signal
540 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
542 Dali::Integration::TouchEvent event;
544 // Test1. No togglable button.
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 // Set togglable property.
558 pushButton.SetTogglableButton( true );
560 // Test2. Touch point down and up inside the button twice.
561 gPushButtonSelectedState = false;
562 event = Dali::Integration::TouchEvent();
563 event.AddPoint( GetPointDownInside() );
564 application.ProcessEvent( event );
566 event = Dali::Integration::TouchEvent();
567 event.AddPoint( GetPointUpInside() );
568 application.ProcessEvent( event );
570 DALI_TEST_CHECK( gPushButtonSelectedState );
572 event = Dali::Integration::TouchEvent();
573 event.AddPoint( GetPointDownInside() );
574 application.ProcessEvent( event );
576 event = Dali::Integration::TouchEvent();
577 event.AddPoint( GetPointUpInside() );
578 application.ProcessEvent( event );
580 DALI_TEST_CHECK( !gPushButtonSelectedState );
582 // Test3. Touch point down and up outside the button.
584 gPushButtonSelectedState = false;
585 event = Dali::Integration::TouchEvent();
586 event.AddPoint( GetPointDownOutside() );
587 application.ProcessEvent( event );
589 event = Dali::Integration::TouchEvent();
590 event.AddPoint( GetPointUpOutside() );
591 application.ProcessEvent( event );
593 DALI_TEST_CHECK( !gPushButtonSelectedState );
595 // Test4. Touch point down inside and up outside the button.
597 gPushButtonSelectedState = false;
598 event = Dali::Integration::TouchEvent();
599 event.AddPoint( GetPointDownInside() );
600 application.ProcessEvent( event );
602 event = Dali::Integration::TouchEvent();
603 event.AddPoint( GetPointLeave() );
604 application.ProcessEvent( event );
606 event = Dali::Integration::TouchEvent();
607 event.AddPoint( GetPointUpOutside() );
608 application.ProcessEvent( event );
610 DALI_TEST_CHECK( !gPushButtonSelectedState );
612 // Test5. Touch point down outside and up inside the button.
614 gPushButtonSelectedState = false;
615 event = Dali::Integration::TouchEvent();
616 event.AddPoint( GetPointDownOutside() );
617 application.ProcessEvent( event );
619 event = Dali::Integration::TouchEvent();
620 event.AddPoint( GetPointEnter() );
621 application.ProcessEvent( event );
623 event = Dali::Integration::TouchEvent();
624 event.AddPoint( GetPointUpInside() );
625 application.ProcessEvent( event );
627 DALI_TEST_CHECK( !gPushButtonSelectedState );
631 int UtcDaliPushButtonPropertySetIconAlignment(void)
633 ToolkitTestApplication application;
634 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
636 PushButton pushButton = PushButton::New();
637 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
638 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
640 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
641 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
646 int UtcDaliPushButtonPropertySetLabelPadding(void)
648 ToolkitTestApplication application;
649 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
651 PushButton pushButton = PushButton::New();
652 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
653 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 );
655 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
656 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 );
661 int UtcDaliPushButtonPropertySetIconPadding(void)
663 ToolkitTestApplication application;
664 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
666 PushButton pushButton = PushButton::New();
667 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
668 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 );
670 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
671 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 );
676 int UtcDaliPushButtonPaddingLayout(void)
678 ToolkitTestApplication application;
679 tet_infoline(" UtcDaliPushButtonPaddingLayout");
681 // This test creates padding for an icon and a label.
682 // The icon and label are each enabled and disabled to confirm the correct padding is used.
683 PushButton pushButton = PushButton::New();
685 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
686 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
688 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
689 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
690 pushButton.SetPosition( 0.0f, 0.0f );
691 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
693 Stage::GetCurrent().Add( pushButton );
695 application.SendNotification();
696 application.Render();
698 // First test the size is zero.
699 // No padding should be added as there is no label or icon.
700 Vector2 size( Vector2::ZERO );
701 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
702 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
704 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
706 // Check label only padding.
707 pushButton.SetLabelText( "Label" );
709 application.SendNotification();
710 application.Render();
712 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
713 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
715 // 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.
716 DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION );
717 DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION );
719 // Re-initialise the button so we can setup icon-only padding.
720 pushButton.Unparent();
721 pushButton = PushButton::New();
723 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
724 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
726 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
727 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
728 pushButton.SetPosition( 0.0f, 0.0f );
729 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
731 Stage::GetCurrent().Add( pushButton );
733 const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
734 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
735 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
736 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
738 application.SendNotification();
739 application.Render();
741 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
742 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
744 DALI_TEST_EQUALS( size, Vector2( 40.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
746 // Now test padding for both label and icon simultaneously.
747 pushButton.SetLabelText( "Label" );
749 application.SendNotification();
750 application.Render();
752 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
753 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
755 // 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.
756 // Note we only test the width as we are horizontally aligned and the label my be less high than the icon.
757 // Full directional alignment tests are done in UtcDaliPushButtonAlignmentLayout.
758 DALI_TEST_GREATER( size.width, 60.0f, TEST_LOCATION );
763 int UtcDaliPushButtonAlignmentLayout(void)
765 ToolkitTestApplication application;
766 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
769 * This test checks different alignments for the icon against the label.
770 * The icon is then moved around the label in each of it's alignments.
771 * The final relayed out size is checked to confirm the layout has been done correctly.
773 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
774 * - Therefore total width and height are both 150.
776 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
777 * - Therefore total width and height are 60+x and 60+y respectively.
778 * Where x & y are the width and height of the text.
780 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
781 * So We use the padding to help us determine the orientation is correct for each alignment.
783 * |<- 150 ->| |<-- 60+x -->|
786 * | | ^ +------------+ -
788 * | Icon | 150 | Label | 60+y
790 * | | v +------------+ -
793 PushButton pushButton = PushButton::New();
795 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) );
796 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) );
798 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
799 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
800 pushButton.SetPosition( 0.0f, 0.0f );
801 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
803 Stage::GetCurrent().Add( pushButton );
805 const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
806 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
807 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
808 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
810 application.SendNotification();
811 application.Render();
813 // First get the base size (without label).
814 Vector2 baseSize( Vector2::ZERO );
815 baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
816 baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
818 DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
820 // Add a label to cause size to be modified in the direction of alignment.
821 pushButton.SetLabelText( "Label" );
823 application.SendNotification();
824 application.Render();
826 Vector2 size( Vector2::ZERO );
827 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
828 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
832 * Test Icon right alignment.
833 * Height grows to largest of Icon or Label (+ padding).
834 * Normally this will be Icons height, except with very large font sizes.
836 * +------------+---------+
842 * +------------+---------+
844 DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION );
845 DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
847 // Now test left alignment matches right for size.
848 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
850 application.SendNotification();
851 application.Render();
853 Vector2 compareSize( Vector2::ZERO );
854 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
855 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
858 * Test Icon left alignment.
859 * Height grows to largest of Icon or Label (+ padding).
860 * Normally this will be Icons height, except with very large font sizes.
862 * +---------+------------+
868 * +---------+------------+
870 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
872 // Test top alignment.
873 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
875 application.SendNotification();
876 application.Render();
878 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
879 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
882 * Test Icon top alignment.
883 * Width grows to largest of Icon or Label (+ padding).
897 * Note: We subtract a small number as we want to do a >= test.
899 DALI_TEST_GREATER( size.width, 150.0f - Math::MACHINE_EPSILON_1000, TEST_LOCATION );
900 DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION );
902 // Test bottom alignment.
903 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
905 application.SendNotification();
906 application.Render();
908 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
909 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
912 * Test Icon bottom alignment.
913 * Width grows to largest of Icon or Label (+ padding).
927 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );