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;
44 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
46 static bool gPushButtonSelectedState = false;
47 bool PushButtonSelected( Button button )
49 gPushButtonSelectedState = button.IsSelected();
53 static bool gPushButtonPressed = false;
55 static bool PushButtonPressed( Button button )
57 gPushButtonPressed = true;
61 static bool gPushButtonReleased = false;
63 static bool PushButtonReleased( Button button )
65 gPushButtonReleased = true;
69 Dali::Integration::Point GetPointDownInside()
71 Dali::Integration::Point point;
72 point.SetState( PointState::DOWN );
73 point.SetScreenPosition( Vector2( 240, 400 ) );
77 Dali::Integration::Point GetPointUpInside()
79 Dali::Integration::Point point;
80 point.SetState( PointState::UP );
81 point.SetScreenPosition( Vector2( 240, 400 ) );
85 Dali::Integration::Point GetPointLeave()
87 Dali::Integration::Point point;
88 point.SetState( PointState::LEAVE );
89 point.SetScreenPosition( Vector2( 240, 400 ) );
93 Dali::Integration::Point GetPointEnter()
95 Dali::Integration::Point point;
96 point.SetState( PointState::MOTION );
97 point.SetScreenPosition( Vector2( 240, 400 ) );
101 Dali::Integration::Point GetPointDownOutside()
103 Dali::Integration::Point point;
104 point.SetState( PointState::DOWN );
105 point.SetScreenPosition( Vector2( 10, 10 ) );
109 Dali::Integration::Point GetPointUpOutside()
111 Dali::Integration::Point point;
112 point.SetState( PointState::UP );
113 point.SetScreenPosition( Vector2( 10, 10 ) );
119 int UtcDaliPushButtonConstructorP(void)
121 TestApplication application;
125 DALI_TEST_CHECK( !button );
129 int UtcDaliPushButtonCopyConstructorP(void)
131 TestApplication application;
133 // Initialize an object, ref count == 1
134 PushButton button = PushButton::New();
136 PushButton copy( button );
137 DALI_TEST_CHECK( copy );
141 int UtcDaliPushButtonAssignmentOperatorP(void)
143 TestApplication application;
145 PushButton button = PushButton::New();
147 PushButton copy( button );
148 DALI_TEST_CHECK( copy );
150 DALI_TEST_CHECK( button == copy );
154 int UtcDaliPushButtonNewP(void)
156 TestApplication application;
158 PushButton button = PushButton::New();
160 DALI_TEST_CHECK( button );
164 int UtcDaliPushButtonDownCastP(void)
166 TestApplication application;
168 PushButton button = PushButton::New();
170 BaseHandle object(button);
172 PushButton button2 = PushButton::DownCast( object );
173 DALI_TEST_CHECK(button2);
175 PushButton button3 = DownCast< PushButton >(object);
176 DALI_TEST_CHECK(button3);
180 int UtcDaliPushButtonDownCastN(void)
182 TestApplication application;
184 BaseHandle unInitializedObject;
186 PushButton button1 = PushButton::DownCast( unInitializedObject );
187 DALI_TEST_CHECK( !button1 );
189 PushButton button2 = DownCast< PushButton >( unInitializedObject );
190 DALI_TEST_CHECK( !button2 );
194 int UtcDaliPushButtonSetGetAutoRepeating(void)
196 ToolkitTestApplication application;
197 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
199 PushButton pushButton = PushButton::New();
201 pushButton.SetAutoRepeating( true );
203 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
205 pushButton.SetAutoRepeating( false );
207 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
209 pushButton.SetAutoRepeating( true );
211 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
215 int UtcDaliPushButtonSetAutoRepeating(void)
217 ToolkitTestApplication application;
218 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
219 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
220 PushButton pushButton = PushButton::New();
222 const bool INITIAL_TOGGLE_VALUE = true;
223 const bool INITIAL_SELECTED_VALUE = true;
225 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
226 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
228 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
229 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
231 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
233 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
238 int UtcDaliPushButtonSetGetTogglableButton(void)
240 ToolkitTestApplication application;
241 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
243 PushButton pushButton = PushButton::New();
245 pushButton.SetTogglableButton( true );
247 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
249 pushButton.SetTogglableButton( false );
251 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
253 pushButton.SetTogglableButton( true );
255 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
259 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
261 ToolkitTestApplication application;
262 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
264 PushButton pushButton = PushButton::New();
266 pushButton.SetAutoRepeating( true );
267 pushButton.SetTogglableButton( true );
269 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
270 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
272 pushButton.SetTogglableButton( true );
273 pushButton.SetAutoRepeating( true );
275 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
276 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
280 int UtcDaliPushButtonSetGetSelected01(void)
282 ToolkitTestApplication application;
283 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
285 PushButton pushButton = PushButton::New();
287 pushButton.SetTogglableButton( true );
288 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
290 gPushButtonSelectedState = false;
291 pushButton.SetSelected( true );
293 DALI_TEST_CHECK( pushButton.IsSelected() );
294 DALI_TEST_CHECK( gPushButtonSelectedState );
296 pushButton.SetSelected( false );
298 DALI_TEST_CHECK( !pushButton.IsSelected() );
299 DALI_TEST_CHECK( !gPushButtonSelectedState );
301 pushButton.SetSelected( true );
303 DALI_TEST_CHECK( pushButton.IsSelected() );
304 DALI_TEST_CHECK( gPushButtonSelectedState );
308 int UtcDaliPushButtonSetGetSelected02(void)
310 ToolkitTestApplication application;
311 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
313 PushButton pushButton = PushButton::New();
315 pushButton.SetTogglableButton( false );
316 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
318 gPushButtonSelectedState = false;
319 pushButton.SetSelected( true );
321 DALI_TEST_CHECK( !pushButton.IsSelected() );
322 DALI_TEST_CHECK( !gPushButtonSelectedState );
324 pushButton.SetSelected( false );
326 DALI_TEST_CHECK( !pushButton.IsSelected() );
327 DALI_TEST_CHECK( !gPushButtonSelectedState );
329 pushButton.SetSelected( true );
331 DALI_TEST_CHECK( !pushButton.IsSelected() );
332 DALI_TEST_CHECK( !gPushButtonSelectedState );
336 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
338 ToolkitTestApplication application;
339 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
341 PushButton pushButton = PushButton::New();
343 pushButton.SetAutoRepeating( true );
345 pushButton.SetInitialAutoRepeatingDelay( 1.f );
346 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
348 pushButton.SetNextAutoRepeatingDelay( 1.f );
349 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
353 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
355 ToolkitTestApplication application;
356 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
358 PushButton pushButton = PushButton::New();
360 bool assert1( false );
361 bool assert2( false );
363 pushButton.SetAutoRepeating( true );
367 pushButton.SetInitialAutoRepeatingDelay( -1.f );
369 catch( Dali::DaliException& e )
371 DALI_TEST_PRINT_ASSERT( e );
372 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
378 pushButton.SetNextAutoRepeatingDelay( -1.f );
380 catch( Dali::DaliException& e )
382 DALI_TEST_PRINT_ASSERT( e );
383 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
387 DALI_TEST_CHECK( assert1 && assert2 );
391 int UtcDaliPushButtonSetLabelText(void)
393 ToolkitTestApplication application;
394 tet_infoline(" UtcDaliPushButtonSetLabelText");
396 const std::string STR( "Hola!" );
398 PushButton pushButton = PushButton::New();
400 application.SendNotification();
401 application.Render();
403 pushButton.SetLabelText( STR );
405 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
410 int UtcDaliPushButtonPressed(void)
412 ToolkitTestApplication application;
413 tet_infoline(" UtcDaliPushButtonPressed");
415 PushButton pushButton = PushButton::New();
416 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
417 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
418 pushButton.SetPosition( 240, 400 );
419 pushButton.SetSize( 100, 100 );
421 Stage::GetCurrent().Add( pushButton );
423 application.SendNotification();
424 application.Render();
426 gPushButtonPressed = false;
428 // connect to its touch signal
429 pushButton.PressedSignal().Connect( &PushButtonPressed );
431 Dali::Integration::TouchEvent eventDown;
432 eventDown.AddPoint( GetPointDownInside() );
434 // flush the queue and render once
435 application.SendNotification();
436 application.Render();
437 application.ProcessEvent( eventDown );
439 DALI_TEST_CHECK( gPushButtonPressed );
443 int UtcDaliPushButtonReleased(void)
445 ToolkitTestApplication application;
446 tet_infoline(" UtcDaliPushButtonReleased");
448 PushButton pushButton = PushButton::New();
449 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
450 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
451 pushButton.SetPosition( 240, 400 );
452 pushButton.SetSize( 100, 100 );
454 Stage::GetCurrent().Add( pushButton );
456 application.SendNotification();
457 application.Render();
459 // connect to its touch signal
460 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
462 Dali::Integration::TouchEvent event;
464 // Test1. Touch point down and up inside the button.
466 gPushButtonReleased = false;
467 event = Dali::Integration::TouchEvent();
468 event.AddPoint( GetPointDownInside() );
469 application.ProcessEvent( event );
471 event = Dali::Integration::TouchEvent();
472 event.AddPoint( GetPointUpInside() );
473 application.ProcessEvent( event );
475 DALI_TEST_CHECK( gPushButtonReleased );
477 // Test2. Touch point down and up outside the button.
479 gPushButtonReleased = false;
480 event = Dali::Integration::TouchEvent();
481 event.AddPoint( GetPointDownOutside() );
482 application.ProcessEvent( event );
484 event = Dali::Integration::TouchEvent();
485 event.AddPoint( GetPointUpOutside() );
486 application.ProcessEvent( event );
488 DALI_TEST_CHECK( !gPushButtonReleased );
490 // Test3. Touch point down inside and up outside the button.
492 gPushButtonReleased = false;
493 event = Dali::Integration::TouchEvent();
494 event.AddPoint( GetPointDownInside() );
495 application.ProcessEvent( event );
497 event = Dali::Integration::TouchEvent();
498 event.AddPoint( GetPointLeave() );
499 application.ProcessEvent( event );
501 event = Dali::Integration::TouchEvent();
502 event.AddPoint( GetPointUpOutside() );
503 application.ProcessEvent( event );
505 DALI_TEST_CHECK( gPushButtonReleased );
507 // Test4. Touch point down outside and up inside the button.
509 gPushButtonReleased = false;
510 event = Dali::Integration::TouchEvent();
511 event.AddPoint( GetPointDownOutside() );
512 application.ProcessEvent( event );
514 event = Dali::Integration::TouchEvent();
515 event.AddPoint( GetPointEnter() );
516 application.ProcessEvent( event );
518 event = Dali::Integration::TouchEvent();
519 event.AddPoint( GetPointUpInside() );
520 application.ProcessEvent( event );
522 DALI_TEST_CHECK( !gPushButtonReleased );
526 int UtcDaliPushButtonSelected(void)
528 ToolkitTestApplication application;
529 tet_infoline(" UtcDaliPushButtonSelected");
531 PushButton pushButton = PushButton::New();
532 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
533 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
534 pushButton.SetPosition( 240, 400 );
535 pushButton.SetSize( 100, 100 );
537 Stage::GetCurrent().Add( pushButton );
539 application.SendNotification();
540 application.Render();
542 // connect to its touch signal
543 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
545 Dali::Integration::TouchEvent event;
547 // Test1. No togglable button.
549 gPushButtonSelectedState = false;
550 event = Dali::Integration::TouchEvent();
551 event.AddPoint( GetPointDownInside() );
552 application.ProcessEvent( event );
554 event = Dali::Integration::TouchEvent();
555 event.AddPoint( GetPointUpInside() );
556 application.ProcessEvent( event );
558 DALI_TEST_CHECK( !gPushButtonSelectedState );
560 // Set togglable property.
561 pushButton.SetTogglableButton( true );
563 // Test2. Touch point down and up inside the button twice.
564 gPushButtonSelectedState = false;
565 event = Dali::Integration::TouchEvent();
566 event.AddPoint( GetPointDownInside() );
567 application.ProcessEvent( event );
569 event = Dali::Integration::TouchEvent();
570 event.AddPoint( GetPointUpInside() );
571 application.ProcessEvent( event );
573 DALI_TEST_CHECK( gPushButtonSelectedState );
575 event = Dali::Integration::TouchEvent();
576 event.AddPoint( GetPointDownInside() );
577 application.ProcessEvent( event );
579 event = Dali::Integration::TouchEvent();
580 event.AddPoint( GetPointUpInside() );
581 application.ProcessEvent( event );
583 DALI_TEST_CHECK( !gPushButtonSelectedState );
585 // Test3. Touch point down and up outside the button.
587 gPushButtonSelectedState = false;
588 event = Dali::Integration::TouchEvent();
589 event.AddPoint( GetPointDownOutside() );
590 application.ProcessEvent( event );
592 event = Dali::Integration::TouchEvent();
593 event.AddPoint( GetPointUpOutside() );
594 application.ProcessEvent( event );
596 DALI_TEST_CHECK( !gPushButtonSelectedState );
598 // Test4. Touch point down inside and up outside the button.
599 // State changes on Button down
600 gPushButtonSelectedState = false;
601 event = Dali::Integration::TouchEvent();
602 event.AddPoint( GetPointDownInside() );
603 application.ProcessEvent( event );
605 event = Dali::Integration::TouchEvent();
606 event.AddPoint( GetPointLeave() );
607 application.ProcessEvent( event );
609 event = Dali::Integration::TouchEvent();
610 event.AddPoint( GetPointUpOutside() );
611 application.ProcessEvent( event );
613 DALI_TEST_CHECK( gPushButtonSelectedState );
615 // Test5. Touch point down outside and up inside the button.
616 // Start in unselected state
617 pushButton.SetProperty( Button::Property::SELECTED, false );
618 DALI_TEST_CHECK( !pushButton.IsSelected());
620 gPushButtonSelectedState = false;
621 event = Dali::Integration::TouchEvent();
622 event.AddPoint( GetPointDownOutside() );
623 application.ProcessEvent( event );
625 event = Dali::Integration::TouchEvent();
626 event.AddPoint( GetPointEnter() );
627 application.ProcessEvent( event );
629 event = Dali::Integration::TouchEvent();
630 event.AddPoint( GetPointUpInside() );
631 application.ProcessEvent( event );
633 DALI_TEST_CHECK( !gPushButtonSelectedState );
637 int UtcDaliPushButtonPropertySetIconAlignment(void)
639 ToolkitTestApplication application;
640 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
642 PushButton pushButton = PushButton::New();
643 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
644 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
646 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
647 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
652 int UtcDaliPushButtonPropertySetLabelPadding(void)
654 ToolkitTestApplication application;
655 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
657 PushButton pushButton = PushButton::New();
658 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
659 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 );
661 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
662 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 );
667 int UtcDaliPushButtonPropertySetIconPadding(void)
669 ToolkitTestApplication application;
670 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
672 PushButton pushButton = PushButton::New();
673 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
674 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 );
676 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
677 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 );
682 int UtcDaliPushButtonPaddingLayout(void)
684 ToolkitTestApplication application;
685 tet_infoline(" UtcDaliPushButtonPaddingLayout");
687 // This test creates padding for an icon and a label.
688 // The icon and label are each enabled and disabled to confirm the correct padding is used.
689 PushButton pushButton = PushButton::New();
691 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
692 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f );
693 const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f);
695 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
696 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
697 pushButton.SetPosition( 0.0f, 0.0f );
698 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
700 Stage::GetCurrent().Add( pushButton );
702 application.SendNotification();
703 application.Render();
705 // First test the size is zero.
706 // No padding should be added as there is no label or icon.
707 Vector2 size( Vector2::ZERO );
708 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
709 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
710 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
712 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
714 // Check label only padding
715 pushButton.SetLabelText( "Label" );
717 application.SendNotification();
718 application.Render();
720 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
721 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
722 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
724 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
726 // Add label padding to label
727 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
728 application.SendNotification();
729 application.Render();
731 Vector2 sizeLabelAndPadding( Vector2::ZERO );
732 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
733 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
734 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
736 // If control size has increased beyond size of just label then padding has been applied
737 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
738 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
740 // Re-initialise the button so we can setup icon-only padding.
741 pushButton.Unparent();
742 pushButton = PushButton::New();
744 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
745 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
746 pushButton.SetPosition( 0.0f, 0.0f );
747 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
749 Stage::GetCurrent().Add( pushButton );
751 TestPlatformAbstraction& platform = application.GetPlatform();
752 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
754 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
755 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
756 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
758 application.SendNotification();
759 application.Render();
761 // Size of button with just icon
762 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
763 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
764 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
766 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
768 application.SendNotification();
769 application.Render();
770 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
772 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
773 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
774 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
775 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 );
776 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
778 // Now test padding for both label and icon simultaneously.
779 pushButton.SetLabelText( "Label" );
780 application.SendNotification();
781 application.Render();
783 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
784 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
785 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
787 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
789 application.SendNotification();
790 application.Render();
792 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
793 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
794 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
796 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
797 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.
802 int UtcDaliPushButtonAlignmentLayout(void)
804 ToolkitTestApplication application;
805 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
808 * This test checks different alignments for the icon against the label.
809 * The icon is then moved around the label in each of it's alignments.
810 * The final relayed out size is checked to confirm the layout has been done correctly.
812 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
813 * - Therefore total width and height are both 150.
815 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
816 * - Therefore total width and height are 60+x and 60+y respectively.
817 * Where x & y are the width and height of the text.
819 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
820 * So We use the padding to help us determine the orientation is correct for each alignment.
822 * |<- 150 ->| |<-- 60+x -->|
825 * | | ^ +------------+ -
827 * | Icon | 150 | Label | 60+y
829 * | | v +------------+ -
833 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
834 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
835 const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f);
837 PushButton pushButton = PushButton::New();
839 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
840 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
841 pushButton.SetPosition( 0.0f, 0.0f );
842 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
844 Stage::GetCurrent().Add( pushButton );
846 // Add a label and get size of control
847 pushButton.SetLabelText( "Label" );
848 application.SendNotification();
849 application.Render();
851 // First get the size of control with just label
852 Vector2 justLabelSize( Vector2::ZERO );
853 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
854 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
855 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
857 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
858 application.SendNotification();
859 application.Render();
861 // Size of Label and Padding
862 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
863 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
864 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
866 Vector2 labelAndPaddingSize( Vector2::ZERO );
867 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
868 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
870 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
872 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
873 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
875 TestPlatformAbstraction& platform = application.GetPlatform();
876 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
878 // Add Icon and set its alignment
879 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
880 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
881 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
882 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
884 application.SendNotification();
885 application.Render();
887 Vector2 size( Vector2::ZERO );
888 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
889 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
892 * Test Icon right alignment.
893 * Height grows to largest of Icon or Label (+ padding).
894 * Normally this will be Icons height, except with very large font sizes.
896 * +------------+---------+
902 * +------------+---------+
904 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
905 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
907 // Now test left alignment matches right for size.
908 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
910 application.SendNotification();
911 application.Render();
913 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
914 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
917 * Test Icon left alignment.
918 * Height grows to largest of Icon or Label (+ padding).
919 * Normally this will be Icons height, except with very large font sizes.
921 * +---------+------------+
927 * +---------+------------+
929 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
930 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
932 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
949 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
950 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
952 application.SendNotification();
953 application.Render();
955 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
956 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
958 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
959 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
961 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
962 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
964 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
966 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
969 * Test Icon bottom alignment.
970 * Width grows to largest of Icon or Label (+ padding).
984 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
985 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
987 application.SendNotification();
988 application.Render();
990 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
991 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
993 DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
994 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
999 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1001 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1002 ToolkitTestApplication application;
1004 PushButton pushButton = PushButton::New();
1005 pushButton.SetSize(100.0f, 100.0f);
1007 Stage::GetCurrent().Add( pushButton );
1009 Property::Map propertyMap;
1010 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1011 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1013 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1015 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1017 application.SendNotification();
1018 application.Render(0);
1020 unsigned int rendererCount = pushButton.GetRendererCount();
1021 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1023 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1025 tet_printf("Remove button from stage\n" );
1027 Stage::GetCurrent().Remove( pushButton );
1029 rendererCount = pushButton.GetRendererCount();
1030 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1032 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1034 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1036 Property::Map propertyMap2;
1037 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1038 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1039 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap2 );
1041 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1043 Stage::GetCurrent().Add( pushButton );
1045 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1047 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1052 int UtcDaliPushButtonSetSelectedVisualN(void)
1054 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1056 ToolkitTestApplication application;
1058 PushButton pushButton = PushButton::New();
1060 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1061 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1062 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1064 Stage::GetCurrent().Add( pushButton );
1065 application.SendNotification();
1066 application.Render(0);
1068 unsigned int preRendererCount = pushButton.GetRendererCount();
1069 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1070 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1072 Stage::GetCurrent().Remove( pushButton );
1073 application.SendNotification();
1074 application.Render(0);
1076 Property::Map colorMap;
1077 const int BROKEN_VISUAL_TYPE = 999999999;
1079 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1080 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1081 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1082 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, colorMap );
1084 Stage::GetCurrent().Add( pushButton );
1085 application.SendNotification();
1086 application.Render(0);
1088 unsigned int postRendererCount = pushButton.GetRendererCount();
1089 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1090 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1095 int UtcDaliPushButtonSetButtonImageP(void)
1097 ToolkitTestApplication application;
1099 PushButton button = PushButton::New();
1100 Stage::GetCurrent().Add( button );
1104 button.SetButtonImage( ImageView::New() );
1105 DALI_TEST_CHECK( true );
1109 DALI_TEST_CHECK( false );
1115 int UtcDaliPushButtonSetBackgroundImageP(void)
1117 ToolkitTestApplication application;
1119 PushButton button = PushButton::New();
1120 Stage::GetCurrent().Add( button );
1124 button.SetBackgroundImage( ImageView::New() );
1125 DALI_TEST_CHECK( true );
1129 DALI_TEST_CHECK( false );
1135 int UtcDaliPushButtonSetSelectedImageP(void)
1137 ToolkitTestApplication application;
1139 PushButton button = PushButton::New();
1140 Stage::GetCurrent().Add( button );
1144 button.SetSelectedImage( ImageView::New() );
1145 DALI_TEST_CHECK( true );
1149 DALI_TEST_CHECK( false );
1155 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1157 ToolkitTestApplication application;
1159 PushButton button = PushButton::New();
1160 Stage::GetCurrent().Add( button );
1164 button.SetSelectedBackgroundImage( ImageView::New() );
1165 DALI_TEST_CHECK( true );
1169 DALI_TEST_CHECK( false );
1175 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1177 ToolkitTestApplication application;
1179 PushButton button = PushButton::New();
1180 Stage::GetCurrent().Add( button );
1184 button.SetDisabledBackgroundImage( ImageView::New() );
1185 DALI_TEST_CHECK( true );
1189 DALI_TEST_CHECK( false );
1196 int UtcDaliPushButtonSetDisabledImageP(void)
1198 ToolkitTestApplication application;
1200 PushButton button = PushButton::New();
1201 Stage::GetCurrent().Add( button );
1205 button.SetDisabledImage( ImageView::New() );
1206 DALI_TEST_CHECK( true );
1210 DALI_TEST_CHECK( false );
1216 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1218 ToolkitTestApplication application;
1220 PushButton button = PushButton::New();
1221 Stage::GetCurrent().Add( button );
1225 button.SetDisabledSelectedImage( ImageView::New() );
1226 DALI_TEST_CHECK( true );
1230 DALI_TEST_CHECK( false );