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>
29 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
33 #include <dali/devel-api/adaptor-framework/image-loading.h>
36 using namespace Toolkit;
38 void utc_dali_toolkit_pushbutton_startup(void)
40 test_return_value = TET_UNDEF;
43 void utc_dali_toolkit_pushbutton_cleanup(void)
45 test_return_value = TET_PASS;
50 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
52 static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2( 240, 400 );
53 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3( 200, 360, 0 );
54 static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size( 100, 100 );
56 static bool gPushButtonSelectedState = false;
57 bool PushButtonSelected( Button button )
59 gPushButtonSelectedState = button.GetProperty<bool>(button.GetPropertyIndex("selected") );
63 static bool gPushButtonPressed = false;
65 static bool PushButtonPressed( Button button )
67 gPushButtonPressed = true;
71 static bool gPushButtonReleased = false;
73 static bool PushButtonReleased( Button button )
75 gPushButtonReleased = true;
79 static bool gPushButtonClicked = false;
81 static bool PushButtonClicked( Button button )
83 gPushButtonClicked = true;
84 return gPushButtonClicked;
87 Dali::Integration::Point GetPointDownInside()
89 Dali::Integration::Point point;
90 point.SetState( PointState::DOWN );
91 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
95 Dali::Integration::Point GetPointUpInside()
97 Dali::Integration::Point point;
98 point.SetState( PointState::UP );
99 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
103 Dali::Integration::Point GetPointLeave()
105 Dali::Integration::Point point;
106 point.SetState( PointState::LEAVE );
107 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
111 Dali::Integration::Point GetPointEnter()
113 Dali::Integration::Point point;
114 point.SetState( PointState::MOTION );
115 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
119 Dali::Integration::Point GetPointDownOutside()
121 Dali::Integration::Point point;
122 point.SetState( PointState::DOWN );
123 point.SetScreenPosition( Vector2( 10, 10 ) );
127 Dali::Integration::Point GetPointUpOutside()
129 Dali::Integration::Point point;
130 point.SetState( PointState::UP );
131 point.SetScreenPosition( Vector2( 10, 10 ) );
135 // Set up the position of the button for the default test events
136 void SetupButtonForTestTouchEvents( ToolkitTestApplication& application, Button& button, bool useDefaultImages )
138 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
139 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
140 button.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
141 if ( useDefaultImages )
143 const Vector2 TEST_IMAGE_SIZE = Vector2( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
144 TestPlatformAbstraction& platform = application.GetPlatform();
145 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
146 button.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
147 button.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
151 static std::string GetButtonText( Button button )
153 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
155 Property::Map *labelProperty = value.GetMap();
157 std::string textLabel;
161 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
162 value->Get( textLabel );
170 int UtcDaliPushButtonConstructorP(void)
172 TestApplication application;
176 DALI_TEST_CHECK( !button );
180 int UtcDaliPushButtonCopyConstructorP(void)
182 TestApplication application;
184 // Initialize an object, ref count == 1
185 PushButton button = PushButton::New();
187 PushButton copy( button );
188 DALI_TEST_CHECK( copy );
192 int UtcDaliPushButtonAssignmentOperatorP(void)
194 TestApplication application;
196 PushButton button = PushButton::New();
198 PushButton copy( button );
199 DALI_TEST_CHECK( copy );
201 DALI_TEST_CHECK( button == copy );
205 int UtcDaliPushButtonNewP(void)
207 TestApplication application;
209 PushButton button = PushButton::New();
211 DALI_TEST_CHECK( button );
215 int UtcDaliPushButtonDownCastP(void)
217 TestApplication application;
219 PushButton button = PushButton::New();
221 BaseHandle object(button);
223 PushButton button2 = PushButton::DownCast( object );
224 DALI_TEST_CHECK(button2);
226 PushButton button3 = DownCast< PushButton >(object);
227 DALI_TEST_CHECK(button3);
231 int UtcDaliPushButtonDownCastN(void)
233 TestApplication application;
235 BaseHandle unInitializedObject;
237 PushButton button1 = PushButton::DownCast( unInitializedObject );
238 DALI_TEST_CHECK( !button1 );
240 PushButton button2 = DownCast< PushButton >( unInitializedObject );
241 DALI_TEST_CHECK( !button2 );
245 int UtcDaliPushButtonAutoRepeatingProperty(void)
247 ToolkitTestApplication application;
248 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
250 PushButton pushButton = PushButton::New();
252 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
253 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
255 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), false );
256 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
258 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
259 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
264 int UtcDaliPushButtonSetAutoRepeating(void)
266 ToolkitTestApplication application;
267 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
268 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
269 PushButton pushButton = PushButton::New();
271 const bool INITIAL_TOGGLE_VALUE = true;
272 const bool INITIAL_SELECTED_VALUE = true;
274 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
275 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
277 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
278 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
280 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
282 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
287 int UtcDaliPushButtonTogglableProperty(void)
289 ToolkitTestApplication application;
290 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
292 PushButton pushButton = PushButton::New();
294 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
295 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
297 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
298 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
300 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
301 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
306 int UtcDaliPushButtonAutoRepeatingPropertyAndTogglableButton(void)
308 ToolkitTestApplication application;
309 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
311 PushButton pushButton = PushButton::New();
313 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
314 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
316 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
317 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
319 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
320 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
322 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
323 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
327 int UtcDaliPushButtonSelectedProperty01(void)
329 ToolkitTestApplication application;
330 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
332 PushButton pushButton = PushButton::New();
334 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
336 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
338 gPushButtonSelectedState = false;
339 pushButton.SetProperty( Button::Property::SELECTED, true );
341 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
342 DALI_TEST_CHECK( gPushButtonSelectedState );
344 pushButton.SetProperty( Button::Property::SELECTED, false );
346 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
347 DALI_TEST_CHECK( !gPushButtonSelectedState );
349 pushButton.SetProperty( Button::Property::SELECTED, true );
351 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
352 DALI_TEST_CHECK( gPushButtonSelectedState );
356 int UtcDaliPushButtonSelectedProperty02(void)
358 ToolkitTestApplication application;
359 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
361 PushButton pushButton = PushButton::New();
363 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
364 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
366 gPushButtonSelectedState = false;
367 pushButton.SetProperty( Button::Property::SELECTED, true );
369 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
370 DALI_TEST_CHECK( !gPushButtonSelectedState );
372 pushButton.SetProperty( Button::Property::SELECTED, false );
374 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
375 DALI_TEST_CHECK( !gPushButtonSelectedState );
377 pushButton.SetProperty( Button::Property::SELECTED, true );
379 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
380 DALI_TEST_CHECK( !gPushButtonSelectedState );
384 int UtcDaliPushButtonAutorepeatingDelayPropertyValues01(void)
386 ToolkitTestApplication application;
387 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
389 PushButton pushButton = PushButton::New();
391 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
393 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f );
395 DALI_TEST_EQUALS( pushButton.GetProperty<float>(pushButton.GetPropertyIndex("initialAutoRepeatingDelay") ), 1.f, TEST_LOCATION );
400 int UtcDaliPushButtonAutorepeatingDelayPropertyValues02(void)
402 ToolkitTestApplication application;
403 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
405 PushButton pushButton = PushButton::New();
407 bool assert1( false );
408 bool assert2( false );
410 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
414 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f );
416 catch( Dali::DaliException& e )
418 DALI_TEST_PRINT_ASSERT( e );
419 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
425 pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f );
427 catch( Dali::DaliException& e )
429 DALI_TEST_PRINT_ASSERT( e );
430 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
434 DALI_TEST_CHECK( assert1 && assert2 );
438 int UtcDaliPushButtonLabelProperty(void)
440 ToolkitTestApplication application;
441 tet_infoline(" UtcDaliPushButtonSetLabelText");
443 const std::string STR( "Hola!" );
445 PushButton pushButton = PushButton::New();
447 application.SendNotification();
448 application.Render();
450 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
451 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
452 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
456 pushButton.SetProperty( Toolkit::Button::Property::LABEL, STR );
458 DALI_TEST_EQUALS( GetButtonText( pushButton ), STR, TEST_LOCATION );
463 int UtcDaliPushButtonPressed(void)
465 ToolkitTestApplication application;
466 tet_infoline(" UtcDaliPushButtonPressed");
468 PushButton pushButton = PushButton::New();
469 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
470 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
471 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
472 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
474 Stage::GetCurrent().Add( pushButton );
476 application.SendNotification();
477 application.Render();
479 gPushButtonPressed = false;
481 // connect to its touch signal
482 pushButton.PressedSignal().Connect( &PushButtonPressed );
484 Dali::Integration::TouchEvent eventDown;
485 eventDown.AddPoint( GetPointDownInside() );
487 // flush the queue and render once
488 application.SendNotification();
489 application.Render();
490 application.ProcessEvent( eventDown );
492 DALI_TEST_CHECK( gPushButtonPressed );
496 int UtcDaliPushButtonReleased(void)
498 ToolkitTestApplication application;
499 tet_infoline(" UtcDaliPushButtonReleased");
501 PushButton pushButton = PushButton::New();
502 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
503 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
504 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
505 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
507 Stage::GetCurrent().Add( pushButton );
509 application.SendNotification();
510 application.Render();
512 // connect to its touch signal
513 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
515 Dali::Integration::TouchEvent event;
517 // Test1. Touch point down and up inside the button.
519 gPushButtonReleased = false;
520 event = Dali::Integration::TouchEvent();
521 event.AddPoint( GetPointDownInside() );
522 application.ProcessEvent( event );
524 event = Dali::Integration::TouchEvent();
525 event.AddPoint( GetPointUpInside() );
526 application.ProcessEvent( event );
528 DALI_TEST_CHECK( gPushButtonReleased );
530 // Test2. Touch point down and up outside the button.
532 gPushButtonReleased = false;
533 event = Dali::Integration::TouchEvent();
534 event.AddPoint( GetPointDownOutside() );
535 application.ProcessEvent( event );
537 event = Dali::Integration::TouchEvent();
538 event.AddPoint( GetPointUpOutside() );
539 application.ProcessEvent( event );
541 DALI_TEST_CHECK( !gPushButtonReleased );
543 // Test3. Touch point down inside and up outside the button.
545 gPushButtonReleased = false;
546 event = Dali::Integration::TouchEvent();
547 event.AddPoint( GetPointDownInside() );
548 application.ProcessEvent( event );
550 event = Dali::Integration::TouchEvent();
551 event.AddPoint( GetPointLeave() );
552 application.ProcessEvent( event );
554 event = Dali::Integration::TouchEvent();
555 event.AddPoint( GetPointUpOutside() );
556 application.ProcessEvent( event );
558 DALI_TEST_CHECK( gPushButtonReleased );
560 // Test4. Touch point down outside and up inside the button.
562 gPushButtonReleased = false;
563 event = Dali::Integration::TouchEvent();
564 event.AddPoint( GetPointDownOutside() );
565 application.ProcessEvent( event );
567 event = Dali::Integration::TouchEvent();
568 event.AddPoint( GetPointEnter() );
569 application.ProcessEvent( event );
571 event = Dali::Integration::TouchEvent();
572 event.AddPoint( GetPointUpInside() );
573 application.ProcessEvent( event );
575 DALI_TEST_CHECK( !gPushButtonReleased );
579 int UtcDaliPushButtonSelected(void)
581 ToolkitTestApplication application;
582 tet_infoline(" UtcDaliPushButtonSelected");
584 PushButton pushButton = PushButton::New();
585 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
586 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
587 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
588 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
590 Stage::GetCurrent().Add( pushButton );
592 application.SendNotification();
593 application.Render();
595 // connect to its touch signal
596 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
598 Dali::Integration::TouchEvent event;
600 // Test1. No togglable button.
602 gPushButtonSelectedState = false;
603 event = Dali::Integration::TouchEvent();
604 event.AddPoint( GetPointDownInside() );
605 application.ProcessEvent( event );
607 event = Dali::Integration::TouchEvent();
608 event.AddPoint( GetPointUpInside() );
609 application.ProcessEvent( event );
611 DALI_TEST_CHECK( !gPushButtonSelectedState );
613 // Set togglable property.
614 pushButton.SetProperty( Button::Property::TOGGLABLE, true );
616 // Test2. Touch point down and up inside the button twice.
617 gPushButtonSelectedState = false;
618 event = Dali::Integration::TouchEvent();
619 event.AddPoint( GetPointDownInside() );
620 application.ProcessEvent( event );
622 event = Dali::Integration::TouchEvent();
623 event.AddPoint( GetPointUpInside() );
624 application.ProcessEvent( event );
626 DALI_TEST_CHECK( gPushButtonSelectedState );
628 event = Dali::Integration::TouchEvent();
629 event.AddPoint( GetPointDownInside() );
630 application.ProcessEvent( event );
632 event = Dali::Integration::TouchEvent();
633 event.AddPoint( GetPointUpInside() );
634 application.ProcessEvent( event );
636 DALI_TEST_CHECK( !gPushButtonSelectedState );
638 // Test3. Touch point down and up outside the button.
640 gPushButtonSelectedState = false;
641 event = Dali::Integration::TouchEvent();
642 event.AddPoint( GetPointDownOutside() );
643 application.ProcessEvent( event );
645 event = Dali::Integration::TouchEvent();
646 event.AddPoint( GetPointUpOutside() );
647 application.ProcessEvent( event );
649 DALI_TEST_CHECK( !gPushButtonSelectedState );
651 // Test4. Touch point down inside and up outside the button.
652 // State changes on Button down
653 gPushButtonSelectedState = false;
654 event = Dali::Integration::TouchEvent();
655 event.AddPoint( GetPointDownInside() );
656 application.ProcessEvent( event );
658 event = Dali::Integration::TouchEvent();
659 event.AddPoint( GetPointLeave() );
660 application.ProcessEvent( event );
662 event = Dali::Integration::TouchEvent();
663 event.AddPoint( GetPointUpOutside() );
664 application.ProcessEvent( event );
666 DALI_TEST_CHECK( gPushButtonSelectedState );
668 // Test5. Touch point down outside and up inside the button.
669 // Start in unselected state
670 pushButton.SetProperty( Button::Property::SELECTED, false );
672 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("selected") ),false , TEST_LOCATION );
674 gPushButtonSelectedState = false;
675 event = Dali::Integration::TouchEvent();
676 event.AddPoint( GetPointDownOutside() );
677 application.ProcessEvent( event );
679 event = Dali::Integration::TouchEvent();
680 event.AddPoint( GetPointEnter() );
681 application.ProcessEvent( event );
683 event = Dali::Integration::TouchEvent();
684 event.AddPoint( GetPointUpInside() );
685 application.ProcessEvent( event );
687 DALI_TEST_CHECK( !gPushButtonSelectedState );
691 int UtcDaliPushButtonPropertySetIconAlignment(void)
693 ToolkitTestApplication application;
694 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
696 PushButton pushButton = PushButton::New();
697 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
698 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
700 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
701 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
706 int UtcDaliPushButtonPropertySetLabelPadding(void)
708 ToolkitTestApplication application;
709 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
711 PushButton pushButton = PushButton::New();
712 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
713 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 );
715 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
716 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 );
721 int UtcDaliPushButtonPropertySetIconPadding(void)
723 ToolkitTestApplication application;
724 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
726 PushButton pushButton = PushButton::New();
727 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
728 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 );
730 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
731 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 );
736 int UtcDaliPushButtonPaddingLayout(void)
738 ToolkitTestApplication application;
739 tet_infoline(" UtcDaliPushButtonPaddingLayout");
741 // This test creates padding for an icon and a label.
742 // The icon and label are each enabled and disabled to confirm the correct padding is used.
743 PushButton pushButton = PushButton::New();
745 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
746 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
748 // Get actual size of test image
749 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
750 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
752 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
753 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
754 pushButton.SetPosition( 0.0f, 0.0f );
755 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
757 Stage::GetCurrent().Add( pushButton );
759 application.SendNotification();
760 application.Render();
762 // First test the size is zero.
763 // No padding should be added as there is no label or icon.
764 Vector2 size( Vector2::ZERO );
765 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
766 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
767 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
769 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
771 // Check label only padding
772 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
774 application.SendNotification();
775 application.Render();
777 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
778 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
779 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
781 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
783 // Add label padding to label
784 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
785 application.SendNotification();
786 application.Render();
788 Vector2 sizeLabelAndPadding( Vector2::ZERO );
789 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
790 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
791 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
793 // If control size has increased beyond size of just label then padding has been applied
794 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
795 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
797 // Re-initialise the button so we can setup icon-only padding.
798 pushButton.Unparent();
799 pushButton = PushButton::New();
801 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
802 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
803 pushButton.SetPosition( 0.0f, 0.0f );
804 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
806 Stage::GetCurrent().Add( pushButton );
809 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
810 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
811 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
813 application.SendNotification();
814 application.Render();
816 // Size of button with just icon
817 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
818 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
819 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
821 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
823 application.SendNotification();
824 application.Render();
825 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
827 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
828 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
829 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
830 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 );
831 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
833 // Now test padding for both label and icon simultaneously.
834 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
836 application.SendNotification();
837 application.Render();
839 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
840 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
841 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
843 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
845 application.SendNotification();
846 application.Render();
848 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
849 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
850 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
852 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
853 // Test height of control is same as icon and padding, as Text is smaller than icon
854 DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
859 int UtcDaliPushButtonAlignmentLayout(void)
861 ToolkitTestApplication application;
862 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
865 * This test checks different alignments for the icon against the label.
866 * The icon is then moved around the label in each of it's alignments.
867 * The final relayed out size is checked to confirm the layout has been done correctly.
869 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
870 * - Therefore total width and height are both 150.
872 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
873 * - Therefore total width and height are 60+x and 60+y respectively.
874 * Where x & y are the width and height of the text.
876 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
877 * So We use the padding to help us determine the orientation is correct for each alignment.
879 * |<- 150 ->| |<-- 60+x -->|
882 * | | ^ +------------+ -
884 * | Icon | 150 | Label | 60+y
886 * | | v +------------+ -
890 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
891 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
893 // Get actual size of test image
894 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
895 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
897 PushButton pushButton = PushButton::New();
899 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
900 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
901 pushButton.SetPosition( 0.0f, 0.0f );
902 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
904 Stage::GetCurrent().Add( pushButton );
906 // Add a label and get size of control
907 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
908 application.SendNotification();
909 application.Render();
911 // First get the size of control with just label
912 Vector2 justLabelSize( Vector2::ZERO );
913 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
914 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
915 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
917 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
918 application.SendNotification();
919 application.Render();
921 // Size of Label and Padding
922 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
923 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
924 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
926 Vector2 labelAndPaddingSize( Vector2::ZERO );
927 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
928 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
930 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
932 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
933 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
935 // Add Icon and set its alignment
936 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
937 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
938 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
939 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
941 application.SendNotification();
942 application.Render();
944 Vector2 size( Vector2::ZERO );
945 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
946 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
949 * Test Icon right alignment.
950 * Height grows to largest of Icon or Label (+ padding).
951 * Normally this will be Icons height, except with very large font sizes.
953 * +------------+---------+
959 * +------------+---------+
961 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
962 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
964 // Now test left alignment matches right for size.
965 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
967 application.SendNotification();
968 application.Render();
970 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
971 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
974 * Test Icon left alignment.
975 * Height grows to largest of Icon or Label (+ padding).
976 * Normally this will be Icons height, except with very large font sizes.
978 * +---------+------------+
984 * +---------+------------+
986 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
987 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
989 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
1006 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
1007 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
1009 application.SendNotification();
1010 application.Render();
1012 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1013 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1015 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
1016 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
1018 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
1019 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
1021 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
1023 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1026 * Test Icon bottom alignment.
1027 * Width grows to largest of Icon or Label (+ padding).
1041 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1042 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
1044 application.SendNotification();
1045 application.Render();
1047 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1048 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1050 DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1051 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1056 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1058 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1059 ToolkitTestApplication application;
1061 PushButton pushButton = PushButton::New();
1062 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
1064 Stage::GetCurrent().Add( pushButton );
1066 Property::Map propertyMap;
1067 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1068 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1070 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1072 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1074 application.SendNotification();
1075 application.Render(0);
1077 unsigned int rendererCount = pushButton.GetRendererCount();
1078 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1080 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1082 tet_printf("Remove button from stage\n" );
1084 Stage::GetCurrent().Remove( pushButton );
1086 rendererCount = pushButton.GetRendererCount();
1087 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1089 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1091 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1093 Property::Map propertyMap2;
1094 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1095 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1096 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap2 );
1098 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1100 Stage::GetCurrent().Add( pushButton );
1102 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1104 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1109 int UtcDaliPushButtonSetSelectedVisualN(void)
1111 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1113 ToolkitTestApplication application;
1115 PushButton pushButton = PushButton::New();
1117 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1118 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1119 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1121 Stage::GetCurrent().Add( pushButton );
1122 application.SendNotification();
1123 application.Render(0);
1125 unsigned int preRendererCount = pushButton.GetRendererCount();
1126 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1127 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1129 Stage::GetCurrent().Remove( pushButton );
1130 application.SendNotification();
1131 application.Render(0);
1133 Property::Map colorMap;
1134 const int BROKEN_VISUAL_TYPE = 999999999;
1136 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1137 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1138 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1139 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, colorMap );
1141 Stage::GetCurrent().Add( pushButton );
1142 application.SendNotification();
1143 application.Render(0);
1145 unsigned int postRendererCount = pushButton.GetRendererCount();
1146 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1147 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1152 int UtcDaliPushButtonSetButtonImageP(void)
1154 ToolkitTestApplication application;
1156 PushButton button = PushButton::New();
1157 Stage::GetCurrent().Add( button );
1161 button.SetButtonImage( ImageView::New() );
1162 DALI_TEST_CHECK( true );
1166 DALI_TEST_CHECK( false );
1172 int UtcDaliPushButtonSetBackgroundImageP(void)
1174 ToolkitTestApplication application;
1176 PushButton button = PushButton::New();
1177 Stage::GetCurrent().Add( button );
1181 button.SetBackgroundImage( ImageView::New() );
1182 DALI_TEST_CHECK( true );
1186 DALI_TEST_CHECK( false );
1192 int UtcDaliPushButtonSetSelectedImageP(void)
1194 ToolkitTestApplication application;
1196 PushButton button = PushButton::New();
1197 Stage::GetCurrent().Add( button );
1201 button.SetSelectedImage( ImageView::New() );
1202 DALI_TEST_CHECK( true );
1206 DALI_TEST_CHECK( false );
1212 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1214 ToolkitTestApplication application;
1216 PushButton button = PushButton::New();
1217 Stage::GetCurrent().Add( button );
1221 button.SetSelectedBackgroundImage( ImageView::New() );
1222 DALI_TEST_CHECK( true );
1226 DALI_TEST_CHECK( false );
1232 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1234 ToolkitTestApplication application;
1236 PushButton button = PushButton::New();
1237 Stage::GetCurrent().Add( button );
1241 button.SetDisabledBackgroundImage( ImageView::New() );
1242 DALI_TEST_CHECK( true );
1246 DALI_TEST_CHECK( false );
1253 int UtcDaliPushButtonSetDisabledImageP(void)
1255 ToolkitTestApplication application;
1257 PushButton button = PushButton::New();
1258 Stage::GetCurrent().Add( button );
1262 button.SetDisabledImage( ImageView::New() );
1263 DALI_TEST_CHECK( true );
1267 DALI_TEST_CHECK( false );
1273 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1275 ToolkitTestApplication application;
1277 PushButton button = PushButton::New();
1278 Stage::GetCurrent().Add( button );
1282 button.SetDisabledSelectedImage( ImageView::New() );
1283 DALI_TEST_CHECK( true );
1287 DALI_TEST_CHECK( false );
1293 int UtcDaliPushButtonToggleSignalP(void)
1295 ToolkitTestApplication application;
1296 tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1298 PushButton button = PushButton::New();
1299 button.SetProperty( Button::Property::TOGGLABLE, true);
1301 SetupButtonForTestTouchEvents( application, button, true );
1303 Stage::GetCurrent().Add( button );
1305 application.SendNotification();
1306 application.Render();
1308 // connect to its signal
1309 button.ClickedSignal().Connect( &PushButtonClicked );
1310 gPushButtonClicked = false;
1312 tet_infoline(" Touch down and up within button");
1313 Dali::Integration::TouchEvent event;
1314 event = Dali::Integration::TouchEvent();
1315 event.AddPoint( GetPointDownInside() );
1316 application.ProcessEvent( event );
1318 event = Dali::Integration::TouchEvent();
1319 event.AddPoint( GetPointUpInside() );
1320 application.ProcessEvent( event );
1322 DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION );
1327 // Deprecated API Tests
1329 int UtcDaliPushButtonSetGetAutoRepeating(void)
1331 ToolkitTestApplication application;
1332 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
1334 PushButton pushButton = PushButton::New();
1336 pushButton.SetAutoRepeating( true );
1338 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1340 pushButton.SetAutoRepeating( false );
1342 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1344 pushButton.SetAutoRepeating( true );
1346 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1350 int UtcDaliPushButtonSetGetTogglableButton(void)
1352 ToolkitTestApplication application;
1353 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
1355 PushButton pushButton = PushButton::New();
1357 pushButton.SetTogglableButton( true );
1359 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1361 pushButton.SetTogglableButton( false );
1363 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1365 pushButton.SetTogglableButton( true );
1367 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1371 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
1373 ToolkitTestApplication application;
1374 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
1376 PushButton pushButton = PushButton::New();
1378 pushButton.SetAutoRepeating( true );
1379 pushButton.SetTogglableButton( true );
1381 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1382 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1384 pushButton.SetTogglableButton( true );
1385 pushButton.SetAutoRepeating( true );
1387 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1388 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1392 int UtcDaliPushButtonSetGetSelected01(void)
1394 ToolkitTestApplication application;
1395 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
1397 PushButton pushButton = PushButton::New();
1399 pushButton.SetTogglableButton( true );
1400 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1402 gPushButtonSelectedState = false;
1403 pushButton.SetSelected( true );
1405 DALI_TEST_CHECK( pushButton.IsSelected() );
1406 DALI_TEST_CHECK( gPushButtonSelectedState );
1408 pushButton.SetSelected( false );
1410 DALI_TEST_CHECK( !pushButton.IsSelected() );
1411 DALI_TEST_CHECK( !gPushButtonSelectedState );
1413 pushButton.SetSelected( true );
1415 DALI_TEST_CHECK( pushButton.IsSelected() );
1416 DALI_TEST_CHECK( gPushButtonSelectedState );
1420 int UtcDaliPushButtonSetGetSelected02(void)
1422 ToolkitTestApplication application;
1423 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
1425 PushButton pushButton = PushButton::New();
1427 pushButton.SetTogglableButton( false );
1428 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1430 gPushButtonSelectedState = false;
1431 pushButton.SetSelected( true );
1433 DALI_TEST_CHECK( !pushButton.IsSelected() );
1434 DALI_TEST_CHECK( !gPushButtonSelectedState );
1436 pushButton.SetSelected( false );
1438 DALI_TEST_CHECK( !pushButton.IsSelected() );
1439 DALI_TEST_CHECK( !gPushButtonSelectedState );
1441 pushButton.SetSelected( true );
1443 DALI_TEST_CHECK( !pushButton.IsSelected() );
1444 DALI_TEST_CHECK( !gPushButtonSelectedState );
1448 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
1450 ToolkitTestApplication application;
1451 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
1453 PushButton pushButton = PushButton::New();
1455 pushButton.SetAutoRepeating( true );
1457 pushButton.SetInitialAutoRepeatingDelay( 1.f );
1458 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1460 pushButton.SetNextAutoRepeatingDelay( 1.f );
1461 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1465 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
1467 ToolkitTestApplication application;
1468 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
1470 PushButton pushButton = PushButton::New();
1472 bool assert1( false );
1473 bool assert2( false );
1475 pushButton.SetAutoRepeating( true );
1479 pushButton.SetInitialAutoRepeatingDelay( -1.f );
1481 catch( Dali::DaliException& e )
1483 DALI_TEST_PRINT_ASSERT( e );
1484 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
1490 pushButton.SetNextAutoRepeatingDelay( -1.f );
1492 catch( Dali::DaliException& e )
1494 DALI_TEST_PRINT_ASSERT( e );
1495 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
1499 DALI_TEST_CHECK( assert1 && assert2 );
1503 int UtcDaliPushButtonSetLabelText(void)
1505 ToolkitTestApplication application;
1506 tet_infoline(" UtcDaliPushButtonSetLabelText");
1508 const std::string STR( "Hola!" );
1510 PushButton pushButton = PushButton::New();
1512 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
1513 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
1514 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1517 application.SendNotification();
1518 application.Render();
1520 pushButton.SetLabelText( STR );
1522 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );