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";
50 static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2( 240, 400 );
51 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3( 200, 360, 0 );
52 static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size( 100, 100 );
54 static bool gPushButtonSelectedState = false;
55 bool PushButtonSelected( Button button )
57 gPushButtonSelectedState = button.GetProperty<bool>(button.GetPropertyIndex("selected") );
61 static bool gPushButtonPressed = false;
63 static bool PushButtonPressed( Button button )
65 gPushButtonPressed = true;
69 static bool gPushButtonReleased = false;
71 static bool PushButtonReleased( Button button )
73 gPushButtonReleased = true;
77 static bool gPushButtonClicked = false;
79 static bool PushButtonClicked( Button button )
81 gPushButtonClicked = true;
82 return gPushButtonClicked;
85 Dali::Integration::Point GetPointDownInside()
87 Dali::Integration::Point point;
88 point.SetState( PointState::DOWN );
89 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
93 Dali::Integration::Point GetPointUpInside()
95 Dali::Integration::Point point;
96 point.SetState( PointState::UP );
97 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
101 Dali::Integration::Point GetPointLeave()
103 Dali::Integration::Point point;
104 point.SetState( PointState::LEAVE );
105 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
109 Dali::Integration::Point GetPointEnter()
111 Dali::Integration::Point point;
112 point.SetState( PointState::MOTION );
113 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
117 Dali::Integration::Point GetPointDownOutside()
119 Dali::Integration::Point point;
120 point.SetState( PointState::DOWN );
121 point.SetScreenPosition( Vector2( 10, 10 ) );
125 Dali::Integration::Point GetPointUpOutside()
127 Dali::Integration::Point point;
128 point.SetState( PointState::UP );
129 point.SetScreenPosition( Vector2( 10, 10 ) );
133 // Set up the position of the button for the default test events
134 void SetupButtonForTestTouchEvents( ToolkitTestApplication& application, Button& button, bool useDefaultImages )
136 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
137 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
138 button.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
139 if ( useDefaultImages )
141 const Vector2 TEST_IMAGE_SIZE = Vector2( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
142 TestPlatformAbstraction& platform = application.GetPlatform();
143 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
144 button.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
145 button.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
149 static std::string GetButtonText( Button button )
151 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
153 Property::Map *labelProperty = value.GetMap();
155 std::string textLabel;
159 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
160 value->Get( textLabel );
168 int UtcDaliPushButtonConstructorP(void)
170 TestApplication application;
174 DALI_TEST_CHECK( !button );
178 int UtcDaliPushButtonCopyConstructorP(void)
180 TestApplication application;
182 // Initialize an object, ref count == 1
183 PushButton button = PushButton::New();
185 PushButton copy( button );
186 DALI_TEST_CHECK( copy );
190 int UtcDaliPushButtonAssignmentOperatorP(void)
192 TestApplication application;
194 PushButton button = PushButton::New();
196 PushButton copy( button );
197 DALI_TEST_CHECK( copy );
199 DALI_TEST_CHECK( button == copy );
203 int UtcDaliPushButtonNewP(void)
205 TestApplication application;
207 PushButton button = PushButton::New();
209 DALI_TEST_CHECK( button );
213 int UtcDaliPushButtonDownCastP(void)
215 TestApplication application;
217 PushButton button = PushButton::New();
219 BaseHandle object(button);
221 PushButton button2 = PushButton::DownCast( object );
222 DALI_TEST_CHECK(button2);
224 PushButton button3 = DownCast< PushButton >(object);
225 DALI_TEST_CHECK(button3);
229 int UtcDaliPushButtonDownCastN(void)
231 TestApplication application;
233 BaseHandle unInitializedObject;
235 PushButton button1 = PushButton::DownCast( unInitializedObject );
236 DALI_TEST_CHECK( !button1 );
238 PushButton button2 = DownCast< PushButton >( unInitializedObject );
239 DALI_TEST_CHECK( !button2 );
243 int UtcDaliPushButtonAutoRepeatingProperty(void)
245 ToolkitTestApplication application;
246 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
248 PushButton pushButton = PushButton::New();
250 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
251 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
253 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), false );
254 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
256 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
257 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
262 int UtcDaliPushButtonSetAutoRepeating(void)
264 ToolkitTestApplication application;
265 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
266 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
267 PushButton pushButton = PushButton::New();
269 const bool INITIAL_TOGGLE_VALUE = true;
270 const bool INITIAL_SELECTED_VALUE = true;
272 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
273 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
275 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
276 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
278 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
280 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
285 int UtcDaliPushButtonTogglableProperty(void)
287 ToolkitTestApplication application;
288 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
290 PushButton pushButton = PushButton::New();
292 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
293 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
295 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
296 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
298 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
299 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
304 int UtcDaliPushButtonAutoRepeatingPropertyAndTogglableButton(void)
306 ToolkitTestApplication application;
307 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
309 PushButton pushButton = PushButton::New();
311 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
312 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
314 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
315 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
317 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
318 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
320 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
321 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
325 int UtcDaliPushButtonSelectedProperty01(void)
327 ToolkitTestApplication application;
328 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
330 PushButton pushButton = PushButton::New();
332 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
334 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
336 gPushButtonSelectedState = false;
337 pushButton.SetProperty( Button::Property::SELECTED, true );
339 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
340 DALI_TEST_CHECK( gPushButtonSelectedState );
342 pushButton.SetProperty( Button::Property::SELECTED, false );
344 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
345 DALI_TEST_CHECK( !gPushButtonSelectedState );
347 pushButton.SetProperty( Button::Property::SELECTED, true );
349 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
350 DALI_TEST_CHECK( gPushButtonSelectedState );
354 int UtcDaliPushButtonSelectedProperty02(void)
356 ToolkitTestApplication application;
357 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
359 PushButton pushButton = PushButton::New();
361 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
362 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
364 gPushButtonSelectedState = false;
365 pushButton.SetProperty( Button::Property::SELECTED, true );
367 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
368 DALI_TEST_CHECK( !gPushButtonSelectedState );
370 pushButton.SetProperty( Button::Property::SELECTED, false );
372 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
373 DALI_TEST_CHECK( !gPushButtonSelectedState );
375 pushButton.SetProperty( Button::Property::SELECTED, true );
377 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
378 DALI_TEST_CHECK( !gPushButtonSelectedState );
382 int UtcDaliPushButtonAutorepeatingDelayPropertyValues01(void)
384 ToolkitTestApplication application;
385 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
387 PushButton pushButton = PushButton::New();
389 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
391 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f );
393 DALI_TEST_EQUALS( pushButton.GetProperty<float>(pushButton.GetPropertyIndex("initialAutoRepeatingDelay") ), 1.f, TEST_LOCATION );
398 int UtcDaliPushButtonAutorepeatingDelayPropertyValues02(void)
400 ToolkitTestApplication application;
401 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
403 PushButton pushButton = PushButton::New();
405 bool assert1( false );
406 bool assert2( false );
408 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
412 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f );
414 catch( Dali::DaliException& e )
416 DALI_TEST_PRINT_ASSERT( e );
417 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
423 pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f );
425 catch( Dali::DaliException& e )
427 DALI_TEST_PRINT_ASSERT( e );
428 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
432 DALI_TEST_CHECK( assert1 && assert2 );
436 int UtcDaliPushButtonLabelProperty(void)
438 ToolkitTestApplication application;
439 tet_infoline(" UtcDaliPushButtonSetLabelText");
441 const std::string STR( "Hola!" );
443 PushButton pushButton = PushButton::New();
445 application.SendNotification();
446 application.Render();
448 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
449 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
450 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
454 pushButton.SetProperty( Toolkit::Button::Property::LABEL, STR );
456 DALI_TEST_EQUALS( GetButtonText( pushButton ), STR, TEST_LOCATION );
461 int UtcDaliPushButtonPressed(void)
463 ToolkitTestApplication application;
464 tet_infoline(" UtcDaliPushButtonPressed");
466 PushButton pushButton = PushButton::New();
467 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
468 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
469 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
470 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
472 Stage::GetCurrent().Add( pushButton );
474 application.SendNotification();
475 application.Render();
477 gPushButtonPressed = false;
479 // connect to its touch signal
480 pushButton.PressedSignal().Connect( &PushButtonPressed );
482 Dali::Integration::TouchEvent eventDown;
483 eventDown.AddPoint( GetPointDownInside() );
485 // flush the queue and render once
486 application.SendNotification();
487 application.Render();
488 application.ProcessEvent( eventDown );
490 DALI_TEST_CHECK( gPushButtonPressed );
494 int UtcDaliPushButtonReleased(void)
496 ToolkitTestApplication application;
497 tet_infoline(" UtcDaliPushButtonReleased");
499 PushButton pushButton = PushButton::New();
500 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
501 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
502 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
503 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
505 Stage::GetCurrent().Add( pushButton );
507 application.SendNotification();
508 application.Render();
510 // connect to its touch signal
511 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
513 Dali::Integration::TouchEvent event;
515 // Test1. Touch point down and up inside the button.
517 gPushButtonReleased = false;
518 event = Dali::Integration::TouchEvent();
519 event.AddPoint( GetPointDownInside() );
520 application.ProcessEvent( event );
522 event = Dali::Integration::TouchEvent();
523 event.AddPoint( GetPointUpInside() );
524 application.ProcessEvent( event );
526 DALI_TEST_CHECK( gPushButtonReleased );
528 // Test2. Touch point down and up outside the button.
530 gPushButtonReleased = false;
531 event = Dali::Integration::TouchEvent();
532 event.AddPoint( GetPointDownOutside() );
533 application.ProcessEvent( event );
535 event = Dali::Integration::TouchEvent();
536 event.AddPoint( GetPointUpOutside() );
537 application.ProcessEvent( event );
539 DALI_TEST_CHECK( !gPushButtonReleased );
541 // Test3. Touch point down inside and up outside the button.
543 gPushButtonReleased = false;
544 event = Dali::Integration::TouchEvent();
545 event.AddPoint( GetPointDownInside() );
546 application.ProcessEvent( event );
548 event = Dali::Integration::TouchEvent();
549 event.AddPoint( GetPointLeave() );
550 application.ProcessEvent( event );
552 event = Dali::Integration::TouchEvent();
553 event.AddPoint( GetPointUpOutside() );
554 application.ProcessEvent( event );
556 DALI_TEST_CHECK( gPushButtonReleased );
558 // Test4. Touch point down outside and up inside the button.
560 gPushButtonReleased = false;
561 event = Dali::Integration::TouchEvent();
562 event.AddPoint( GetPointDownOutside() );
563 application.ProcessEvent( event );
565 event = Dali::Integration::TouchEvent();
566 event.AddPoint( GetPointEnter() );
567 application.ProcessEvent( event );
569 event = Dali::Integration::TouchEvent();
570 event.AddPoint( GetPointUpInside() );
571 application.ProcessEvent( event );
573 DALI_TEST_CHECK( !gPushButtonReleased );
577 int UtcDaliPushButtonSelected(void)
579 ToolkitTestApplication application;
580 tet_infoline(" UtcDaliPushButtonSelected");
582 PushButton pushButton = PushButton::New();
583 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
584 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
585 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
586 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
588 Stage::GetCurrent().Add( pushButton );
590 application.SendNotification();
591 application.Render();
593 // connect to its touch signal
594 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
596 Dali::Integration::TouchEvent event;
598 // Test1. No togglable button.
600 gPushButtonSelectedState = false;
601 event = Dali::Integration::TouchEvent();
602 event.AddPoint( GetPointDownInside() );
603 application.ProcessEvent( event );
605 event = Dali::Integration::TouchEvent();
606 event.AddPoint( GetPointUpInside() );
607 application.ProcessEvent( event );
609 DALI_TEST_CHECK( !gPushButtonSelectedState );
611 // Set togglable property.
612 pushButton.SetProperty( Button::Property::TOGGLABLE, true );
614 // Test2. Touch point down and up inside the button twice.
615 gPushButtonSelectedState = false;
616 event = Dali::Integration::TouchEvent();
617 event.AddPoint( GetPointDownInside() );
618 application.ProcessEvent( event );
620 event = Dali::Integration::TouchEvent();
621 event.AddPoint( GetPointUpInside() );
622 application.ProcessEvent( event );
624 DALI_TEST_CHECK( gPushButtonSelectedState );
626 event = Dali::Integration::TouchEvent();
627 event.AddPoint( GetPointDownInside() );
628 application.ProcessEvent( event );
630 event = Dali::Integration::TouchEvent();
631 event.AddPoint( GetPointUpInside() );
632 application.ProcessEvent( event );
634 DALI_TEST_CHECK( !gPushButtonSelectedState );
636 // Test3. Touch point down and up outside the button.
638 gPushButtonSelectedState = false;
639 event = Dali::Integration::TouchEvent();
640 event.AddPoint( GetPointDownOutside() );
641 application.ProcessEvent( event );
643 event = Dali::Integration::TouchEvent();
644 event.AddPoint( GetPointUpOutside() );
645 application.ProcessEvent( event );
647 DALI_TEST_CHECK( !gPushButtonSelectedState );
649 // Test4. Touch point down inside and up outside the button.
650 // State changes on Button down
651 gPushButtonSelectedState = false;
652 event = Dali::Integration::TouchEvent();
653 event.AddPoint( GetPointDownInside() );
654 application.ProcessEvent( event );
656 event = Dali::Integration::TouchEvent();
657 event.AddPoint( GetPointLeave() );
658 application.ProcessEvent( event );
660 event = Dali::Integration::TouchEvent();
661 event.AddPoint( GetPointUpOutside() );
662 application.ProcessEvent( event );
664 DALI_TEST_CHECK( gPushButtonSelectedState );
666 // Test5. Touch point down outside and up inside the button.
667 // Start in unselected state
668 pushButton.SetProperty( Button::Property::SELECTED, false );
670 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("selected") ),false , TEST_LOCATION );
672 gPushButtonSelectedState = false;
673 event = Dali::Integration::TouchEvent();
674 event.AddPoint( GetPointDownOutside() );
675 application.ProcessEvent( event );
677 event = Dali::Integration::TouchEvent();
678 event.AddPoint( GetPointEnter() );
679 application.ProcessEvent( event );
681 event = Dali::Integration::TouchEvent();
682 event.AddPoint( GetPointUpInside() );
683 application.ProcessEvent( event );
685 DALI_TEST_CHECK( !gPushButtonSelectedState );
689 int UtcDaliPushButtonPropertySetIconAlignment(void)
691 ToolkitTestApplication application;
692 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
694 PushButton pushButton = PushButton::New();
695 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
696 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
698 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
699 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
704 int UtcDaliPushButtonPropertySetLabelPadding(void)
706 ToolkitTestApplication application;
707 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
709 PushButton pushButton = PushButton::New();
710 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
711 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 );
713 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
714 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 );
719 int UtcDaliPushButtonPropertySetIconPadding(void)
721 ToolkitTestApplication application;
722 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
724 PushButton pushButton = PushButton::New();
725 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
726 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 );
728 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
729 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 );
734 int UtcDaliPushButtonPaddingLayout(void)
736 ToolkitTestApplication application;
737 tet_infoline(" UtcDaliPushButtonPaddingLayout");
739 // This test creates padding for an icon and a label.
740 // The icon and label are each enabled and disabled to confirm the correct padding is used.
741 PushButton pushButton = PushButton::New();
743 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
744 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
746 // Get actual size of test image
747 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
748 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
750 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
751 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
752 pushButton.SetPosition( 0.0f, 0.0f );
753 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
755 Stage::GetCurrent().Add( pushButton );
757 application.SendNotification();
758 application.Render();
760 // First test the size is zero.
761 // No padding should be added as there is no label or icon.
762 Vector2 size( Vector2::ZERO );
763 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
764 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
765 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
767 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
769 // Check label only padding
770 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
772 application.SendNotification();
773 application.Render();
775 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
776 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
777 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
779 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
781 // Add label padding to label
782 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
783 application.SendNotification();
784 application.Render();
786 Vector2 sizeLabelAndPadding( Vector2::ZERO );
787 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
788 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
789 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
791 // If control size has increased beyond size of just label then padding has been applied
792 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
793 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
795 // Re-initialise the button so we can setup icon-only padding.
796 pushButton.Unparent();
797 pushButton = PushButton::New();
799 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
800 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
801 pushButton.SetPosition( 0.0f, 0.0f );
802 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
804 Stage::GetCurrent().Add( pushButton );
807 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
808 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
809 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
811 application.SendNotification();
812 application.Render();
814 // Size of button with just icon
815 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
816 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
817 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
819 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
821 application.SendNotification();
822 application.Render();
823 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
825 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
826 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
827 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
828 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 );
829 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
831 // Now test padding for both label and icon simultaneously.
832 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
834 application.SendNotification();
835 application.Render();
837 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
838 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
839 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
841 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
843 application.SendNotification();
844 application.Render();
846 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
847 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
848 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
850 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
851 // Test height of control is same as icon and padding, as Text is smaller than icon
852 DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
857 int UtcDaliPushButtonAlignmentLayout(void)
859 ToolkitTestApplication application;
860 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
863 * This test checks different alignments for the icon against the label.
864 * The icon is then moved around the label in each of it's alignments.
865 * The final relayed out size is checked to confirm the layout has been done correctly.
867 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
868 * - Therefore total width and height are both 150.
870 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
871 * - Therefore total width and height are 60+x and 60+y respectively.
872 * Where x & y are the width and height of the text.
874 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
875 * So We use the padding to help us determine the orientation is correct for each alignment.
877 * |<- 150 ->| |<-- 60+x -->|
880 * | | ^ +------------+ -
882 * | Icon | 150 | Label | 60+y
884 * | | v +------------+ -
888 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
889 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
891 // Get actual size of test image
892 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
893 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
895 PushButton pushButton = PushButton::New();
897 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
898 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
899 pushButton.SetPosition( 0.0f, 0.0f );
900 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
902 Stage::GetCurrent().Add( pushButton );
904 // Add a label and get size of control
905 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
906 application.SendNotification();
907 application.Render();
909 // First get the size of control with just label
910 Vector2 justLabelSize( Vector2::ZERO );
911 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
912 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
913 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
915 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
916 application.SendNotification();
917 application.Render();
919 // Size of Label and Padding
920 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
921 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
922 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
924 Vector2 labelAndPaddingSize( Vector2::ZERO );
925 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
926 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
928 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
930 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
931 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
933 // Add Icon and set its alignment
934 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
935 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
936 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
937 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
939 application.SendNotification();
940 application.Render();
942 Vector2 size( Vector2::ZERO );
943 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
944 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
947 * Test Icon right alignment.
948 * Height grows to largest of Icon or Label (+ padding).
949 * Normally this will be Icons height, except with very large font sizes.
951 * +------------+---------+
957 * +------------+---------+
959 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
960 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
962 // Now test left alignment matches right for size.
963 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
965 application.SendNotification();
966 application.Render();
968 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
969 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
972 * Test Icon left alignment.
973 * Height grows to largest of Icon or Label (+ padding).
974 * Normally this will be Icons height, except with very large font sizes.
976 * +---------+------------+
982 * +---------+------------+
984 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
985 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
987 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
1004 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
1005 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
1007 application.SendNotification();
1008 application.Render();
1010 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1011 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1013 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
1014 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
1016 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
1017 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
1019 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
1021 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1024 * Test Icon bottom alignment.
1025 * Width grows to largest of Icon or Label (+ padding).
1039 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1040 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
1042 application.SendNotification();
1043 application.Render();
1045 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1046 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1048 DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1049 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1054 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1056 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1057 ToolkitTestApplication application;
1059 PushButton pushButton = PushButton::New();
1060 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
1062 Stage::GetCurrent().Add( pushButton );
1064 Property::Map propertyMap;
1065 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1066 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1068 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1070 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1072 application.SendNotification();
1073 application.Render(0);
1075 unsigned int rendererCount = pushButton.GetRendererCount();
1076 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1078 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1080 tet_printf("Remove button from stage\n" );
1082 Stage::GetCurrent().Remove( pushButton );
1084 rendererCount = pushButton.GetRendererCount();
1085 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1087 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1089 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1091 Property::Map propertyMap2;
1092 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1093 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1094 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap2 );
1096 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1098 Stage::GetCurrent().Add( pushButton );
1100 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1102 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1107 int UtcDaliPushButtonSetSelectedVisualN(void)
1109 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1111 ToolkitTestApplication application;
1113 PushButton pushButton = PushButton::New();
1115 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1116 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1117 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1119 Stage::GetCurrent().Add( pushButton );
1120 application.SendNotification();
1121 application.Render(0);
1123 unsigned int preRendererCount = pushButton.GetRendererCount();
1124 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1125 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1127 Stage::GetCurrent().Remove( pushButton );
1128 application.SendNotification();
1129 application.Render(0);
1131 Property::Map colorMap;
1132 const int BROKEN_VISUAL_TYPE = 999999999;
1134 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1135 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1136 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1137 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, colorMap );
1139 Stage::GetCurrent().Add( pushButton );
1140 application.SendNotification();
1141 application.Render(0);
1143 unsigned int postRendererCount = pushButton.GetRendererCount();
1144 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1145 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1150 int UtcDaliPushButtonToggleSignalP(void)
1152 ToolkitTestApplication application;
1153 tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1155 PushButton button = PushButton::New();
1156 button.SetProperty( Button::Property::TOGGLABLE, true);
1158 SetupButtonForTestTouchEvents( application, button, true );
1160 Stage::GetCurrent().Add( button );
1162 application.SendNotification();
1163 application.Render();
1165 // connect to its signal
1166 button.ClickedSignal().Connect( &PushButtonClicked );
1167 gPushButtonClicked = false;
1169 tet_infoline(" Touch down and up within button");
1170 Dali::Integration::TouchEvent event;
1171 event = Dali::Integration::TouchEvent();
1172 event.AddPoint( GetPointDownInside() );
1173 application.ProcessEvent( event );
1175 event = Dali::Integration::TouchEvent();
1176 event.AddPoint( GetPointUpInside() );
1177 application.ProcessEvent( event );
1179 DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION );
1184 // Deprecated API Tests
1186 int UtcDaliPushButtonSetGetAutoRepeating(void)
1188 ToolkitTestApplication application;
1189 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
1191 PushButton pushButton = PushButton::New();
1193 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1195 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
1197 pushButton.SetProperty( Button::Property::AUTO_REPEATING, false );
1199 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), false, TEST_LOCATION );
1201 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1203 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
1207 int UtcDaliPushButtonSetGetTogglableButton(void)
1209 ToolkitTestApplication application;
1210 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
1212 PushButton pushButton = PushButton::New();
1214 pushButton.SetProperty( Button::Property::TOGGLABLE, true );
1216 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), true, TEST_LOCATION );
1218 pushButton.SetProperty( Button::Property::TOGGLABLE, false );
1220 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), false, TEST_LOCATION );
1222 pushButton.SetProperty( Button::Property::TOGGLABLE, true );
1224 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), true, TEST_LOCATION );
1228 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
1230 ToolkitTestApplication application;
1231 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
1233 PushButton pushButton = PushButton::New();
1235 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1236 pushButton.SetProperty( Button::Property::TOGGLABLE, true);
1238 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), true, TEST_LOCATION );
1239 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), false, TEST_LOCATION );
1241 pushButton.SetProperty( Button::Property::TOGGLABLE, true);
1242 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1244 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
1245 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), false, TEST_LOCATION );
1250 int UtcDaliPushButtonSetGetSelected01(void)
1252 ToolkitTestApplication application;
1253 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
1255 PushButton pushButton = PushButton::New();
1257 pushButton.SetProperty( Button::Property::TOGGLABLE, true);
1258 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1260 gPushButtonSelectedState = false;
1261 pushButton.SetProperty( Button::Property::SELECTED, true );
1263 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), true, TEST_LOCATION );
1264 DALI_TEST_CHECK( gPushButtonSelectedState );
1266 pushButton.SetProperty( Button::Property::SELECTED, false );
1268 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), false, TEST_LOCATION );
1269 DALI_TEST_CHECK( !gPushButtonSelectedState );
1271 pushButton.SetProperty( Button::Property::SELECTED, true );
1273 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), true, TEST_LOCATION );
1274 DALI_TEST_CHECK( gPushButtonSelectedState );
1278 int UtcDaliPushButtonSetGetSelected02(void)
1280 ToolkitTestApplication application;
1281 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
1283 PushButton pushButton = PushButton::New();
1285 tet_infoline(" Set Toggle feature off");
1286 pushButton.SetProperty( Button::Property::TOGGLABLE, false);
1287 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1289 gPushButtonSelectedState = false;
1290 tet_infoline(" Try to set to selected, expecting failure as not a toggle button");
1291 pushButton.SetProperty( Button::Property::SELECTED, true );
1293 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), false, TEST_LOCATION );
1294 DALI_TEST_CHECK( !gPushButtonSelectedState );
1296 pushButton.SetProperty( Button::Property::SELECTED, false );
1298 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), false, TEST_LOCATION );
1299 DALI_TEST_CHECK( !gPushButtonSelectedState );
1301 pushButton.SetProperty( Button::Property::SELECTED, true );
1303 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false, TEST_LOCATION );
1304 DALI_TEST_CHECK( !gPushButtonSelectedState );
1309 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
1311 ToolkitTestApplication application;
1312 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
1314 PushButton pushButton = PushButton::New();
1316 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1318 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f);
1319 DALI_TEST_EQUALS( pushButton.GetProperty<float>( Button::Property::INITIAL_AUTO_REPEATING_DELAY ), 1.f, TEST_LOCATION );
1321 pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 1.f);
1323 DALI_TEST_EQUALS( pushButton.GetProperty<float>( Button::Property::NEXT_AUTO_REPEATING_DELAY ), 1.f, TEST_LOCATION );
1327 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
1329 ToolkitTestApplication application;
1330 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
1332 PushButton pushButton = PushButton::New();
1334 bool assert1( false );
1335 bool assert2( false );
1337 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1341 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f );
1343 catch( Dali::DaliException& e )
1345 DALI_TEST_PRINT_ASSERT( e );
1346 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
1352 pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f );
1354 catch( Dali::DaliException& e )
1356 DALI_TEST_PRINT_ASSERT( e );
1357 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
1361 DALI_TEST_CHECK( assert1 && assert2 );
1365 int UtcDaliPushButtonSetLabelText(void)
1367 ToolkitTestApplication application;
1368 tet_infoline(" UtcDaliPushButtonSetLabelText");
1370 const std::string STR( "Hola!" );
1372 PushButton pushButton = PushButton::New();
1374 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
1375 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
1376 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1379 application.SendNotification();
1380 application.Render();
1382 pushButton.SetProperty( Button::Property::LABEL, STR );
1384 DALI_TEST_EQUALS(GetButtonText( pushButton ), STR, TEST_LOCATION);