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 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
69 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
70 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
71 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
72 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
73 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
74 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
76 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
78 BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
81 PixelBuffer* pixbuf = imageData.GetBuffer();
82 unsigned int size = width * height;
84 for( size_t i = 0; i < size; i++ )
86 pixbuf[i*4+0] = 0xFF * color.r;
87 pixbuf[i*4+1] = 0xFF * color.g;
88 pixbuf[i*4+2] = 0xFF * color.b;
89 pixbuf[i*4+3] = 0xFF * color.a;
99 int UtcDaliPushButtonConstructorP(void)
101 TestApplication application;
105 DALI_TEST_CHECK( !button );
109 int UtcDaliPushButtonCopyConstructorP(void)
111 TestApplication application;
113 // Initialize an object, ref count == 1
114 PushButton button = PushButton::New();
116 PushButton copy( button );
117 DALI_TEST_CHECK( copy );
121 int UtcDaliPushButtonAssignmentOperatorP(void)
123 TestApplication application;
125 PushButton button = PushButton::New();
127 PushButton copy( button );
128 DALI_TEST_CHECK( copy );
130 DALI_TEST_CHECK( button == copy );
134 int UtcDaliPushButtonNewP(void)
136 TestApplication application;
138 PushButton button = PushButton::New();
140 DALI_TEST_CHECK( button );
144 int UtcDaliPushButtonDownCastP(void)
146 TestApplication application;
148 PushButton button = PushButton::New();
150 BaseHandle object(button);
152 PushButton button2 = PushButton::DownCast( object );
153 DALI_TEST_CHECK(button2);
155 PushButton button3 = DownCast< PushButton >(object);
156 DALI_TEST_CHECK(button3);
160 int UtcDaliPushButtonDownCastN(void)
162 TestApplication application;
164 BaseHandle unInitializedObject;
166 PushButton button1 = PushButton::DownCast( unInitializedObject );
167 DALI_TEST_CHECK( !button1 );
169 PushButton button2 = DownCast< PushButton >( unInitializedObject );
170 DALI_TEST_CHECK( !button2 );
174 int UtcDaliPushButtonSetGetAutoRepeating(void)
176 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
179 PushButton pushButton = PushButton::New();
181 pushButton.SetAutoRepeating( true );
183 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
185 pushButton.SetAutoRepeating( false );
187 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
189 pushButton.SetAutoRepeating( true );
191 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
195 int UtcDaliPushButtonSetGetTogglableButton(void)
197 ToolkitTestApplication application;
198 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
200 PushButton pushButton = PushButton::New();
202 pushButton.SetTogglableButton( true );
204 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
206 pushButton.SetTogglableButton( false );
208 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
210 pushButton.SetTogglableButton( true );
212 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
216 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
218 ToolkitTestApplication application;
219 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
221 PushButton pushButton = PushButton::New();
223 pushButton.SetAutoRepeating( true );
224 pushButton.SetTogglableButton( true );
226 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
227 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
229 pushButton.SetTogglableButton( true );
230 pushButton.SetAutoRepeating( true );
232 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
233 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
237 int UtcDaliPushButtonSetGetSelected01(void)
239 ToolkitTestApplication application;
240 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
242 PushButton pushButton = PushButton::New();
244 pushButton.SetTogglableButton( true );
245 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
247 gPushButtonSelectedState = false;
248 pushButton.SetSelected( true );
250 DALI_TEST_CHECK( pushButton.IsSelected() );
251 DALI_TEST_CHECK( gPushButtonSelectedState );
253 pushButton.SetSelected( false );
255 DALI_TEST_CHECK( !pushButton.IsSelected() );
256 DALI_TEST_CHECK( !gPushButtonSelectedState );
258 pushButton.SetSelected( true );
260 DALI_TEST_CHECK( pushButton.IsSelected() );
261 DALI_TEST_CHECK( gPushButtonSelectedState );
265 int UtcDaliPushButtonSetGetSelected02(void)
267 ToolkitTestApplication application;
268 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
270 PushButton pushButton = PushButton::New();
272 pushButton.SetTogglableButton( false );
273 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
275 gPushButtonSelectedState = false;
276 pushButton.SetSelected( true );
278 DALI_TEST_CHECK( !pushButton.IsSelected() );
279 DALI_TEST_CHECK( !gPushButtonSelectedState );
281 pushButton.SetSelected( false );
283 DALI_TEST_CHECK( !pushButton.IsSelected() );
284 DALI_TEST_CHECK( !gPushButtonSelectedState );
286 pushButton.SetSelected( true );
288 DALI_TEST_CHECK( !pushButton.IsSelected() );
289 DALI_TEST_CHECK( !gPushButtonSelectedState );
293 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
295 ToolkitTestApplication application;
296 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
298 PushButton pushButton = PushButton::New();
300 pushButton.SetAutoRepeating( true );
302 pushButton.SetInitialAutoRepeatingDelay( 1.f );
303 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
305 pushButton.SetNextAutoRepeatingDelay( 1.f );
306 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
310 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
312 ToolkitTestApplication application;
313 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
315 PushButton pushButton = PushButton::New();
317 bool assert1( false );
318 bool assert2( false );
320 pushButton.SetAutoRepeating( true );
324 pushButton.SetInitialAutoRepeatingDelay( -1.f );
326 catch( Dali::DaliException& e )
328 DALI_TEST_PRINT_ASSERT( e );
329 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
335 pushButton.SetNextAutoRepeatingDelay( -1.f );
337 catch( Dali::DaliException& e )
339 DALI_TEST_PRINT_ASSERT( e );
340 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
344 DALI_TEST_CHECK( assert1 && assert2 );
348 int UtcDaliPushButtonSetLabelText(void)
350 ToolkitTestApplication application;
351 tet_infoline(" UtcDaliPushButtonSetLabelText");
353 const std::string STR( "Hola!" );
355 PushButton pushButton = PushButton::New();
357 application.SendNotification();
358 application.Render();
360 pushButton.SetLabelText( STR );
362 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
367 int UtcDaliPushButtonPressed(void)
369 ToolkitTestApplication application;
370 tet_infoline(" UtcDaliPushButtonPressed");
372 PushButton pushButton = PushButton::New();
373 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
374 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
375 pushButton.SetPosition( 240, 400 );
376 pushButton.SetSize( 100, 100 );
378 Stage::GetCurrent().Add( pushButton );
380 application.SendNotification();
381 application.Render();
383 gPushButtonPressed = false;
385 // connect to its touch signal
386 pushButton.PressedSignal().Connect( &PushButtonPressed );
388 Dali::Integration::TouchEvent eventDown;
389 eventDown.AddPoint( pointDownInside );
391 // flush the queue and render once
392 application.SendNotification();
393 application.Render();
394 application.ProcessEvent( eventDown );
396 DALI_TEST_CHECK( gPushButtonPressed );
400 int UtcDaliPushButtonReleased(void)
402 ToolkitTestApplication application;
403 tet_infoline(" UtcDaliPushButtonReleased");
405 PushButton pushButton = PushButton::New();
406 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
407 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
408 pushButton.SetPosition( 240, 400 );
409 pushButton.SetSize( 100, 100 );
411 Stage::GetCurrent().Add( pushButton );
413 application.SendNotification();
414 application.Render();
416 // connect to its touch signal
417 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
419 Dali::Integration::TouchEvent event;
421 // Test1. Touch point down and up inside the button.
423 gPushButtonReleased = false;
424 event = Dali::Integration::TouchEvent();
425 event.AddPoint( pointDownInside );
426 application.ProcessEvent( event );
428 event = Dali::Integration::TouchEvent();
429 event.AddPoint( pointUpInside );
430 application.ProcessEvent( event );
432 DALI_TEST_CHECK( gPushButtonReleased );
434 // Test2. Touch point down and up outside the button.
436 gPushButtonReleased = false;
437 event = Dali::Integration::TouchEvent();
438 event.AddPoint( pointDownOutside );
439 application.ProcessEvent( event );
441 event = Dali::Integration::TouchEvent();
442 event.AddPoint( pointUpOutside );
443 application.ProcessEvent( event );
445 DALI_TEST_CHECK( !gPushButtonReleased );
447 // Test3. Touch point down inside and up outside the button.
449 gPushButtonReleased = false;
450 event = Dali::Integration::TouchEvent();
451 event.AddPoint( pointDownInside );
452 application.ProcessEvent( event );
454 event = Dali::Integration::TouchEvent();
455 event.AddPoint( pointLeave );
456 application.ProcessEvent( event );
458 event = Dali::Integration::TouchEvent();
459 event.AddPoint( pointUpOutside );
460 application.ProcessEvent( event );
462 DALI_TEST_CHECK( gPushButtonReleased );
464 // Test4. Touch point down outside and up inside the button.
466 gPushButtonReleased = false;
467 event = Dali::Integration::TouchEvent();
468 event.AddPoint( pointDownOutside );
469 application.ProcessEvent( event );
471 event = Dali::Integration::TouchEvent();
472 event.AddPoint( pointEnter );
473 application.ProcessEvent( event );
475 event = Dali::Integration::TouchEvent();
476 event.AddPoint( pointUpInside );
477 application.ProcessEvent( event );
479 DALI_TEST_CHECK( !gPushButtonReleased );
483 int UtcDaliPushButtonSelected(void)
485 ToolkitTestApplication application;
486 tet_infoline(" UtcDaliPushButtonSelected");
488 PushButton pushButton = PushButton::New();
489 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
490 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
491 pushButton.SetPosition( 240, 400 );
492 pushButton.SetSize( 100, 100 );
494 Stage::GetCurrent().Add( pushButton );
496 application.SendNotification();
497 application.Render();
499 // connect to its touch signal
500 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
502 Dali::Integration::TouchEvent event;
504 // Test1. No togglable button.
506 gPushButtonSelectedState = false;
507 event = Dali::Integration::TouchEvent();
508 event.AddPoint( pointDownInside );
509 application.ProcessEvent( event );
511 event = Dali::Integration::TouchEvent();
512 event.AddPoint( pointUpInside );
513 application.ProcessEvent( event );
515 DALI_TEST_CHECK( !gPushButtonSelectedState );
517 // Set togglable property.
518 pushButton.SetTogglableButton( true );
520 // Test2. Touch point down and up inside the button twice.
521 gPushButtonSelectedState = false;
522 event = Dali::Integration::TouchEvent();
523 event.AddPoint( pointDownInside );
524 application.ProcessEvent( event );
526 event = Dali::Integration::TouchEvent();
527 event.AddPoint( pointUpInside );
528 application.ProcessEvent( event );
530 DALI_TEST_CHECK( gPushButtonSelectedState );
532 event = Dali::Integration::TouchEvent();
533 event.AddPoint( pointDownInside );
534 application.ProcessEvent( event );
536 event = Dali::Integration::TouchEvent();
537 event.AddPoint( pointUpInside );
538 application.ProcessEvent( event );
540 DALI_TEST_CHECK( !gPushButtonSelectedState );
542 // Test3. Touch point down and up outside the button.
544 gPushButtonSelectedState = false;
545 event = Dali::Integration::TouchEvent();
546 event.AddPoint( pointDownOutside );
547 application.ProcessEvent( event );
549 event = Dali::Integration::TouchEvent();
550 event.AddPoint( pointUpOutside );
551 application.ProcessEvent( event );
553 DALI_TEST_CHECK( !gPushButtonSelectedState );
555 // Test4. Touch point down inside and up outside the button.
557 gPushButtonSelectedState = false;
558 event = Dali::Integration::TouchEvent();
559 event.AddPoint( pointDownInside );
560 application.ProcessEvent( event );
562 event = Dali::Integration::TouchEvent();
563 event.AddPoint( pointLeave );
564 application.ProcessEvent( event );
566 event = Dali::Integration::TouchEvent();
567 event.AddPoint( pointUpOutside );
568 application.ProcessEvent( event );
570 DALI_TEST_CHECK( !gPushButtonSelectedState );
572 // Test5. Touch point down outside and up inside the button.
574 gPushButtonSelectedState = false;
575 event = Dali::Integration::TouchEvent();
576 event.AddPoint( pointDownOutside );
577 application.ProcessEvent( event );
579 event = Dali::Integration::TouchEvent();
580 event.AddPoint( pointEnter );
581 application.ProcessEvent( event );
583 event = Dali::Integration::TouchEvent();
584 event.AddPoint( pointUpInside );
585 application.ProcessEvent( event );
587 DALI_TEST_CHECK( !gPushButtonSelectedState );
591 int UtcDaliPushButtonPropertySetIconAlignment(void)
593 ToolkitTestApplication application;
594 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
596 PushButton pushButton = PushButton::New();
597 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
598 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
600 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
601 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
606 int UtcDaliPushButtonPropertySetLabelPadding(void)
608 ToolkitTestApplication application;
609 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
611 PushButton pushButton = PushButton::New();
612 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
613 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 );
615 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
616 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 );
621 int UtcDaliPushButtonPropertySetIconPadding(void)
623 ToolkitTestApplication application;
624 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
626 PushButton pushButton = PushButton::New();
627 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
628 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 );
630 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
631 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 );
636 int UtcDaliPushButtonPaddingLayout(void)
638 ToolkitTestApplication application;
639 tet_infoline(" UtcDaliPushButtonPaddingLayout");
641 // This test creates padding for an icon and a label.
642 // The icon and label are each enabled and disabled to confirm the correct padding is used.
643 PushButton pushButton = PushButton::New();
645 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
646 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
648 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
649 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
650 pushButton.SetPosition( 0.0f, 0.0f );
651 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
653 Stage::GetCurrent().Add( pushButton );
655 application.SendNotification();
656 application.Render();
658 // First test the size is zero.
659 // No padding should be added as there is no label or icon.
660 Vector2 size( Vector2::ZERO );
661 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
662 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
664 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
666 // Check label only padding.
667 pushButton.SetLabelText( "Label" );
669 application.SendNotification();
670 application.Render();
672 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
673 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
675 // 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.
676 DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION );
677 DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION );
679 // Re-initialise the button so we can setup icon-only padding.
680 pushButton.Unparent();
681 pushButton = PushButton::New();
683 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
684 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
686 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
687 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
688 pushButton.SetPosition( 0.0f, 0.0f );
689 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
691 Stage::GetCurrent().Add( pushButton );
693 const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
694 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
695 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
696 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
698 application.SendNotification();
699 application.Render();
701 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
702 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
704 DALI_TEST_EQUALS( size, Vector2( 40.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
706 // Now test padding for both label and icon simultaneously.
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 // Note we only test the width as we are horizontally aligned and the label my be less high than the icon.
717 // Full directional alignment tests are done in UtcDaliPushButtonAlignmentLayout.
718 DALI_TEST_GREATER( size.width, 60.0f, TEST_LOCATION );
723 int UtcDaliPushButtonAlignmentLayout(void)
725 ToolkitTestApplication application;
726 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
728 // This test checks different alignments for the icon against the label.
729 // The icon is then moved around the label in each of it's alignments.
730 // The final relayed out size is checked to confirm the layout has been done correctly.
731 PushButton pushButton = PushButton::New();
733 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) );
734 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) );
736 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
737 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
738 pushButton.SetPosition( 0.0f, 0.0f );
739 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
741 Stage::GetCurrent().Add( pushButton );
743 const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
744 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
745 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
746 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
748 application.SendNotification();
749 application.Render();
751 // First get the base size (without label).
752 Vector2 baseSize( Vector2::ZERO );
753 baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
754 baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
756 DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
758 // Add a label to cause size to be modified in the direction of alignment.
759 pushButton.SetLabelText( "Label" );
761 application.SendNotification();
762 application.Render();
764 Vector2 size( Vector2::ZERO );
765 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
766 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
768 DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION );
769 DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
771 // Now test left alignment matches right for size.
772 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
774 application.SendNotification();
775 application.Render();
777 Vector2 compareSize( Vector2::ZERO );
778 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
779 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
781 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
783 // Test top alignment.
784 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
786 application.SendNotification();
787 application.Render();
789 compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
790 compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
792 DALI_TEST_EQUALS( compareSize.width, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
793 DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION );
795 // Test bottom alignment.
796 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
798 application.SendNotification();
799 application.Render();
801 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
802 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
804 DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );