2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali-toolkit/dali-toolkit.h>
29 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
31 #include <dali/devel-api/adaptor-framework/image-loading.h>
34 using namespace Toolkit;
36 void utc_dali_toolkit_pushbutton_startup(void)
38 test_return_value = TET_UNDEF;
41 void utc_dali_toolkit_pushbutton_cleanup(void)
43 test_return_value = TET_PASS;
48 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
49 static const char* TEST_IMAGE_TWO = TEST_RESOURCE_DIR "/icon-delete.jpg";
51 static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2( 240, 400 );
52 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3( 200, 360, 0 );
53 static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size( 100, 100 );
55 static bool gPushButtonSelectedState = false;
56 bool PushButtonSelected( Button button )
58 gPushButtonSelectedState = button.GetProperty<bool>(button.GetPropertyIndex("selected") );
62 static bool gPushButtonPressed = false;
64 static bool PushButtonPressed( Button button )
66 gPushButtonPressed = true;
70 static bool gPushButtonReleased = false;
72 static bool PushButtonReleased( Button button )
74 gPushButtonReleased = true;
78 static bool gPushButtonClicked = false;
80 static bool PushButtonClicked( Button button )
82 gPushButtonClicked = true;
83 return gPushButtonClicked;
86 Dali::Integration::Point GetPointDownInside()
88 Dali::Integration::Point point;
89 point.SetState( PointState::DOWN );
90 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
94 Dali::Integration::Point GetPointUpInside()
96 Dali::Integration::Point point;
97 point.SetState( PointState::UP );
98 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
102 Dali::Integration::Point GetPointLeave()
104 Dali::Integration::Point point;
105 point.SetState( PointState::LEAVE );
106 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
110 Dali::Integration::Point GetPointEnter()
112 Dali::Integration::Point point;
113 point.SetState( PointState::MOTION );
114 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
118 Dali::Integration::Point GetPointDownOutside()
120 Dali::Integration::Point point;
121 point.SetState( PointState::DOWN );
122 point.SetScreenPosition( Vector2( 10, 10 ) );
126 Dali::Integration::Point GetPointUpOutside()
128 Dali::Integration::Point point;
129 point.SetState( PointState::UP );
130 point.SetScreenPosition( Vector2( 10, 10 ) );
134 // Set up the position of the button for the default test events
135 void SetupButtonForTestTouchEvents( ToolkitTestApplication& application, Button& button, bool useDefaultImages )
137 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
138 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
139 button.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
140 if ( useDefaultImages )
142 const Vector2 TEST_IMAGE_SIZE = Vector2( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
143 TestPlatformAbstraction& platform = application.GetPlatform();
144 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
145 button.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
146 button.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
150 static std::string GetButtonText( Button button )
152 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
154 Property::Map *labelProperty = value.GetMap();
156 std::string textLabel;
160 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
161 value->Get( textLabel );
169 int UtcDaliPushButtonConstructorP(void)
171 TestApplication application;
175 DALI_TEST_CHECK( !button );
179 int UtcDaliPushButtonCopyConstructorP(void)
181 TestApplication application;
183 // Initialize an object, ref count == 1
184 PushButton button = PushButton::New();
186 PushButton copy( button );
187 DALI_TEST_CHECK( copy );
191 int UtcDaliPushButtonAssignmentOperatorP(void)
193 TestApplication application;
195 PushButton button = PushButton::New();
197 PushButton copy( button );
198 DALI_TEST_CHECK( copy );
200 DALI_TEST_CHECK( button == copy );
204 int UtcDaliPushButtonNewP(void)
206 TestApplication application;
208 PushButton button = PushButton::New();
210 DALI_TEST_CHECK( button );
214 int UtcDaliPushButtonDownCastP(void)
216 TestApplication application;
218 PushButton button = PushButton::New();
220 BaseHandle object(button);
222 PushButton button2 = PushButton::DownCast( object );
223 DALI_TEST_CHECK(button2);
225 PushButton button3 = DownCast< PushButton >(object);
226 DALI_TEST_CHECK(button3);
230 int UtcDaliPushButtonDownCastN(void)
232 TestApplication application;
234 BaseHandle unInitializedObject;
236 PushButton button1 = PushButton::DownCast( unInitializedObject );
237 DALI_TEST_CHECK( !button1 );
239 PushButton button2 = DownCast< PushButton >( unInitializedObject );
240 DALI_TEST_CHECK( !button2 );
244 int UtcDaliPushButtonAutoRepeatingProperty(void)
246 ToolkitTestApplication application;
247 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
249 PushButton pushButton = PushButton::New();
251 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
252 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
254 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), false );
255 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
257 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
258 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
263 int UtcDaliPushButtonSetAutoRepeating(void)
265 ToolkitTestApplication application;
266 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
267 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
268 PushButton pushButton = PushButton::New();
270 const bool INITIAL_TOGGLE_VALUE = true;
271 const bool INITIAL_SELECTED_VALUE = true;
273 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
274 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
276 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
277 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
279 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
281 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
286 int UtcDaliPushButtonTogglableProperty(void)
288 ToolkitTestApplication application;
289 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
291 PushButton pushButton = PushButton::New();
293 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
294 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
296 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
297 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
299 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
300 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
305 int UtcDaliPushButtonAutoRepeatingPropertyAndTogglableButton(void)
307 ToolkitTestApplication application;
308 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
310 PushButton pushButton = PushButton::New();
312 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
313 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
315 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
316 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
318 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
319 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
321 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
322 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
326 int UtcDaliPushButtonSelectedProperty01(void)
328 ToolkitTestApplication application;
329 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
331 PushButton pushButton = PushButton::New();
333 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
335 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
337 gPushButtonSelectedState = false;
338 pushButton.SetProperty( Button::Property::SELECTED, true );
340 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
341 DALI_TEST_CHECK( gPushButtonSelectedState );
343 pushButton.SetProperty( Button::Property::SELECTED, false );
345 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
346 DALI_TEST_CHECK( !gPushButtonSelectedState );
348 pushButton.SetProperty( Button::Property::SELECTED, true );
350 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
351 DALI_TEST_CHECK( gPushButtonSelectedState );
355 int UtcDaliPushButtonSelectedProperty02(void)
357 ToolkitTestApplication application;
358 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
360 PushButton pushButton = PushButton::New();
362 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
363 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
365 gPushButtonSelectedState = false;
366 pushButton.SetProperty( Button::Property::SELECTED, true );
368 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
369 DALI_TEST_CHECK( !gPushButtonSelectedState );
371 pushButton.SetProperty( Button::Property::SELECTED, false );
373 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
374 DALI_TEST_CHECK( !gPushButtonSelectedState );
376 pushButton.SetProperty( Button::Property::SELECTED, true );
378 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
379 DALI_TEST_CHECK( !gPushButtonSelectedState );
383 int UtcDaliPushButtonAutorepeatingDelayPropertyValues01(void)
385 ToolkitTestApplication application;
386 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
388 PushButton pushButton = PushButton::New();
390 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
392 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f );
394 DALI_TEST_EQUALS( pushButton.GetProperty<float>(pushButton.GetPropertyIndex("initialAutoRepeatingDelay") ), 1.f, TEST_LOCATION );
399 int UtcDaliPushButtonAutorepeatingDelayPropertyValues02(void)
401 ToolkitTestApplication application;
402 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
404 PushButton pushButton = PushButton::New();
406 bool assert1( false );
407 bool assert2( false );
409 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
413 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f );
415 catch( Dali::DaliException& e )
417 DALI_TEST_PRINT_ASSERT( e );
418 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
424 pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f );
426 catch( Dali::DaliException& e )
428 DALI_TEST_PRINT_ASSERT( e );
429 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
433 DALI_TEST_CHECK( assert1 && assert2 );
437 int UtcDaliPushButtonLabelProperty(void)
439 ToolkitTestApplication application;
440 tet_infoline(" UtcDaliPushButtonSetLabelText");
442 const std::string STR( "Hola!" );
444 PushButton pushButton = PushButton::New();
446 application.SendNotification();
447 application.Render();
449 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
450 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
451 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
455 pushButton.SetProperty( Toolkit::Button::Property::LABEL, STR );
457 DALI_TEST_EQUALS( GetButtonText( pushButton ), STR, TEST_LOCATION );
462 int UtcDaliPushButtonPressed(void)
464 ToolkitTestApplication application;
465 tet_infoline(" UtcDaliPushButtonPressed");
467 PushButton pushButton = PushButton::New();
468 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
469 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
470 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
471 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
473 Stage::GetCurrent().Add( pushButton );
475 application.SendNotification();
476 application.Render();
478 gPushButtonPressed = false;
480 // connect to its touch signal
481 pushButton.PressedSignal().Connect( &PushButtonPressed );
483 Dali::Integration::TouchEvent eventDown;
484 eventDown.AddPoint( GetPointDownInside() );
486 // flush the queue and render once
487 application.SendNotification();
488 application.Render();
489 application.ProcessEvent( eventDown );
491 DALI_TEST_CHECK( gPushButtonPressed );
495 int UtcDaliPushButtonReleased(void)
497 ToolkitTestApplication application;
498 tet_infoline(" UtcDaliPushButtonReleased");
500 PushButton pushButton = PushButton::New();
501 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
502 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
503 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
504 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
506 Stage::GetCurrent().Add( pushButton );
508 application.SendNotification();
509 application.Render();
511 // connect to its touch signal
512 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
514 Dali::Integration::TouchEvent event;
516 // Test1. Touch point down and up inside the button.
518 gPushButtonReleased = false;
519 event = Dali::Integration::TouchEvent();
520 event.AddPoint( GetPointDownInside() );
521 application.ProcessEvent( event );
523 event = Dali::Integration::TouchEvent();
524 event.AddPoint( GetPointUpInside() );
525 application.ProcessEvent( event );
527 DALI_TEST_CHECK( gPushButtonReleased );
529 // Test2. Touch point down and up outside the button.
531 gPushButtonReleased = false;
532 event = Dali::Integration::TouchEvent();
533 event.AddPoint( GetPointDownOutside() );
534 application.ProcessEvent( event );
536 event = Dali::Integration::TouchEvent();
537 event.AddPoint( GetPointUpOutside() );
538 application.ProcessEvent( event );
540 DALI_TEST_CHECK( !gPushButtonReleased );
542 // Test3. Touch point down inside and up outside the button.
544 gPushButtonReleased = false;
545 event = Dali::Integration::TouchEvent();
546 event.AddPoint( GetPointDownInside() );
547 application.ProcessEvent( event );
549 event = Dali::Integration::TouchEvent();
550 event.AddPoint( GetPointLeave() );
551 application.ProcessEvent( event );
553 event = Dali::Integration::TouchEvent();
554 event.AddPoint( GetPointUpOutside() );
555 application.ProcessEvent( event );
557 DALI_TEST_CHECK( gPushButtonReleased );
559 // Test4. Touch point down outside and up inside the button.
561 gPushButtonReleased = false;
562 event = Dali::Integration::TouchEvent();
563 event.AddPoint( GetPointDownOutside() );
564 application.ProcessEvent( event );
566 event = Dali::Integration::TouchEvent();
567 event.AddPoint( GetPointEnter() );
568 application.ProcessEvent( event );
570 event = Dali::Integration::TouchEvent();
571 event.AddPoint( GetPointUpInside() );
572 application.ProcessEvent( event );
574 DALI_TEST_CHECK( !gPushButtonReleased );
578 int UtcDaliPushButtonSelected(void)
580 ToolkitTestApplication application;
581 tet_infoline(" UtcDaliPushButtonSelected");
583 PushButton pushButton = PushButton::New();
584 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
585 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
586 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
587 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
589 Stage::GetCurrent().Add( pushButton );
591 application.SendNotification();
592 application.Render();
594 // connect to its touch signal
595 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
597 Dali::Integration::TouchEvent event;
599 // Test1. No togglable button.
601 gPushButtonSelectedState = false;
602 event = Dali::Integration::TouchEvent();
603 event.AddPoint( GetPointDownInside() );
604 application.ProcessEvent( event );
606 event = Dali::Integration::TouchEvent();
607 event.AddPoint( GetPointUpInside() );
608 application.ProcessEvent( event );
610 DALI_TEST_CHECK( !gPushButtonSelectedState );
612 // Set togglable property.
613 pushButton.SetProperty( Button::Property::TOGGLABLE, true );
615 // Test2. Touch point down and up inside the button twice.
616 gPushButtonSelectedState = false;
617 event = Dali::Integration::TouchEvent();
618 event.AddPoint( GetPointDownInside() );
619 application.ProcessEvent( event );
621 event = Dali::Integration::TouchEvent();
622 event.AddPoint( GetPointUpInside() );
623 application.ProcessEvent( event );
625 DALI_TEST_CHECK( gPushButtonSelectedState );
627 event = Dali::Integration::TouchEvent();
628 event.AddPoint( GetPointDownInside() );
629 application.ProcessEvent( event );
631 event = Dali::Integration::TouchEvent();
632 event.AddPoint( GetPointUpInside() );
633 application.ProcessEvent( event );
635 DALI_TEST_CHECK( !gPushButtonSelectedState );
637 // Test3. Touch point down and up outside the button.
639 gPushButtonSelectedState = false;
640 event = Dali::Integration::TouchEvent();
641 event.AddPoint( GetPointDownOutside() );
642 application.ProcessEvent( event );
644 event = Dali::Integration::TouchEvent();
645 event.AddPoint( GetPointUpOutside() );
646 application.ProcessEvent( event );
648 DALI_TEST_CHECK( !gPushButtonSelectedState );
650 // Test4. Touch point down inside and up outside the button.
651 // State changes on Button down
652 gPushButtonSelectedState = false;
653 event = Dali::Integration::TouchEvent();
654 event.AddPoint( GetPointDownInside() );
655 application.ProcessEvent( event );
657 event = Dali::Integration::TouchEvent();
658 event.AddPoint( GetPointLeave() );
659 application.ProcessEvent( event );
661 event = Dali::Integration::TouchEvent();
662 event.AddPoint( GetPointUpOutside() );
663 application.ProcessEvent( event );
665 DALI_TEST_CHECK( gPushButtonSelectedState );
667 // Test5. Touch point down outside and up inside the button.
668 // Start in unselected state
669 pushButton.SetProperty( Button::Property::SELECTED, false );
671 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("selected") ),false , TEST_LOCATION );
673 gPushButtonSelectedState = false;
674 event = Dali::Integration::TouchEvent();
675 event.AddPoint( GetPointDownOutside() );
676 application.ProcessEvent( event );
678 event = Dali::Integration::TouchEvent();
679 event.AddPoint( GetPointEnter() );
680 application.ProcessEvent( event );
682 event = Dali::Integration::TouchEvent();
683 event.AddPoint( GetPointUpInside() );
684 application.ProcessEvent( event );
686 DALI_TEST_CHECK( !gPushButtonSelectedState );
690 int UtcDaliPushButtonPropertySetIconAlignment(void)
692 ToolkitTestApplication application;
693 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
695 PushButton pushButton = PushButton::New();
696 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
697 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
699 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
700 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
705 int UtcDaliPushButtonPropertySetLabelPadding(void)
707 ToolkitTestApplication application;
708 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
710 PushButton pushButton = PushButton::New();
711 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
712 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 );
714 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
715 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 );
720 int UtcDaliPushButtonPropertySetIconPadding(void)
722 ToolkitTestApplication application;
723 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
725 PushButton pushButton = PushButton::New();
726 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
727 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 );
729 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
730 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 );
735 int UtcDaliPushButtonPaddingLayout(void)
737 ToolkitTestApplication application;
738 tet_infoline(" UtcDaliPushButtonPaddingLayout");
740 // This test creates padding for an icon and a label.
741 // The icon and label are each enabled and disabled to confirm the correct padding is used.
742 PushButton pushButton = PushButton::New();
744 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
745 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
747 // Get actual size of test image
748 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
749 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
751 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
752 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
753 pushButton.SetPosition( 0.0f, 0.0f );
754 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
756 Stage::GetCurrent().Add( pushButton );
758 application.SendNotification();
759 application.Render();
761 // First test the size is zero.
762 // No padding should be added as there is no label or icon.
763 Vector2 size( Vector2::ZERO );
764 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
765 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
766 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
768 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
770 // Check label only padding
771 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
773 application.SendNotification();
774 application.Render();
776 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
777 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
778 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
780 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
782 // Add label padding to label
783 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
784 application.SendNotification();
785 application.Render();
787 Vector2 sizeLabelAndPadding( Vector2::ZERO );
788 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
789 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
790 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
792 // If control size has increased beyond size of just label then padding has been applied
793 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
794 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
796 // Re-initialise the button so we can setup icon-only padding.
797 pushButton.Unparent();
798 pushButton = PushButton::New();
800 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
801 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
802 pushButton.SetPosition( 0.0f, 0.0f );
803 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
805 Stage::GetCurrent().Add( pushButton );
808 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
809 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
810 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
812 application.SendNotification();
813 application.Render();
815 // Size of button with just icon
816 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
817 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
818 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
820 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
822 application.SendNotification();
823 application.Render();
824 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
826 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
827 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
828 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
829 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 );
830 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
832 // Now test padding for both label and icon simultaneously.
833 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
835 application.SendNotification();
836 application.Render();
838 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
839 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
840 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
842 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
844 application.SendNotification();
845 application.Render();
847 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
848 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
849 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
851 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
852 // Test height of control is same as icon and padding, as Text is smaller than icon
853 DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
858 int UtcDaliPushButtonAlignmentLayout(void)
860 ToolkitTestApplication application;
861 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
864 * This test checks different alignments for the icon against the label.
865 * The icon is then moved around the label in each of it's alignments.
866 * The final relayed out size is checked to confirm the layout has been done correctly.
868 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
869 * - Therefore total width and height are both 150.
871 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
872 * - Therefore total width and height are 60+x and 60+y respectively.
873 * Where x & y are the width and height of the text.
875 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
876 * So We use the padding to help us determine the orientation is correct for each alignment.
878 * |<- 150 ->| |<-- 60+x -->|
881 * | | ^ +------------+ -
883 * | Icon | 150 | Label | 60+y
885 * | | v +------------+ -
889 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
890 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
892 // Get actual size of test image
893 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
894 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
896 PushButton pushButton = PushButton::New();
898 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
899 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
900 pushButton.SetPosition( 0.0f, 0.0f );
901 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
903 Stage::GetCurrent().Add( pushButton );
905 // Add a label and get size of control
906 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
907 application.SendNotification();
908 application.Render();
910 // First get the size of control with just label
911 Vector2 justLabelSize( Vector2::ZERO );
912 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
913 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
914 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
916 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
917 application.SendNotification();
918 application.Render();
920 // Size of Label and Padding
921 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
922 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
923 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
925 Vector2 labelAndPaddingSize( Vector2::ZERO );
926 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
927 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
929 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
931 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
932 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
934 // Add Icon and set its alignment
935 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
936 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
937 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
938 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
940 application.SendNotification();
941 application.Render();
943 Vector2 size( Vector2::ZERO );
944 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
945 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
948 * Test Icon right alignment.
949 * Height grows to largest of Icon or Label (+ padding).
950 * Normally this will be Icons height, except with very large font sizes.
952 * +------------+---------+
958 * +------------+---------+
960 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
961 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
963 // Now test left alignment matches right for size.
964 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
966 application.SendNotification();
967 application.Render();
969 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
970 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
973 * Test Icon left alignment.
974 * Height grows to largest of Icon or Label (+ padding).
975 * Normally this will be Icons height, except with very large font sizes.
977 * +---------+------------+
983 * +---------+------------+
985 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
986 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
988 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
1005 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
1006 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
1008 application.SendNotification();
1009 application.Render();
1011 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1012 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1014 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
1015 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
1017 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
1018 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
1020 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
1022 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1025 * Test Icon bottom alignment.
1026 * Width grows to largest of Icon or Label (+ padding).
1040 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1041 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
1043 application.SendNotification();
1044 application.Render();
1046 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1047 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1049 DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1050 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1055 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1057 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1058 ToolkitTestApplication application;
1060 PushButton pushButton = PushButton::New();
1061 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
1063 Stage::GetCurrent().Add( pushButton );
1065 Property::Map propertyMap;
1066 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1067 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1069 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1071 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1073 application.SendNotification();
1074 application.Render(0);
1076 unsigned int rendererCount = pushButton.GetRendererCount();
1077 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1079 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1081 tet_printf("Remove button from stage\n" );
1083 Stage::GetCurrent().Remove( pushButton );
1085 rendererCount = pushButton.GetRendererCount();
1086 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1088 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1090 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1092 Property::Map propertyMap2;
1093 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1094 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1095 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap2 );
1097 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1099 Stage::GetCurrent().Add( pushButton );
1101 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1103 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1108 int UtcDaliPushButtonSetSelectedVisualN(void)
1110 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1112 ToolkitTestApplication application;
1114 PushButton pushButton = PushButton::New();
1116 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1117 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1118 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1120 Stage::GetCurrent().Add( pushButton );
1121 application.SendNotification();
1122 application.Render(0);
1124 unsigned int preRendererCount = pushButton.GetRendererCount();
1125 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1126 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1128 Stage::GetCurrent().Remove( pushButton );
1129 application.SendNotification();
1130 application.Render(0);
1132 Property::Map colorMap;
1133 const int BROKEN_VISUAL_TYPE = 999999999;
1135 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1136 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1137 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1138 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, colorMap );
1140 Stage::GetCurrent().Add( pushButton );
1141 application.SendNotification();
1142 application.Render(0);
1144 unsigned int postRendererCount = pushButton.GetRendererCount();
1145 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1146 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1151 int UtcDaliPushButtonSetButtonImageP(void)
1153 ToolkitTestApplication application;
1155 PushButton button = PushButton::New();
1156 Stage::GetCurrent().Add( button );
1160 button.SetButtonImage( ImageView::New() );
1161 DALI_TEST_CHECK( true );
1165 DALI_TEST_CHECK( false );
1171 int UtcDaliPushButtonSetBackgroundImageP(void)
1173 ToolkitTestApplication application;
1175 PushButton button = PushButton::New();
1176 Stage::GetCurrent().Add( button );
1180 button.SetBackgroundImage( ImageView::New() );
1181 DALI_TEST_CHECK( true );
1185 DALI_TEST_CHECK( false );
1191 int UtcDaliPushButtonSetSelectedImageP(void)
1193 ToolkitTestApplication application;
1195 PushButton button = PushButton::New();
1196 Stage::GetCurrent().Add( button );
1200 button.SetSelectedImage( ImageView::New() );
1201 DALI_TEST_CHECK( true );
1205 DALI_TEST_CHECK( false );
1211 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1213 ToolkitTestApplication application;
1215 PushButton button = PushButton::New();
1216 Stage::GetCurrent().Add( button );
1220 button.SetSelectedBackgroundImage( ImageView::New() );
1221 DALI_TEST_CHECK( true );
1225 DALI_TEST_CHECK( false );
1231 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1233 ToolkitTestApplication application;
1235 PushButton button = PushButton::New();
1236 Stage::GetCurrent().Add( button );
1240 button.SetDisabledBackgroundImage( ImageView::New() );
1241 DALI_TEST_CHECK( true );
1245 DALI_TEST_CHECK( false );
1252 int UtcDaliPushButtonSetDisabledImageP(void)
1254 ToolkitTestApplication application;
1256 PushButton button = PushButton::New();
1257 Stage::GetCurrent().Add( button );
1261 button.SetDisabledImage( ImageView::New() );
1262 DALI_TEST_CHECK( true );
1266 DALI_TEST_CHECK( false );
1272 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1274 ToolkitTestApplication application;
1276 PushButton button = PushButton::New();
1277 Stage::GetCurrent().Add( button );
1281 button.SetDisabledSelectedImage( ImageView::New() );
1282 DALI_TEST_CHECK( true );
1286 DALI_TEST_CHECK( false );
1292 int UtcDaliPushButtonToggleSignalP(void)
1294 ToolkitTestApplication application;
1295 tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1297 PushButton button = PushButton::New();
1298 button.SetProperty( Button::Property::TOGGLABLE, true);
1300 SetupButtonForTestTouchEvents( application, button, true );
1302 Stage::GetCurrent().Add( button );
1304 application.SendNotification();
1305 application.Render();
1307 // connect to its signal
1308 button.ClickedSignal().Connect( &PushButtonClicked );
1309 gPushButtonClicked = false;
1311 tet_infoline(" Touch down and up within button");
1312 Dali::Integration::TouchEvent event;
1313 event = Dali::Integration::TouchEvent();
1314 event.AddPoint( GetPointDownInside() );
1315 application.ProcessEvent( event );
1317 event = Dali::Integration::TouchEvent();
1318 event.AddPoint( GetPointUpInside() );
1319 application.ProcessEvent( event );
1321 DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION );
1326 // Deprecated API Tests
1328 int UtcDaliPushButtonSetGetAutoRepeating(void)
1330 ToolkitTestApplication application;
1331 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
1333 PushButton pushButton = PushButton::New();
1335 pushButton.SetAutoRepeating( true );
1337 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1339 pushButton.SetAutoRepeating( false );
1341 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1343 pushButton.SetAutoRepeating( true );
1345 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1349 int UtcDaliPushButtonSetGetTogglableButton(void)
1351 ToolkitTestApplication application;
1352 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
1354 PushButton pushButton = PushButton::New();
1356 pushButton.SetTogglableButton( true );
1358 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1360 pushButton.SetTogglableButton( false );
1362 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1364 pushButton.SetTogglableButton( true );
1366 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1370 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
1372 ToolkitTestApplication application;
1373 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
1375 PushButton pushButton = PushButton::New();
1377 pushButton.SetAutoRepeating( true );
1378 pushButton.SetTogglableButton( true );
1380 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1381 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1383 pushButton.SetTogglableButton( true );
1384 pushButton.SetAutoRepeating( true );
1386 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1387 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1391 int UtcDaliPushButtonSetGetSelected01(void)
1393 ToolkitTestApplication application;
1394 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
1396 PushButton pushButton = PushButton::New();
1398 pushButton.SetTogglableButton( true );
1399 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1401 gPushButtonSelectedState = false;
1402 pushButton.SetSelected( true );
1404 DALI_TEST_CHECK( pushButton.IsSelected() );
1405 DALI_TEST_CHECK( gPushButtonSelectedState );
1407 pushButton.SetSelected( false );
1409 DALI_TEST_CHECK( !pushButton.IsSelected() );
1410 DALI_TEST_CHECK( !gPushButtonSelectedState );
1412 pushButton.SetSelected( true );
1414 DALI_TEST_CHECK( pushButton.IsSelected() );
1415 DALI_TEST_CHECK( gPushButtonSelectedState );
1419 int UtcDaliPushButtonSetGetSelected02(void)
1421 ToolkitTestApplication application;
1422 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
1424 PushButton pushButton = PushButton::New();
1426 pushButton.SetTogglableButton( false );
1427 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1429 gPushButtonSelectedState = false;
1430 pushButton.SetSelected( true );
1432 DALI_TEST_CHECK( !pushButton.IsSelected() );
1433 DALI_TEST_CHECK( !gPushButtonSelectedState );
1435 pushButton.SetSelected( false );
1437 DALI_TEST_CHECK( !pushButton.IsSelected() );
1438 DALI_TEST_CHECK( !gPushButtonSelectedState );
1440 pushButton.SetSelected( true );
1442 DALI_TEST_CHECK( !pushButton.IsSelected() );
1443 DALI_TEST_CHECK( !gPushButtonSelectedState );
1447 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
1449 ToolkitTestApplication application;
1450 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
1452 PushButton pushButton = PushButton::New();
1454 pushButton.SetAutoRepeating( true );
1456 pushButton.SetInitialAutoRepeatingDelay( 1.f );
1457 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1459 pushButton.SetNextAutoRepeatingDelay( 1.f );
1460 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1464 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
1466 ToolkitTestApplication application;
1467 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
1469 PushButton pushButton = PushButton::New();
1471 bool assert1( false );
1472 bool assert2( false );
1474 pushButton.SetAutoRepeating( true );
1478 pushButton.SetInitialAutoRepeatingDelay( -1.f );
1480 catch( Dali::DaliException& e )
1482 DALI_TEST_PRINT_ASSERT( e );
1483 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
1489 pushButton.SetNextAutoRepeatingDelay( -1.f );
1491 catch( Dali::DaliException& e )
1493 DALI_TEST_PRINT_ASSERT( e );
1494 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
1498 DALI_TEST_CHECK( assert1 && assert2 );
1502 int UtcDaliPushButtonSetLabelText(void)
1504 ToolkitTestApplication application;
1505 tet_infoline(" UtcDaliPushButtonSetLabelText");
1507 const std::string STR( "Hola!" );
1509 PushButton pushButton = PushButton::New();
1511 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
1512 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
1513 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1516 application.SendNotification();
1517 application.Render();
1519 pushButton.SetLabelText( STR );
1521 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
1526 int UtcDaliPushButtonSetButtonImageDeprecatedP(void)
1528 ToolkitTestApplication application;
1529 Image setButtonImage = ResourceImage::New( TEST_IMAGE_ONE);
1530 PushButton pushButton = PushButton::New();
1531 pushButton.SetButtonImage( setButtonImage );
1532 Image retreivedButtonImage = ImageView::DownCast(pushButton.GetButtonImage()).GetImage();
1533 DALI_TEST_EQUALS( retreivedButtonImage, setButtonImage , TEST_LOCATION );
1538 int UtcDaliPushButtonSetSelectedImageDeprecatedP(void)
1540 ToolkitTestApplication application;
1541 Image setButtonImage = ResourceImage::New( TEST_IMAGE_ONE);
1542 PushButton pushButton = PushButton::New();
1543 pushButton.SetSelectedImage( setButtonImage );
1544 Image retreivedButtonImage = ImageView::DownCast(pushButton.GetSelectedImage()).GetImage();
1545 DALI_TEST_EQUALS( retreivedButtonImage, setButtonImage , TEST_LOCATION );
1550 int UtcDaliPushButtonGetButtonImageURLDeprecatedP(void)
1552 tet_infoline(" UtcDaliPushButtonGetButtonImageURLDeprecatedP Testing mix use of API");
1554 ToolkitTestApplication application;
1556 PushButton pushButton = PushButton::New();
1557 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
1559 ImageView retreivedButtonImageView = ImageView::DownCast(pushButton.GetButtonImage());
1560 Image retreivedButtonImage = retreivedButtonImageView.GetImage();
1561 ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
1563 DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_ONE , TEST_LOCATION );
1568 int UtcDaliPushButtonGetSelectedImageURLDeprecatedP(void)
1570 tet_infoline(" UtcDaliPushButtonGetSelectedImageURLDeprecatedP Testing mix use of API");
1572 ToolkitTestApplication application;
1574 PushButton pushButton = PushButton::New();
1576 pushButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
1578 Image retreivedButtonImage = ImageView::DownCast(pushButton.GetSelectedImage()).GetImage();
1579 ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
1580 DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_ONE , TEST_LOCATION );
1585 int UtcDaliPushButtonSetSelectedImageWithActorDeprecatedP(void)
1587 tet_infoline(" UtcDaliPushButton SetSelectedImage With ImageView (Actor)");
1589 ToolkitTestApplication application;
1591 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1593 DALI_TEST_CHECK( image );
1595 ImageView imgViewSet = ImageView::New(image);
1597 DALI_TEST_CHECK(imgViewSet );
1599 PushButton pushButton = PushButton::New();
1601 DALI_TEST_CHECK( pushButton );
1603 pushButton.SetSelectedImage( imgViewSet );
1605 ImageView imageView = ImageView::DownCast( pushButton.GetSelectedImage());
1607 DALI_TEST_CHECK( imageView );
1609 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1612 DALI_TEST_CHECK( !map.Empty() );
1613 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1618 int UtcDaliPushButtonSetButtonImageWithActorDeprecatedP(void)
1620 tet_infoline(" UtcDaliPushButton SetButtonImage With ImageView (Actor)");
1622 ToolkitTestApplication application;
1624 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1626 DALI_TEST_CHECK( image );
1628 ImageView imgViewSet = ImageView::New(image);
1630 DALI_TEST_CHECK(imgViewSet );
1632 PushButton pushButton = PushButton::New();
1634 DALI_TEST_CHECK( pushButton );
1636 pushButton.SetButtonImage( imgViewSet );
1638 ImageView imageView = ImageView::DownCast( pushButton.GetButtonImage());
1640 DALI_TEST_CHECK( imageView );
1642 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1645 DALI_TEST_CHECK( !map.Empty() );
1646 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1651 int UtcDaliPushButtonSetBackgroundImageWithActorDeprecatedP(void)
1653 tet_infoline(" UtcDaliPushButton SetBackgroundImage With ImageView (Actor)");
1655 ToolkitTestApplication application;
1657 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1659 DALI_TEST_CHECK( image );
1661 ImageView imgViewSet = ImageView::New(image);
1663 DALI_TEST_CHECK(imgViewSet );
1665 PushButton pushButton = PushButton::New();
1667 DALI_TEST_CHECK( pushButton );
1669 pushButton.SetBackgroundImage( imgViewSet );
1671 ImageView imageView = ImageView::DownCast( pushButton.GetButtonImage());
1673 DALI_TEST_CHECK( imageView );
1675 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1678 DALI_TEST_CHECK( !map.Empty() );
1679 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1685 int UtcDaliPushButtonSetSelectedBackgroundImageWithActorDeprecatedP(void)
1687 tet_infoline(" UtcDaliPushButton SetSelectedBackgroundImage With ImageView (Actor)");
1689 ToolkitTestApplication application;
1691 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1693 DALI_TEST_CHECK( image );
1695 ImageView imgViewSet = ImageView::New(image);
1697 DALI_TEST_CHECK(imgViewSet );
1699 PushButton pushButton = PushButton::New();
1701 DALI_TEST_CHECK( pushButton );
1703 pushButton.SetSelectedBackgroundImage( imgViewSet );
1705 ImageView imageView = ImageView::DownCast( pushButton.GetSelectedImage());
1707 DALI_TEST_CHECK( imageView );
1709 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1712 DALI_TEST_CHECK( !map.Empty() );
1713 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1718 int UtcDaliPushButtonSetDisabledBackgroundImageWithActorDeprecatedP(void)
1720 tet_infoline(" UtcDaliPushButton SetDisabledBackgroundImage With ImageView (Actor)");
1722 ToolkitTestApplication application;
1724 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1726 DALI_TEST_CHECK( image );
1728 ImageView imgViewSet = ImageView::New(image);
1730 DALI_TEST_CHECK(imgViewSet );
1732 PushButton pushButton = PushButton::New();
1734 DALI_TEST_CHECK( pushButton );
1736 pushButton.SetDisabledBackgroundImage( imgViewSet );
1738 Property::Value value = pushButton.GetProperty( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL );
1742 Property::Value* urlValue = map.Find( ImageVisual::Property::URL );
1744 std::string urlString;
1745 urlValue->Get( urlString );
1746 DALI_TEST_EQUALS( urlString , TEST_IMAGE_ONE , TEST_LOCATION );
1751 int UtcDaliPushButtonSetDisabledImageWithActorDeprecatedP(void)
1753 tet_infoline(" UtcDaliPushButton SetDisabledImage With ImageView (Actor)");
1755 ToolkitTestApplication application;
1757 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1759 DALI_TEST_CHECK( image );
1761 ImageView imgViewSet = ImageView::New(image);
1763 DALI_TEST_CHECK(imgViewSet );
1765 PushButton pushButton = PushButton::New();
1767 DALI_TEST_CHECK( pushButton );
1769 pushButton.SetDisabledImage( imgViewSet );
1771 Property::Value value = pushButton.GetProperty( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL );
1776 Property::Value* urlValue = map.Find( ImageVisual::Property::URL );
1778 std::string urlString;
1779 urlValue->Get( urlString );
1780 DALI_TEST_EQUALS( urlString , TEST_IMAGE_ONE , TEST_LOCATION );
1785 int UtcDaliPushButtonSetDisabledSelectedImageWithActorDeprecatedP(void)
1787 tet_infoline(" UtcDaliPushButton SetDisabledSelectedImage With ImageView (Actor)");
1789 ToolkitTestApplication application;
1791 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1793 DALI_TEST_CHECK( image );
1795 ImageView imgViewSet = ImageView::New(image);
1797 DALI_TEST_CHECK(imgViewSet );
1799 PushButton pushButton = PushButton::New();
1801 DALI_TEST_CHECK( pushButton );
1803 pushButton.SetDisabledSelectedImage( imgViewSet );
1805 Property::Value value = pushButton.GetProperty( Toolkit::DevelButton::Property::DISABLED_SELECTED_BACKGROUND_VISUAL );
1810 Property::Value* urlValue = map.Find( ImageVisual::Property::URL );
1812 std::string urlString;
1813 urlValue->Get( urlString );
1814 DALI_TEST_EQUALS( urlString , TEST_IMAGE_ONE , TEST_LOCATION );
1819 int UtcDaliPushButtonReplaceButtonImageP2(void)
1821 tet_infoline("Set button image then replace with new image and query url");
1823 ToolkitTestApplication application;
1825 ResourceImage setImage = ResourceImage::New( TEST_IMAGE_ONE );
1826 DALI_TEST_CHECK(setImage);
1828 Actor imgActorSet = ImageView::New(setImage);
1829 DALI_TEST_CHECK(imgActorSet);
1831 PushButton pushButton = PushButton::New();
1832 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_TWO );
1835 Stage::GetCurrent().Add( pushButton );
1837 pushButton.SetButtonImage( imgActorSet );
1838 application.SendNotification();
1839 application.Render();
1841 tet_infoline("Get button image before it has been able to load");
1843 ImageView imageView = ImageView::DownCast(pushButton.GetButtonImage());
1845 ResourceImage getImage = ResourceImage::DownCast( imageView.GetImage() );
1847 tet_infoline("Check if url matches last assignment even if not loaded yet");
1848 DALI_TEST_EQUALS( getImage.GetUrl(), setImage.GetUrl() , TEST_LOCATION );