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";
51 static const char* TEST_IMAGE_TWO = TEST_RESOURCE_DIR "/icon-delete.jpg";
53 static const Vector2 INSIDE_TOUCH_POINT_POSITON = Vector2( 240, 400 );
54 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3( 200, 360, 0 );
55 static const Size BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS = Size( 100, 100 );
57 static bool gPushButtonSelectedState = false;
58 bool PushButtonSelected( Button button )
60 gPushButtonSelectedState = button.GetProperty<bool>(button.GetPropertyIndex("selected") );
64 static bool gPushButtonPressed = false;
66 static bool PushButtonPressed( Button button )
68 gPushButtonPressed = true;
72 static bool gPushButtonReleased = false;
74 static bool PushButtonReleased( Button button )
76 gPushButtonReleased = true;
80 static bool gPushButtonClicked = false;
82 static bool PushButtonClicked( Button button )
84 gPushButtonClicked = true;
85 return gPushButtonClicked;
88 Dali::Integration::Point GetPointDownInside()
90 Dali::Integration::Point point;
91 point.SetState( PointState::DOWN );
92 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
96 Dali::Integration::Point GetPointUpInside()
98 Dali::Integration::Point point;
99 point.SetState( PointState::UP );
100 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
104 Dali::Integration::Point GetPointLeave()
106 Dali::Integration::Point point;
107 point.SetState( PointState::LEAVE );
108 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
112 Dali::Integration::Point GetPointEnter()
114 Dali::Integration::Point point;
115 point.SetState( PointState::MOTION );
116 point.SetScreenPosition( INSIDE_TOUCH_POINT_POSITON );
120 Dali::Integration::Point GetPointDownOutside()
122 Dali::Integration::Point point;
123 point.SetState( PointState::DOWN );
124 point.SetScreenPosition( Vector2( 10, 10 ) );
128 Dali::Integration::Point GetPointUpOutside()
130 Dali::Integration::Point point;
131 point.SetState( PointState::UP );
132 point.SetScreenPosition( Vector2( 10, 10 ) );
136 // Set up the position of the button for the default test events
137 void SetupButtonForTestTouchEvents( ToolkitTestApplication& application, Button& button, bool useDefaultImages )
139 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
140 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
141 button.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
142 if ( useDefaultImages )
144 const Vector2 TEST_IMAGE_SIZE = Vector2( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
145 TestPlatformAbstraction& platform = application.GetPlatform();
146 platform.SetClosestImageSize( TEST_IMAGE_SIZE );
147 button.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
148 button.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
152 static std::string GetButtonText( Button button )
154 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
156 Property::Map *labelProperty = value.GetMap();
158 std::string textLabel;
162 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
163 value->Get( textLabel );
171 int UtcDaliPushButtonConstructorP(void)
173 TestApplication application;
177 DALI_TEST_CHECK( !button );
181 int UtcDaliPushButtonCopyConstructorP(void)
183 TestApplication application;
185 // Initialize an object, ref count == 1
186 PushButton button = PushButton::New();
188 PushButton copy( button );
189 DALI_TEST_CHECK( copy );
193 int UtcDaliPushButtonAssignmentOperatorP(void)
195 TestApplication application;
197 PushButton button = PushButton::New();
199 PushButton copy( button );
200 DALI_TEST_CHECK( copy );
202 DALI_TEST_CHECK( button == copy );
206 int UtcDaliPushButtonNewP(void)
208 TestApplication application;
210 PushButton button = PushButton::New();
212 DALI_TEST_CHECK( button );
216 int UtcDaliPushButtonDownCastP(void)
218 TestApplication application;
220 PushButton button = PushButton::New();
222 BaseHandle object(button);
224 PushButton button2 = PushButton::DownCast( object );
225 DALI_TEST_CHECK(button2);
227 PushButton button3 = DownCast< PushButton >(object);
228 DALI_TEST_CHECK(button3);
232 int UtcDaliPushButtonDownCastN(void)
234 TestApplication application;
236 BaseHandle unInitializedObject;
238 PushButton button1 = PushButton::DownCast( unInitializedObject );
239 DALI_TEST_CHECK( !button1 );
241 PushButton button2 = DownCast< PushButton >( unInitializedObject );
242 DALI_TEST_CHECK( !button2 );
246 int UtcDaliPushButtonAutoRepeatingProperty(void)
248 ToolkitTestApplication application;
249 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
251 PushButton pushButton = PushButton::New();
253 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
254 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
256 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), false );
257 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
259 pushButton.SetProperty( pushButton.GetPropertyIndex("autoRepeating"), true );
260 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
265 int UtcDaliPushButtonSetAutoRepeating(void)
267 ToolkitTestApplication application;
268 tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
269 tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
270 PushButton pushButton = PushButton::New();
272 const bool INITIAL_TOGGLE_VALUE = true;
273 const bool INITIAL_SELECTED_VALUE = true;
275 pushButton.SetProperty( Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
276 pushButton.SetProperty( Button::Property::SELECTED, INITIAL_SELECTED_VALUE );
278 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), INITIAL_TOGGLE_VALUE , TEST_LOCATION );
279 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), INITIAL_SELECTED_VALUE , TEST_LOCATION );
281 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
283 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), !INITIAL_TOGGLE_VALUE , TEST_LOCATION );
288 int UtcDaliPushButtonTogglableProperty(void)
290 ToolkitTestApplication application;
291 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
293 PushButton pushButton = PushButton::New();
295 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
296 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
298 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
299 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
301 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
302 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
307 int UtcDaliPushButtonAutoRepeatingPropertyAndTogglableButton(void)
309 ToolkitTestApplication application;
310 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
312 PushButton pushButton = PushButton::New();
314 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
315 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
317 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION );
318 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
320 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
321 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
323 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
324 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION );
328 int UtcDaliPushButtonSelectedProperty01(void)
330 ToolkitTestApplication application;
331 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
333 PushButton pushButton = PushButton::New();
335 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), true );
337 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
339 gPushButtonSelectedState = false;
340 pushButton.SetProperty( Button::Property::SELECTED, true );
342 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
343 DALI_TEST_CHECK( gPushButtonSelectedState );
345 pushButton.SetProperty( Button::Property::SELECTED, false );
347 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
348 DALI_TEST_CHECK( !gPushButtonSelectedState );
350 pushButton.SetProperty( Button::Property::SELECTED, true );
352 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), true , TEST_LOCATION );
353 DALI_TEST_CHECK( gPushButtonSelectedState );
357 int UtcDaliPushButtonSelectedProperty02(void)
359 ToolkitTestApplication application;
360 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
362 PushButton pushButton = PushButton::New();
364 pushButton.SetProperty( pushButton.GetPropertyIndex("togglable"), false );
365 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
367 gPushButtonSelectedState = false;
368 pushButton.SetProperty( Button::Property::SELECTED, true );
370 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
371 DALI_TEST_CHECK( !gPushButtonSelectedState );
373 pushButton.SetProperty( Button::Property::SELECTED, false );
375 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
376 DALI_TEST_CHECK( !gPushButtonSelectedState );
378 pushButton.SetProperty( Button::Property::SELECTED, true );
380 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false , TEST_LOCATION );
381 DALI_TEST_CHECK( !gPushButtonSelectedState );
385 int UtcDaliPushButtonAutorepeatingDelayPropertyValues01(void)
387 ToolkitTestApplication application;
388 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
390 PushButton pushButton = PushButton::New();
392 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
394 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f );
396 DALI_TEST_EQUALS( pushButton.GetProperty<float>(pushButton.GetPropertyIndex("initialAutoRepeatingDelay") ), 1.f, TEST_LOCATION );
401 int UtcDaliPushButtonAutorepeatingDelayPropertyValues02(void)
403 ToolkitTestApplication application;
404 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
406 PushButton pushButton = PushButton::New();
408 bool assert1( false );
409 bool assert2( false );
411 pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
415 pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f );
417 catch( Dali::DaliException& e )
419 DALI_TEST_PRINT_ASSERT( e );
420 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
426 pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f );
428 catch( Dali::DaliException& e )
430 DALI_TEST_PRINT_ASSERT( e );
431 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
435 DALI_TEST_CHECK( assert1 && assert2 );
439 int UtcDaliPushButtonLabelProperty(void)
441 ToolkitTestApplication application;
442 tet_infoline(" UtcDaliPushButtonSetLabelText");
444 const std::string STR( "Hola!" );
446 PushButton pushButton = PushButton::New();
448 application.SendNotification();
449 application.Render();
451 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
452 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
453 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
457 pushButton.SetProperty( Toolkit::Button::Property::LABEL, STR );
459 DALI_TEST_EQUALS( GetButtonText( pushButton ), STR, TEST_LOCATION );
464 int UtcDaliPushButtonPressed(void)
466 ToolkitTestApplication application;
467 tet_infoline(" UtcDaliPushButtonPressed");
469 PushButton pushButton = PushButton::New();
470 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
471 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
472 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
473 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
475 Stage::GetCurrent().Add( pushButton );
477 application.SendNotification();
478 application.Render();
480 gPushButtonPressed = false;
482 // connect to its touch signal
483 pushButton.PressedSignal().Connect( &PushButtonPressed );
485 Dali::Integration::TouchEvent eventDown;
486 eventDown.AddPoint( GetPointDownInside() );
488 // flush the queue and render once
489 application.SendNotification();
490 application.Render();
491 application.ProcessEvent( eventDown );
493 DALI_TEST_CHECK( gPushButtonPressed );
497 int UtcDaliPushButtonReleased(void)
499 ToolkitTestApplication application;
500 tet_infoline(" UtcDaliPushButtonReleased");
502 PushButton pushButton = PushButton::New();
503 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
504 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
505 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
506 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
508 Stage::GetCurrent().Add( pushButton );
510 application.SendNotification();
511 application.Render();
513 // connect to its touch signal
514 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
516 Dali::Integration::TouchEvent event;
518 // Test1. Touch point down and up inside the button.
520 gPushButtonReleased = false;
521 event = Dali::Integration::TouchEvent();
522 event.AddPoint( GetPointDownInside() );
523 application.ProcessEvent( event );
525 event = Dali::Integration::TouchEvent();
526 event.AddPoint( GetPointUpInside() );
527 application.ProcessEvent( event );
529 DALI_TEST_CHECK( gPushButtonReleased );
531 // Test2. Touch point down and up outside the button.
533 gPushButtonReleased = false;
534 event = Dali::Integration::TouchEvent();
535 event.AddPoint( GetPointDownOutside() );
536 application.ProcessEvent( event );
538 event = Dali::Integration::TouchEvent();
539 event.AddPoint( GetPointUpOutside() );
540 application.ProcessEvent( event );
542 DALI_TEST_CHECK( !gPushButtonReleased );
544 // Test3. Touch point down inside and up outside the button.
546 gPushButtonReleased = false;
547 event = Dali::Integration::TouchEvent();
548 event.AddPoint( GetPointDownInside() );
549 application.ProcessEvent( event );
551 event = Dali::Integration::TouchEvent();
552 event.AddPoint( GetPointLeave() );
553 application.ProcessEvent( event );
555 event = Dali::Integration::TouchEvent();
556 event.AddPoint( GetPointUpOutside() );
557 application.ProcessEvent( event );
559 DALI_TEST_CHECK( gPushButtonReleased );
561 // Test4. Touch point down outside and up inside the button.
563 gPushButtonReleased = false;
564 event = Dali::Integration::TouchEvent();
565 event.AddPoint( GetPointDownOutside() );
566 application.ProcessEvent( event );
568 event = Dali::Integration::TouchEvent();
569 event.AddPoint( GetPointEnter() );
570 application.ProcessEvent( event );
572 event = Dali::Integration::TouchEvent();
573 event.AddPoint( GetPointUpInside() );
574 application.ProcessEvent( event );
576 DALI_TEST_CHECK( !gPushButtonReleased );
580 int UtcDaliPushButtonSelected(void)
582 ToolkitTestApplication application;
583 tet_infoline(" UtcDaliPushButtonSelected");
585 PushButton pushButton = PushButton::New();
586 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
587 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
588 pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
589 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
591 Stage::GetCurrent().Add( pushButton );
593 application.SendNotification();
594 application.Render();
596 // connect to its touch signal
597 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
599 Dali::Integration::TouchEvent event;
601 // Test1. No togglable button.
603 gPushButtonSelectedState = false;
604 event = Dali::Integration::TouchEvent();
605 event.AddPoint( GetPointDownInside() );
606 application.ProcessEvent( event );
608 event = Dali::Integration::TouchEvent();
609 event.AddPoint( GetPointUpInside() );
610 application.ProcessEvent( event );
612 DALI_TEST_CHECK( !gPushButtonSelectedState );
614 // Set togglable property.
615 pushButton.SetProperty( Button::Property::TOGGLABLE, true );
617 // Test2. Touch point down and up inside the button twice.
618 gPushButtonSelectedState = false;
619 event = Dali::Integration::TouchEvent();
620 event.AddPoint( GetPointDownInside() );
621 application.ProcessEvent( event );
623 event = Dali::Integration::TouchEvent();
624 event.AddPoint( GetPointUpInside() );
625 application.ProcessEvent( event );
627 DALI_TEST_CHECK( gPushButtonSelectedState );
629 event = Dali::Integration::TouchEvent();
630 event.AddPoint( GetPointDownInside() );
631 application.ProcessEvent( event );
633 event = Dali::Integration::TouchEvent();
634 event.AddPoint( GetPointUpInside() );
635 application.ProcessEvent( event );
637 DALI_TEST_CHECK( !gPushButtonSelectedState );
639 // Test3. Touch point down and up outside the button.
641 gPushButtonSelectedState = false;
642 event = Dali::Integration::TouchEvent();
643 event.AddPoint( GetPointDownOutside() );
644 application.ProcessEvent( event );
646 event = Dali::Integration::TouchEvent();
647 event.AddPoint( GetPointUpOutside() );
648 application.ProcessEvent( event );
650 DALI_TEST_CHECK( !gPushButtonSelectedState );
652 // Test4. Touch point down inside and up outside the button.
653 // State changes on Button down
654 gPushButtonSelectedState = false;
655 event = Dali::Integration::TouchEvent();
656 event.AddPoint( GetPointDownInside() );
657 application.ProcessEvent( event );
659 event = Dali::Integration::TouchEvent();
660 event.AddPoint( GetPointLeave() );
661 application.ProcessEvent( event );
663 event = Dali::Integration::TouchEvent();
664 event.AddPoint( GetPointUpOutside() );
665 application.ProcessEvent( event );
667 DALI_TEST_CHECK( gPushButtonSelectedState );
669 // Test5. Touch point down outside and up inside the button.
670 // Start in unselected state
671 pushButton.SetProperty( Button::Property::SELECTED, false );
673 DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("selected") ),false , TEST_LOCATION );
675 gPushButtonSelectedState = false;
676 event = Dali::Integration::TouchEvent();
677 event.AddPoint( GetPointDownOutside() );
678 application.ProcessEvent( event );
680 event = Dali::Integration::TouchEvent();
681 event.AddPoint( GetPointEnter() );
682 application.ProcessEvent( event );
684 event = Dali::Integration::TouchEvent();
685 event.AddPoint( GetPointUpInside() );
686 application.ProcessEvent( event );
688 DALI_TEST_CHECK( !gPushButtonSelectedState );
692 int UtcDaliPushButtonPropertySetIconAlignment(void)
694 ToolkitTestApplication application;
695 tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
697 PushButton pushButton = PushButton::New();
698 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
699 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
701 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
702 DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
707 int UtcDaliPushButtonPropertySetLabelPadding(void)
709 ToolkitTestApplication application;
710 tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
712 PushButton pushButton = PushButton::New();
713 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
714 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 );
716 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
717 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 );
722 int UtcDaliPushButtonPropertySetIconPadding(void)
724 ToolkitTestApplication application;
725 tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
727 PushButton pushButton = PushButton::New();
728 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
729 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 );
731 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
732 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 );
737 int UtcDaliPushButtonPaddingLayout(void)
739 ToolkitTestApplication application;
740 tet_infoline(" UtcDaliPushButtonPaddingLayout");
742 // This test creates padding for an icon and a label.
743 // The icon and label are each enabled and disabled to confirm the correct padding is used.
744 PushButton pushButton = PushButton::New();
746 const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
747 const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
749 // Get actual size of test image
750 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
751 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
753 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
754 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
755 pushButton.SetPosition( 0.0f, 0.0f );
756 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
758 Stage::GetCurrent().Add( pushButton );
760 application.SendNotification();
761 application.Render();
763 // First test the size is zero.
764 // No padding should be added as there is no label or icon.
765 Vector2 size( Vector2::ZERO );
766 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
767 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
768 tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
770 DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
772 // Check label only padding
773 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
775 application.SendNotification();
776 application.Render();
778 Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
779 sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
780 sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
782 tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
784 // Add label padding to label
785 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
786 application.SendNotification();
787 application.Render();
789 Vector2 sizeLabelAndPadding( Vector2::ZERO );
790 sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
791 sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
792 tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
794 // If control size has increased beyond size of just label then padding has been applied
795 DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
796 DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
798 // Re-initialise the button so we can setup icon-only padding.
799 pushButton.Unparent();
800 pushButton = PushButton::New();
802 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
803 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
804 pushButton.SetPosition( 0.0f, 0.0f );
805 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
807 Stage::GetCurrent().Add( pushButton );
810 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
811 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
812 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
814 application.SendNotification();
815 application.Render();
817 // Size of button with just icon
818 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
819 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
820 tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
822 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
824 application.SendNotification();
825 application.Render();
826 DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
828 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
829 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
830 tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
831 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 );
832 DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
834 // Now test padding for both label and icon simultaneously.
835 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
837 application.SendNotification();
838 application.Render();
840 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
841 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
842 tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
844 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
846 application.SendNotification();
847 application.Render();
849 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
850 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
851 tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
853 DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
854 // Test height of control is same as icon and padding, as Text is smaller than icon
855 DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
860 int UtcDaliPushButtonAlignmentLayout(void)
862 ToolkitTestApplication application;
863 tet_infoline(" UtcDaliPushButtonAlignmentLayout");
866 * This test checks different alignments for the icon against the label.
867 * The icon is then moved around the label in each of it's alignments.
868 * The final relayed out size is checked to confirm the layout has been done correctly.
870 * There is an Icon which has 0 width and height, but with 75 padding on all sides.
871 * - Therefore total width and height are both 150.
873 * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
874 * - Therefore total width and height are 60+x and 60+y respectively.
875 * Where x & y are the width and height of the text.
877 * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
878 * So We use the padding to help us determine the orientation is correct for each alignment.
880 * |<- 150 ->| |<-- 60+x -->|
883 * | | ^ +------------+ -
885 * | Icon | 150 | Label | 60+y
887 * | | v +------------+ -
891 const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
892 const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
894 // Get actual size of test image
895 ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
896 const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
898 PushButton pushButton = PushButton::New();
900 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
901 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
902 pushButton.SetPosition( 0.0f, 0.0f );
903 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
905 Stage::GetCurrent().Add( pushButton );
907 // Add a label and get size of control
908 pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
909 application.SendNotification();
910 application.Render();
912 // First get the size of control with just label
913 Vector2 justLabelSize( Vector2::ZERO );
914 justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
915 justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
916 tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
918 pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
919 application.SendNotification();
920 application.Render();
922 // Size of Label and Padding
923 Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
924 expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
925 expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
927 Vector2 labelAndPaddingSize( Vector2::ZERO );
928 labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
929 labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
931 DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
933 const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
934 ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
936 // Add Icon and set its alignment
937 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
938 pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
939 pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
940 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
942 application.SendNotification();
943 application.Render();
945 Vector2 size( Vector2::ZERO );
946 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
947 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
950 * Test Icon right alignment.
951 * Height grows to largest of Icon or Label (+ padding).
952 * Normally this will be Icons height, except with very large font sizes.
954 * +------------+---------+
960 * +------------+---------+
962 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
963 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
965 // Now test left alignment matches right for size.
966 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
968 application.SendNotification();
969 application.Render();
971 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
972 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
975 * Test Icon left alignment.
976 * Height grows to largest of Icon or Label (+ padding).
977 * Normally this will be Icons height, except with very large font sizes.
979 * +---------+------------+
985 * +---------+------------+
987 DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
988 DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
990 tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
1007 tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
1008 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
1010 application.SendNotification();
1011 application.Render();
1013 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1014 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1016 tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
1017 tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
1019 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
1020 tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
1022 DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
1024 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1027 * Test Icon bottom alignment.
1028 * Width grows to largest of Icon or Label (+ padding).
1042 tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1043 pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
1045 application.SendNotification();
1046 application.Render();
1048 size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1049 size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1051 DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1052 DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1057 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1059 tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1060 ToolkitTestApplication application;
1062 PushButton pushButton = PushButton::New();
1063 pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
1065 Stage::GetCurrent().Add( pushButton );
1067 Property::Map propertyMap;
1068 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1069 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1071 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1073 tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1075 application.SendNotification();
1076 application.Render(0);
1078 unsigned int rendererCount = pushButton.GetRendererCount();
1079 tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1081 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1083 tet_printf("Remove button from stage\n" );
1085 Stage::GetCurrent().Remove( pushButton );
1087 rendererCount = pushButton.GetRendererCount();
1088 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1090 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1092 tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1094 Property::Map propertyMap2;
1095 propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1096 propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1097 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap2 );
1099 tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1101 Stage::GetCurrent().Add( pushButton );
1103 tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1105 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1110 int UtcDaliPushButtonSetSelectedVisualN(void)
1112 tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1114 ToolkitTestApplication application;
1116 PushButton pushButton = PushButton::New();
1118 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1119 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1120 pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1122 Stage::GetCurrent().Add( pushButton );
1123 application.SendNotification();
1124 application.Render(0);
1126 unsigned int preRendererCount = pushButton.GetRendererCount();
1127 tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1128 DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1130 Stage::GetCurrent().Remove( pushButton );
1131 application.SendNotification();
1132 application.Render(0);
1134 Property::Map colorMap;
1135 const int BROKEN_VISUAL_TYPE = 999999999;
1137 colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1138 colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1139 colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1140 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, colorMap );
1142 Stage::GetCurrent().Add( pushButton );
1143 application.SendNotification();
1144 application.Render(0);
1146 unsigned int postRendererCount = pushButton.GetRendererCount();
1147 tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1148 DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1153 int UtcDaliPushButtonSetButtonImageP(void)
1155 ToolkitTestApplication application;
1157 PushButton button = PushButton::New();
1158 Stage::GetCurrent().Add( button );
1162 button.SetButtonImage( ImageView::New() );
1163 DALI_TEST_CHECK( true );
1167 DALI_TEST_CHECK( false );
1173 int UtcDaliPushButtonSetBackgroundImageP(void)
1175 ToolkitTestApplication application;
1177 PushButton button = PushButton::New();
1178 Stage::GetCurrent().Add( button );
1182 button.SetBackgroundImage( ImageView::New() );
1183 DALI_TEST_CHECK( true );
1187 DALI_TEST_CHECK( false );
1193 int UtcDaliPushButtonSetSelectedImageP(void)
1195 ToolkitTestApplication application;
1197 PushButton button = PushButton::New();
1198 Stage::GetCurrent().Add( button );
1202 button.SetSelectedImage( ImageView::New() );
1203 DALI_TEST_CHECK( true );
1207 DALI_TEST_CHECK( false );
1213 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1215 ToolkitTestApplication application;
1217 PushButton button = PushButton::New();
1218 Stage::GetCurrent().Add( button );
1222 button.SetSelectedBackgroundImage( ImageView::New() );
1223 DALI_TEST_CHECK( true );
1227 DALI_TEST_CHECK( false );
1233 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1235 ToolkitTestApplication application;
1237 PushButton button = PushButton::New();
1238 Stage::GetCurrent().Add( button );
1242 button.SetDisabledBackgroundImage( ImageView::New() );
1243 DALI_TEST_CHECK( true );
1247 DALI_TEST_CHECK( false );
1254 int UtcDaliPushButtonSetDisabledImageP(void)
1256 ToolkitTestApplication application;
1258 PushButton button = PushButton::New();
1259 Stage::GetCurrent().Add( button );
1263 button.SetDisabledImage( ImageView::New() );
1264 DALI_TEST_CHECK( true );
1268 DALI_TEST_CHECK( false );
1274 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1276 ToolkitTestApplication application;
1278 PushButton button = PushButton::New();
1279 Stage::GetCurrent().Add( button );
1283 button.SetDisabledSelectedImage( ImageView::New() );
1284 DALI_TEST_CHECK( true );
1288 DALI_TEST_CHECK( false );
1294 int UtcDaliPushButtonToggleSignalP(void)
1296 ToolkitTestApplication application;
1297 tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1299 PushButton button = PushButton::New();
1300 button.SetProperty( Button::Property::TOGGLABLE, true);
1302 SetupButtonForTestTouchEvents( application, button, true );
1304 Stage::GetCurrent().Add( button );
1306 application.SendNotification();
1307 application.Render();
1309 // connect to its signal
1310 button.ClickedSignal().Connect( &PushButtonClicked );
1311 gPushButtonClicked = false;
1313 tet_infoline(" Touch down and up within button");
1314 Dali::Integration::TouchEvent event;
1315 event = Dali::Integration::TouchEvent();
1316 event.AddPoint( GetPointDownInside() );
1317 application.ProcessEvent( event );
1319 event = Dali::Integration::TouchEvent();
1320 event.AddPoint( GetPointUpInside() );
1321 application.ProcessEvent( event );
1323 DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION );
1328 // Deprecated API Tests
1330 int UtcDaliPushButtonSetGetAutoRepeating(void)
1332 ToolkitTestApplication application;
1333 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
1335 PushButton pushButton = PushButton::New();
1337 pushButton.SetAutoRepeating( true );
1339 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1341 pushButton.SetAutoRepeating( false );
1343 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1345 pushButton.SetAutoRepeating( true );
1347 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1351 int UtcDaliPushButtonSetGetTogglableButton(void)
1353 ToolkitTestApplication application;
1354 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
1356 PushButton pushButton = PushButton::New();
1358 pushButton.SetTogglableButton( true );
1360 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1362 pushButton.SetTogglableButton( false );
1364 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1366 pushButton.SetTogglableButton( true );
1368 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1372 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
1374 ToolkitTestApplication application;
1375 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
1377 PushButton pushButton = PushButton::New();
1379 pushButton.SetAutoRepeating( true );
1380 pushButton.SetTogglableButton( true );
1382 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1383 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1385 pushButton.SetTogglableButton( true );
1386 pushButton.SetAutoRepeating( true );
1388 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1389 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1393 int UtcDaliPushButtonSetGetSelected01(void)
1395 ToolkitTestApplication application;
1396 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
1398 PushButton pushButton = PushButton::New();
1400 pushButton.SetTogglableButton( true );
1401 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1403 gPushButtonSelectedState = false;
1404 pushButton.SetSelected( true );
1406 DALI_TEST_CHECK( pushButton.IsSelected() );
1407 DALI_TEST_CHECK( gPushButtonSelectedState );
1409 pushButton.SetSelected( false );
1411 DALI_TEST_CHECK( !pushButton.IsSelected() );
1412 DALI_TEST_CHECK( !gPushButtonSelectedState );
1414 pushButton.SetSelected( true );
1416 DALI_TEST_CHECK( pushButton.IsSelected() );
1417 DALI_TEST_CHECK( gPushButtonSelectedState );
1421 int UtcDaliPushButtonSetGetSelected02(void)
1423 ToolkitTestApplication application;
1424 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
1426 PushButton pushButton = PushButton::New();
1428 pushButton.SetTogglableButton( false );
1429 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1431 gPushButtonSelectedState = false;
1432 pushButton.SetSelected( true );
1434 DALI_TEST_CHECK( !pushButton.IsSelected() );
1435 DALI_TEST_CHECK( !gPushButtonSelectedState );
1437 pushButton.SetSelected( false );
1439 DALI_TEST_CHECK( !pushButton.IsSelected() );
1440 DALI_TEST_CHECK( !gPushButtonSelectedState );
1442 pushButton.SetSelected( true );
1444 DALI_TEST_CHECK( !pushButton.IsSelected() );
1445 DALI_TEST_CHECK( !gPushButtonSelectedState );
1449 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
1451 ToolkitTestApplication application;
1452 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
1454 PushButton pushButton = PushButton::New();
1456 pushButton.SetAutoRepeating( true );
1458 pushButton.SetInitialAutoRepeatingDelay( 1.f );
1459 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1461 pushButton.SetNextAutoRepeatingDelay( 1.f );
1462 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1466 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
1468 ToolkitTestApplication application;
1469 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
1471 PushButton pushButton = PushButton::New();
1473 bool assert1( false );
1474 bool assert2( false );
1476 pushButton.SetAutoRepeating( true );
1480 pushButton.SetInitialAutoRepeatingDelay( -1.f );
1482 catch( Dali::DaliException& e )
1484 DALI_TEST_PRINT_ASSERT( e );
1485 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
1491 pushButton.SetNextAutoRepeatingDelay( -1.f );
1493 catch( Dali::DaliException& e )
1495 DALI_TEST_PRINT_ASSERT( e );
1496 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
1500 DALI_TEST_CHECK( assert1 && assert2 );
1504 int UtcDaliPushButtonSetLabelText(void)
1506 ToolkitTestApplication application;
1507 tet_infoline(" UtcDaliPushButtonSetLabelText");
1509 const std::string STR( "Hola!" );
1511 PushButton pushButton = PushButton::New();
1513 pushButton.SetProperty( Toolkit::Button::Property::LABEL,
1514 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
1515 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1518 application.SendNotification();
1519 application.Render();
1521 pushButton.SetLabelText( STR );
1523 DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
1528 int UtcDaliPushButtonSetButtonImageDeprecatedP(void)
1530 ToolkitTestApplication application;
1531 Image setButtonImage = ResourceImage::New( TEST_IMAGE_ONE);
1532 PushButton pushButton = PushButton::New();
1533 pushButton.SetButtonImage( setButtonImage );
1534 Image retreivedButtonImage = ImageView::DownCast(pushButton.GetButtonImage()).GetImage();
1535 DALI_TEST_EQUALS( retreivedButtonImage, setButtonImage , TEST_LOCATION );
1540 int UtcDaliPushButtonSetSelectedImageDeprecatedP(void)
1542 ToolkitTestApplication application;
1543 Image setButtonImage = ResourceImage::New( TEST_IMAGE_ONE);
1544 PushButton pushButton = PushButton::New();
1545 pushButton.SetSelectedImage( setButtonImage );
1546 Image retreivedButtonImage = ImageView::DownCast(pushButton.GetSelectedImage()).GetImage();
1547 DALI_TEST_EQUALS( retreivedButtonImage, setButtonImage , TEST_LOCATION );
1552 int UtcDaliPushButtonGetButtonImageURLDeprecatedP(void)
1554 tet_infoline(" UtcDaliPushButtonGetButtonImageURLDeprecatedP Testing mix use of API");
1556 ToolkitTestApplication application;
1558 PushButton pushButton = PushButton::New();
1559 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
1561 ImageView retreivedButtonImageView = ImageView::DownCast(pushButton.GetButtonImage());
1562 Image retreivedButtonImage = retreivedButtonImageView.GetImage();
1563 ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
1565 DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_ONE , TEST_LOCATION );
1570 int UtcDaliPushButtonGetSelectedImageURLDeprecatedP(void)
1572 tet_infoline(" UtcDaliPushButtonGetSelectedImageURLDeprecatedP Testing mix use of API");
1574 ToolkitTestApplication application;
1576 PushButton pushButton = PushButton::New();
1578 pushButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
1580 Image retreivedButtonImage = ImageView::DownCast(pushButton.GetSelectedImage()).GetImage();
1581 ResourceImage resourceImage = ResourceImage::DownCast( retreivedButtonImage );
1582 DALI_TEST_EQUALS( resourceImage.GetUrl(), TEST_IMAGE_ONE , TEST_LOCATION );
1587 int UtcDaliPushButtonSetSelectedImageWithActorDeprecatedP(void)
1589 tet_infoline(" UtcDaliPushButton SetSelectedImage With ImageView (Actor)");
1591 ToolkitTestApplication application;
1593 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1595 DALI_TEST_CHECK( image );
1597 ImageView imgViewSet = ImageView::New(image);
1599 DALI_TEST_CHECK(imgViewSet );
1601 PushButton pushButton = PushButton::New();
1603 DALI_TEST_CHECK( pushButton );
1605 pushButton.SetSelectedImage( imgViewSet );
1607 ImageView imageView = ImageView::DownCast( pushButton.GetSelectedImage());
1609 DALI_TEST_CHECK( imageView );
1611 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1614 DALI_TEST_CHECK( !map.Empty() );
1615 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1620 int UtcDaliPushButtonSetButtonImageWithActorDeprecatedP(void)
1622 tet_infoline(" UtcDaliPushButton SetButtonImage With ImageView (Actor)");
1624 ToolkitTestApplication application;
1626 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1628 DALI_TEST_CHECK( image );
1630 ImageView imgViewSet = ImageView::New(image);
1632 DALI_TEST_CHECK(imgViewSet );
1634 PushButton pushButton = PushButton::New();
1636 DALI_TEST_CHECK( pushButton );
1638 pushButton.SetButtonImage( imgViewSet );
1640 ImageView imageView = ImageView::DownCast( pushButton.GetButtonImage());
1642 DALI_TEST_CHECK( imageView );
1644 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1647 DALI_TEST_CHECK( !map.Empty() );
1648 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1653 int UtcDaliPushButtonSetBackgroundImageWithActorDeprecatedP(void)
1655 tet_infoline(" UtcDaliPushButton SetBackgroundImage With ImageView (Actor)");
1657 ToolkitTestApplication application;
1659 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1661 DALI_TEST_CHECK( image );
1663 ImageView imgViewSet = ImageView::New(image);
1665 DALI_TEST_CHECK(imgViewSet );
1667 PushButton pushButton = PushButton::New();
1669 DALI_TEST_CHECK( pushButton );
1671 pushButton.SetBackgroundImage( imgViewSet );
1673 ImageView imageView = ImageView::DownCast( pushButton.GetButtonImage());
1675 DALI_TEST_CHECK( imageView );
1677 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1680 DALI_TEST_CHECK( !map.Empty() );
1681 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1687 int UtcDaliPushButtonSetSelectedBackgroundImageWithActorDeprecatedP(void)
1689 tet_infoline(" UtcDaliPushButton SetSelectedBackgroundImage With ImageView (Actor)");
1691 ToolkitTestApplication application;
1693 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1695 DALI_TEST_CHECK( image );
1697 ImageView imgViewSet = ImageView::New(image);
1699 DALI_TEST_CHECK(imgViewSet );
1701 PushButton pushButton = PushButton::New();
1703 DALI_TEST_CHECK( pushButton );
1705 pushButton.SetSelectedBackgroundImage( imgViewSet );
1707 ImageView imageView = ImageView::DownCast( pushButton.GetSelectedImage());
1709 DALI_TEST_CHECK( imageView );
1711 Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
1714 DALI_TEST_CHECK( !map.Empty() );
1715 DALI_TEST_EQUALS( map[ "filename" ].Get<std::string>(), TEST_IMAGE_ONE , TEST_LOCATION );
1720 int UtcDaliPushButtonSetDisabledBackgroundImageWithActorDeprecatedP(void)
1722 tet_infoline(" UtcDaliPushButton SetDisabledBackgroundImage With ImageView (Actor)");
1724 ToolkitTestApplication application;
1726 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1728 DALI_TEST_CHECK( image );
1730 ImageView imgViewSet = ImageView::New(image);
1732 DALI_TEST_CHECK(imgViewSet );
1734 PushButton pushButton = PushButton::New();
1736 DALI_TEST_CHECK( pushButton );
1738 pushButton.SetDisabledBackgroundImage( imgViewSet );
1740 Property::Value value = pushButton.GetProperty( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL );
1744 Property::Value* urlValue = map.Find( ImageVisual::Property::URL );
1746 std::string urlString;
1747 urlValue->Get( urlString );
1748 DALI_TEST_EQUALS( urlString , TEST_IMAGE_ONE , TEST_LOCATION );
1753 int UtcDaliPushButtonSetDisabledImageWithActorDeprecatedP(void)
1755 tet_infoline(" UtcDaliPushButton SetDisabledImage With ImageView (Actor)");
1757 ToolkitTestApplication application;
1759 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1761 DALI_TEST_CHECK( image );
1763 ImageView imgViewSet = ImageView::New(image);
1765 DALI_TEST_CHECK(imgViewSet );
1767 PushButton pushButton = PushButton::New();
1769 DALI_TEST_CHECK( pushButton );
1771 pushButton.SetDisabledImage( imgViewSet );
1773 Property::Value value = pushButton.GetProperty( Toolkit::DevelButton::Property::DISABLED_UNSELECTED_BACKGROUND_VISUAL );
1778 Property::Value* urlValue = map.Find( ImageVisual::Property::URL );
1780 std::string urlString;
1781 urlValue->Get( urlString );
1782 DALI_TEST_EQUALS( urlString , TEST_IMAGE_ONE , TEST_LOCATION );
1787 int UtcDaliPushButtonSetDisabledSelectedImageWithActorDeprecatedP(void)
1789 tet_infoline(" UtcDaliPushButton SetDisabledSelectedImage With ImageView (Actor)");
1791 ToolkitTestApplication application;
1793 Image image = ResourceImage::New( TEST_IMAGE_ONE );
1795 DALI_TEST_CHECK( image );
1797 ImageView imgViewSet = ImageView::New(image);
1799 DALI_TEST_CHECK(imgViewSet );
1801 PushButton pushButton = PushButton::New();
1803 DALI_TEST_CHECK( pushButton );
1805 pushButton.SetDisabledSelectedImage( imgViewSet );
1807 Property::Value value = pushButton.GetProperty( Toolkit::DevelButton::Property::DISABLED_SELECTED_BACKGROUND_VISUAL );
1812 Property::Value* urlValue = map.Find( ImageVisual::Property::URL );
1814 std::string urlString;
1815 urlValue->Get( urlString );
1816 DALI_TEST_EQUALS( urlString , TEST_IMAGE_ONE , TEST_LOCATION );
1821 int UtcDaliPushButtonReplaceButtonImageP2(void)
1823 tet_infoline("Set button image then replace with new image and query url");
1825 ToolkitTestApplication application;
1827 ResourceImage setImage = ResourceImage::New( TEST_IMAGE_ONE );
1828 DALI_TEST_CHECK(setImage);
1830 Actor imgActorSet = ImageView::New(setImage);
1831 DALI_TEST_CHECK(imgActorSet);
1833 PushButton pushButton = PushButton::New();
1834 pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_TWO );
1837 Stage::GetCurrent().Add( pushButton );
1839 pushButton.SetButtonImage( imgActorSet );
1840 application.SendNotification();
1841 application.Render();
1843 tet_infoline("Get button image before it has been able to load");
1845 ImageView imageView = ImageView::DownCast(pushButton.GetButtonImage());
1847 ResourceImage getImage = ResourceImage::DownCast( imageView.GetImage() );
1849 tet_infoline("Check if url matches last assignment even if not loaded yet");
1850 DALI_TEST_EQUALS( getImage.GetUrl(), setImage.GetUrl() , TEST_LOCATION );