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 ) );
118 int UtcDaliPushButtonConstructorP(void)
120 TestApplication application;
124 DALI_TEST_CHECK( !button );
128 int UtcDaliPushButtonCopyConstructorP(void)
130 TestApplication application;
132 // Initialize an object, ref count == 1
133 PushButton button = PushButton::New();
135 PushButton copy( button );
136 DALI_TEST_CHECK( copy );
140 int UtcDaliPushButtonAssignmentOperatorP(void)
142 TestApplication application;
144 PushButton button = PushButton::New();
146 PushButton copy( button );
147 DALI_TEST_CHECK( copy );
149 DALI_TEST_CHECK( button == copy );
153 int UtcDaliPushButtonNewP(void)
155 TestApplication application;
157 PushButton button = PushButton::New();
159 DALI_TEST_CHECK( button );
163 int UtcDaliPushButtonDownCastP(void)
165 TestApplication application;
167 PushButton button = PushButton::New();
169 BaseHandle object(button);
171 PushButton button2 = PushButton::DownCast( object );
172 DALI_TEST_CHECK(button2);
174 PushButton button3 = DownCast< PushButton >(object);
175 DALI_TEST_CHECK(button3);
179 int UtcDaliPushButtonDownCastN(void)
181 TestApplication application;
183 BaseHandle unInitializedObject;
185 PushButton button1 = PushButton::DownCast( unInitializedObject );
186 DALI_TEST_CHECK( !button1 );
188 PushButton button2 = DownCast< PushButton >( unInitializedObject );
189 DALI_TEST_CHECK( !button2 );
193 int UtcDaliPushButtonSetGetAutoRepeating(void)
195 ToolkitTestApplication application;
196 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
198 PushButton pushButton = PushButton::New();
200 pushButton.SetAutoRepeating( true );
202 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
204 pushButton.SetAutoRepeating( false );
206 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
208 pushButton.SetAutoRepeating( true );
210 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
214 int UtcDaliPushButtonSetGetTogglableButton(void)
216 ToolkitTestApplication application;
217 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
219 PushButton pushButton = PushButton::New();
221 pushButton.SetTogglableButton( true );
223 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
225 pushButton.SetTogglableButton( false );
227 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
229 pushButton.SetTogglableButton( true );
231 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
235 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
237 ToolkitTestApplication application;
238 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
240 PushButton pushButton = PushButton::New();
242 pushButton.SetAutoRepeating( true );
243 pushButton.SetTogglableButton( true );
245 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
246 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
248 pushButton.SetTogglableButton( true );
249 pushButton.SetAutoRepeating( true );
251 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
252 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
256 int UtcDaliPushButtonSetGetSelected01(void)
258 ToolkitTestApplication application;
259 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
261 PushButton pushButton = PushButton::New();
263 pushButton.SetTogglableButton( true );
264 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
266 gPushButtonSelectedState = false;
267 pushButton.SetSelected( true );
269 DALI_TEST_CHECK( pushButton.IsSelected() );
270 DALI_TEST_CHECK( gPushButtonSelectedState );
272 pushButton.SetSelected( false );
274 DALI_TEST_CHECK( !pushButton.IsSelected() );
275 DALI_TEST_CHECK( !gPushButtonSelectedState );
277 pushButton.SetSelected( true );
279 DALI_TEST_CHECK( pushButton.IsSelected() );
280 DALI_TEST_CHECK( gPushButtonSelectedState );
284 int UtcDaliPushButtonSetGetSelected02(void)
286 ToolkitTestApplication application;
287 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
289 PushButton pushButton = PushButton::New();
291 pushButton.SetTogglableButton( false );
292 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
294 gPushButtonSelectedState = false;
295 pushButton.SetSelected( true );
297 DALI_TEST_CHECK( !pushButton.IsSelected() );
298 DALI_TEST_CHECK( !gPushButtonSelectedState );
300 pushButton.SetSelected( false );
302 DALI_TEST_CHECK( !pushButton.IsSelected() );
303 DALI_TEST_CHECK( !gPushButtonSelectedState );
305 pushButton.SetSelected( true );
307 DALI_TEST_CHECK( !pushButton.IsSelected() );
308 DALI_TEST_CHECK( !gPushButtonSelectedState );
312 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
314 ToolkitTestApplication application;
315 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
317 PushButton pushButton = PushButton::New();
319 pushButton.SetAutoRepeating( true );
321 pushButton.SetInitialAutoRepeatingDelay( 1.f );
322 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
324 pushButton.SetNextAutoRepeatingDelay( 1.f );
325 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
329 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
331 ToolkitTestApplication application;
332 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
334 PushButton pushButton = PushButton::New();
336 bool assert1( false );
337 bool assert2( false );
339 pushButton.SetAutoRepeating( true );
343 pushButton.SetInitialAutoRepeatingDelay( -1.f );
345 catch( Dali::DaliException& e )
347 DALI_TEST_PRINT_ASSERT( e );
348 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
354 pushButton.SetNextAutoRepeatingDelay( -1.f );
356 catch( Dali::DaliException& e )
358 DALI_TEST_PRINT_ASSERT( e );
359 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
363 DALI_TEST_CHECK( assert1 && assert2 );
367 int UtcDaliPushButtonSetLabelText(void)
369 ToolkitTestApplication application;
370 tet_infoline(" UtcDaliPushButtonSetLabelText");
372 const std::string STR( "Hola!" );
374 PushButton pushButton = PushButton::New();
376 application.SendNotification();
377 application.Render();
379 pushButton.SetLabelText( STR );
381 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
386 int UtcDaliPushButtonPressed(void)
388 ToolkitTestApplication application;
389 tet_infoline(" UtcDaliPushButtonPressed");
391 PushButton pushButton = PushButton::New();
392 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
393 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
394 pushButton.SetPosition( 240, 400 );
395 pushButton.SetSize( 100, 100 );
397 Stage::GetCurrent().Add( pushButton );
399 application.SendNotification();
400 application.Render();
402 gPushButtonPressed = false;
404 // connect to its touch signal
405 pushButton.PressedSignal().Connect( &PushButtonPressed );
407 Dali::Integration::TouchEvent eventDown;
408 eventDown.AddPoint( GetPointDownInside() );
410 // flush the queue and render once
411 application.SendNotification();
412 application.Render();
413 application.ProcessEvent( eventDown );
415 DALI_TEST_CHECK( gPushButtonPressed );
419 int UtcDaliPushButtonReleased(void)
421 ToolkitTestApplication application;
422 tet_infoline(" UtcDaliPushButtonReleased");
424 PushButton pushButton = PushButton::New();
425 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
426 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
427 pushButton.SetPosition( 240, 400 );
428 pushButton.SetSize( 100, 100 );
430 Stage::GetCurrent().Add( pushButton );
432 application.SendNotification();
433 application.Render();
435 // connect to its touch signal
436 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
438 Dali::Integration::TouchEvent event;
440 // Test1. Touch point down and up inside the button.
442 gPushButtonReleased = false;
443 event = Dali::Integration::TouchEvent();
444 event.AddPoint( GetPointDownInside() );
445 application.ProcessEvent( event );
447 event = Dali::Integration::TouchEvent();
448 event.AddPoint( GetPointUpInside() );
449 application.ProcessEvent( event );
451 DALI_TEST_CHECK( gPushButtonReleased );
453 // Test2. Touch point down and up outside the button.
455 gPushButtonReleased = false;
456 event = Dali::Integration::TouchEvent();
457 event.AddPoint( GetPointDownOutside() );
458 application.ProcessEvent( event );
460 event = Dali::Integration::TouchEvent();
461 event.AddPoint( GetPointUpOutside() );
462 application.ProcessEvent( event );
464 DALI_TEST_CHECK( !gPushButtonReleased );
466 // Test3. Touch point down inside and up outside the button.
468 gPushButtonReleased = false;
469 event = Dali::Integration::TouchEvent();
470 event.AddPoint( GetPointDownInside() );
471 application.ProcessEvent( event );
473 event = Dali::Integration::TouchEvent();
474 event.AddPoint( GetPointLeave() );
475 application.ProcessEvent( event );
477 event = Dali::Integration::TouchEvent();
478 event.AddPoint( GetPointUpOutside() );
479 application.ProcessEvent( event );
481 DALI_TEST_CHECK( gPushButtonReleased );
483 // Test4. Touch point down outside and up inside the button.
485 gPushButtonReleased = false;
486 event = Dali::Integration::TouchEvent();
487 event.AddPoint( GetPointDownOutside() );
488 application.ProcessEvent( event );
490 event = Dali::Integration::TouchEvent();
491 event.AddPoint( GetPointEnter() );
492 application.ProcessEvent( event );
494 event = Dali::Integration::TouchEvent();
495 event.AddPoint( GetPointUpInside() );
496 application.ProcessEvent( event );
498 DALI_TEST_CHECK( !gPushButtonReleased );
502 int UtcDaliPushButtonSelected(void)
504 ToolkitTestApplication application;
505 tet_infoline(" UtcDaliPushButtonSelected");
507 PushButton pushButton = PushButton::New();
508 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
509 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
510 pushButton.SetPosition( 240, 400 );
511 pushButton.SetSize( 100, 100 );
513 Stage::GetCurrent().Add( pushButton );
515 application.SendNotification();
516 application.Render();
518 // connect to its touch signal
519 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
521 Dali::Integration::TouchEvent event;
523 // Test1. No togglable button.
525 gPushButtonSelectedState = false;
526 event = Dali::Integration::TouchEvent();
527 event.AddPoint( GetPointDownInside() );
528 application.ProcessEvent( event );
530 event = Dali::Integration::TouchEvent();
531 event.AddPoint( GetPointUpInside() );
532 application.ProcessEvent( event );
534 DALI_TEST_CHECK( !gPushButtonSelectedState );
536 // Set togglable property.
537 pushButton.SetTogglableButton( true );
539 // Test2. Touch point down and up inside the button twice.
540 gPushButtonSelectedState = false;
541 event = Dali::Integration::TouchEvent();
542 event.AddPoint( GetPointDownInside() );
543 application.ProcessEvent( event );
545 event = Dali::Integration::TouchEvent();
546 event.AddPoint( GetPointUpInside() );
547 application.ProcessEvent( event );
549 DALI_TEST_CHECK( gPushButtonSelectedState );
551 event = Dali::Integration::TouchEvent();
552 event.AddPoint( GetPointDownInside() );
553 application.ProcessEvent( event );
555 event = Dali::Integration::TouchEvent();
556 event.AddPoint( GetPointUpInside() );
557 application.ProcessEvent( event );
559 DALI_TEST_CHECK( !gPushButtonSelectedState );
561 // Test3. Touch point down and up outside the button.
563 gPushButtonSelectedState = false;
564 event = Dali::Integration::TouchEvent();
565 event.AddPoint( GetPointDownOutside() );
566 application.ProcessEvent( event );
568 event = Dali::Integration::TouchEvent();
569 event.AddPoint( GetPointUpOutside() );
570 application.ProcessEvent( event );
572 DALI_TEST_CHECK( !gPushButtonSelectedState );
574 // Test4. Touch point down inside and up outside the button.
576 gPushButtonSelectedState = false;
577 event = Dali::Integration::TouchEvent();
578 event.AddPoint( GetPointDownInside() );
579 application.ProcessEvent( event );
581 event = Dali::Integration::TouchEvent();
582 event.AddPoint( GetPointLeave() );
583 application.ProcessEvent( event );
585 event = Dali::Integration::TouchEvent();
586 event.AddPoint( GetPointUpOutside() );
587 application.ProcessEvent( event );
589 DALI_TEST_CHECK( !gPushButtonSelectedState );
591 // Test5. Touch point down outside and up inside the button.
593 gPushButtonSelectedState = false;
594 event = Dali::Integration::TouchEvent();
595 event.AddPoint( GetPointDownOutside() );
596 application.ProcessEvent( event );
598 event = Dali::Integration::TouchEvent();
599 event.AddPoint( GetPointEnter() );
600 application.ProcessEvent( event );
602 event = Dali::Integration::TouchEvent();
603 event.AddPoint( GetPointUpInside() );
604 application.ProcessEvent( event );
606 DALI_TEST_CHECK( !gPushButtonSelectedState );
610 int UtcDaliPushButtonPropertySetIconAlignment(void)
612 ToolkitTestApplication application;
613 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
615 PushButton pushButton = PushButton::New();
616 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
617 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
619 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
620 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
625 int UtcDaliPushButtonPropertySetLabelPadding(void)
627 ToolkitTestApplication application;
628 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
630 PushButton pushButton = PushButton::New();
631 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
632 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 );
634 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
635 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 );
640 int UtcDaliPushButtonPropertySetIconPadding(void)
642 ToolkitTestApplication application;
643 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
645 PushButton pushButton = PushButton::New();
646 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
647 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 );
649 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
650 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 );
655 int UtcDaliPushButtonPaddingLayout(void)
657 ToolkitTestApplication application;
658 tet_infoline(" UtcDaliPushButtonPaddingLayout");
660 // This test creates padding for an icon and a label.
661 // The icon and label are each enabled and disabled to confirm the correct padding is used.
662 PushButton pushButton = PushButton::New();
664 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
665 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
667 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
668 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
669 pushButton.SetPosition( 0.0f, 0.0f );
670 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
672 Stage::GetCurrent().Add( pushButton );
674 application.SendNotification();
675 application.Render();
677 // First test the size is zero.
678 // No padding should be added as there is no label or icon.
679 Vector2 size( Vector2::ZERO );
680 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
681 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
683 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
685 // Check label only padding.
686 pushButton.SetLabelText( "Label" );
688 application.SendNotification();
689 application.Render();
691 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
692 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
694 // 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.
695 DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION );
696 DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION );
698 // Re-initialise the button so we can setup icon-only padding.
699 pushButton.Unparent();
700 pushButton = PushButton::New();
702 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
703 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
705 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
706 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
707 pushButton.SetPosition( 0.0f, 0.0f );
708 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
710 Stage::GetCurrent().Add( pushButton );
712 const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
713 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
714 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
715 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
717 application.SendNotification();
718 application.Render();
720 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
721 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
723 DALI_TEST_EQUALS( size, Vector2( 40.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
725 // Now test padding for both label and icon simultaneously.
726 pushButton.SetLabelText( "Label" );
728 application.SendNotification();
729 application.Render();
731 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
732 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
734 // 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.
735 // Note we only test the width as we are horizontally aligned and the label my be less high than the icon.
736 // Full directional alignment tests are done in UtcDaliPushButtonAlignmentLayout.
737 DALI_TEST_GREATER( size.width, 60.0f, TEST_LOCATION );
742 int UtcDaliPushButtonAlignmentLayout(void)
744 ToolkitTestApplication application;
745 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
748 * This test checks different alignments for the icon against the label.
749 * The icon is then moved around the label in each of it's alignments.
750 * The final relayed out size is checked to confirm the layout has been done correctly.
752 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
753 * - Therefore total width and height are both 150.
755 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
756 * - Therefore total width and height are 60+x and 60+y respectively.
757 * Where x & y are the width and height of the text.
759 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
760 * So We use the padding to help us determine the orientation is correct for each alignment.
762 * |<- 150 ->| |<-- 60+x -->|
765 * | | ^ +------------+ -
767 * | Icon | 150 | Label | 60+y
769 * | | v +------------+ -
772 PushButton pushButton = PushButton::New();
774 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) );
775 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) );
777 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
778 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
779 pushButton.SetPosition( 0.0f, 0.0f );
780 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
782 Stage::GetCurrent().Add( pushButton );
784 const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
785 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
786 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
787 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
789 application.SendNotification();
790 application.Render();
792 // First get the base size (without label).
793 Vector2 baseSize( Vector2::ZERO );
794 baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
795 baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
797 DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
799 // Add a label to cause size to be modified in the direction of alignment.
800 pushButton.SetLabelText( "Label" );
802 application.SendNotification();
803 application.Render();
805 Vector2 size( Vector2::ZERO );
806 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
807 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
811 * Test Icon right alignment.
812 * Height grows to largest of Icon or Label (+ padding).
813 * Normally this will be Icons height, except with very large font sizes.
815 * +------------+---------+
821 * +------------+---------+
823 DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION );
824 DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
826 // Now test left alignment matches right for size.
827 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
829 application.SendNotification();
830 application.Render();
832 Vector2 compareSize( Vector2::ZERO );
833 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
834 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
837 * Test Icon left alignment.
838 * Height grows to largest of Icon or Label (+ padding).
839 * Normally this will be Icons height, except with very large font sizes.
841 * +---------+------------+
847 * +---------+------------+
849 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
851 // Test top alignment.
852 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
854 application.SendNotification();
855 application.Render();
857 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
858 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
861 * Test Icon top alignment.
862 * Width grows to largest of Icon or Label (+ padding).
876 * Note: We subtract a small number as we want to do a >= test.
878 DALI_TEST_GREATER( size.width, 150.0f - Math::MACHINE_EPSILON_1000, TEST_LOCATION );
879 DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION );
881 // Test bottom alignment.
882 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
884 application.SendNotification();
885 application.Render();
887 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
888 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
891 * Test Icon bottom alignment.
892 * Width grows to largest of Icon or Label (+ padding).
906 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
911 int UtcDaliPushButtonSetButtonImageP(void)
913 ToolkitTestApplication application;
915 PushButton button = PushButton::New();
916 Stage::GetCurrent().Add( button );
920 button.SetButtonImage( ImageView::New() );
921 DALI_TEST_CHECK( true );
925 DALI_TEST_CHECK( false );
931 int UtcDaliPushButtonSetButtonImageN(void)
933 ToolkitTestApplication application;
939 button.SetSelectedImage( ImageView::New() );
940 DALI_TEST_CHECK( false );
944 DALI_TEST_CHECK( true );
950 int UtcDaliPushButtonSetBackgroundImageP(void)
952 ToolkitTestApplication application;
954 PushButton button = PushButton::New();
955 Stage::GetCurrent().Add( button );
959 button.SetBackgroundImage( ImageView::New() );
960 DALI_TEST_CHECK( true );
964 DALI_TEST_CHECK( false );
970 int UtcDaliPushButtonSetBackgroundImageN(void)
972 ToolkitTestApplication application;
978 button.SetBackgroundImage( ImageView::New() );
979 DALI_TEST_CHECK( false );
983 DALI_TEST_CHECK( true );
989 int UtcDaliPushButtonSetSelectedImageP(void)
991 ToolkitTestApplication application;
993 PushButton button = PushButton::New();
994 Stage::GetCurrent().Add( button );
998 button.SetSelectedImage( ImageView::New() );
999 DALI_TEST_CHECK( true );
1003 DALI_TEST_CHECK( false );
1009 int UtcDaliPushButtonSetSelectedImageN(void)
1011 ToolkitTestApplication application;
1017 button.SetSelectedImage( ImageView::New() );
1018 DALI_TEST_CHECK( false );
1022 DALI_TEST_CHECK( true );
1028 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1030 ToolkitTestApplication application;
1032 PushButton button = PushButton::New();
1033 Stage::GetCurrent().Add( button );
1037 button.SetSelectedBackgroundImage( ImageView::New() );
1038 DALI_TEST_CHECK( true );
1042 DALI_TEST_CHECK( false );
1048 int UtcDaliPushButtonSetSelectedBackgroundImageN(void)
1050 ToolkitTestApplication application;
1056 button.SetSelectedBackgroundImage( ImageView::New() );
1057 DALI_TEST_CHECK( false );
1061 DALI_TEST_CHECK( true );
1067 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1069 ToolkitTestApplication application;
1071 PushButton button = PushButton::New();
1072 Stage::GetCurrent().Add( button );
1076 button.SetDisabledBackgroundImage( ImageView::New() );
1077 DALI_TEST_CHECK( true );
1081 DALI_TEST_CHECK( false );
1087 int UtcDaliPushButtonSetDisabledBackgroundImageN(void)
1089 ToolkitTestApplication application;
1095 button.SetDisabledBackgroundImage( ImageView::New() );
1096 DALI_TEST_CHECK( false );
1100 DALI_TEST_CHECK( true );
1106 int UtcDaliPushButtonSetDisabledImageP(void)
1108 ToolkitTestApplication application;
1110 PushButton button = PushButton::New();
1111 Stage::GetCurrent().Add( button );
1115 button.SetDisabledImage( ImageView::New() );
1116 DALI_TEST_CHECK( true );
1120 DALI_TEST_CHECK( false );
1126 int UtcDaliPushButtonSetDisabledImageN(void)
1128 ToolkitTestApplication application;
1134 button.SetDisabledImage( ImageView::New() );
1135 DALI_TEST_CHECK( false );
1139 DALI_TEST_CHECK( true );
1145 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1147 ToolkitTestApplication application;
1149 PushButton button = PushButton::New();
1150 Stage::GetCurrent().Add( button );
1154 button.SetDisabledSelectedImage( ImageView::New() );
1155 DALI_TEST_CHECK( true );
1159 DALI_TEST_CHECK( false );
1165 int UtcDaliPushButtonSetDisabledSelectedImageN(void)
1167 ToolkitTestApplication application;
1173 button.SetDisabledSelectedImage( ImageView::New() );
1174 DALI_TEST_CHECK( false );
1178 DALI_TEST_CHECK( true );