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>
24 #include "dali-toolkit-test-utils/toolkit-timer.h"
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali/integration-api/events/touch-event-integ.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
34 using namespace Toolkit;
37 void utc_dali_toolkit_button_startup(void)
39 test_return_value = TET_UNDEF;
42 void utc_dali_toolkit_button_cleanup(void)
44 test_return_value = TET_PASS;
49 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
51 static bool gIsCalledButtonCallback = false;
53 const int RENDER_FRAME_INTERVAL = 16;
55 static bool ButtonCallback( Button button )
57 gIsCalledButtonCallback = true;
61 struct CallbackFunctor
63 CallbackFunctor(bool* callbackFlag)
64 : mCallbackFlag( callbackFlag )
70 *mCallbackFlag = true;
75 Dali::Integration::Point GetPointDownInside()
77 Dali::Integration::Point point;
78 point.SetState( PointState::DOWN );
79 point.SetScreenPosition( Vector2( 240, 400 ) );
83 Dali::Integration::Point GetPointUpInside()
85 Dali::Integration::Point point;
86 point.SetState( PointState::UP );
87 point.SetScreenPosition( Vector2( 240, 400 ) );
91 Dali::Integration::Point GetPointLeave()
93 Dali::Integration::Point point;
94 point.SetState( PointState::LEAVE );
95 point.SetScreenPosition( Vector2( 240, 400 ) );
99 Dali::Integration::Point GetPointEnter()
101 Dali::Integration::Point point;
102 point.SetState( PointState::MOTION );
103 point.SetScreenPosition( Vector2( 240, 400 ) );
107 Dali::Integration::Point GetPointDownOutside()
109 Dali::Integration::Point point;
110 point.SetState( PointState::DOWN );
111 point.SetScreenPosition( Vector2( 10, 10 ) );
115 Dali::Integration::Point GetPointUpOutside()
117 Dali::Integration::Point point;
118 point.SetState( PointState::UP );
119 point.SetScreenPosition( Vector2( 10, 10 ) );
123 static float ANIMATION_TIME( 0.5f );
127 int UtcDaliButtonConstructorP(void)
129 TestApplication application;
133 DALI_TEST_CHECK( !button );
137 int UtcDaliButtonCopyConstructorP(void)
139 TestApplication application;
141 // Initialize an object, ref count == 1
142 Button button = PushButton::New();
144 Button copy( button );
145 DALI_TEST_CHECK( copy );
149 int UtcDaliButtonAssignmentOperatorP(void)
151 TestApplication application;
153 Button button = PushButton::New();
155 Button copy( button );
156 DALI_TEST_CHECK( copy );
158 DALI_TEST_CHECK( button == copy );
162 int UtcDaliButtonDownCastP(void)
164 TestApplication application;
166 Button button = PushButton::New();
168 BaseHandle object(button);
170 Button button2 = Button::DownCast( object );
171 DALI_TEST_CHECK(button2);
173 Button button3 = DownCast< Button >(object);
174 DALI_TEST_CHECK(button3);
178 int UtcDaliButtonDownCastN(void)
180 TestApplication application;
182 BaseHandle unInitializedObject;
184 Button button1 = Button::DownCast( unInitializedObject );
185 DALI_TEST_CHECK( !button1 );
187 Button button2 = DownCast< Button >( unInitializedObject );
188 DALI_TEST_CHECK( !button2 );
192 int UtcDaliButtonSetDisabledP(void)
194 ToolkitTestApplication application;
196 Button button = PushButton::New();
198 button.SetDisabled( true );
200 DALI_TEST_CHECK( button.IsDisabled() );
202 button.SetDisabled( false );
204 DALI_TEST_CHECK( !button.IsDisabled() );
206 button.SetDisabled( true );
208 DALI_TEST_CHECK( button.IsDisabled() );
210 button.SetDisabled( false );
212 DALI_TEST_CHECK( !button.IsDisabled() );
216 int UtcDaliButtonSetDisabledWithDifferentStates01P(void)
218 ToolkitTestApplication application;
220 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n");
222 Button button = PushButton::New();
224 bool SELECTED = true;
226 button.SetProperty( Button::Property::TOGGLABLE, true);
227 button.SetProperty( Button::Property::SELECTED, SELECTED );
229 button.SetProperty( Button::Property::DISABLED, true);
231 tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n");
232 button.SetProperty( Button::Property::SELECTED, !SELECTED );
234 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
236 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
241 int UtcDaliButtonSetDisabledWithDifferentStates02P(void)
243 ToolkitTestApplication application;
245 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n");
247 Button button = PushButton::New();
249 bool SELECTED = true;
251 button.SetProperty( Button::Property::TOGGLABLE, true );
252 button.SetProperty( Button::Property::SELECTED, SELECTED );
253 button.SetProperty( Button::Property::DISABLED, true );
255 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
256 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
257 tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n");
259 button.SetProperty( Button::Property::DISABLED, false );
260 button.SetProperty( Button::Property::SELECTED, !SELECTED );
262 isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
263 DALI_TEST_EQUALS( isSelected, !SELECTED , TEST_LOCATION );
268 int UtcDaliButtonPropertyGetLabelAlignment(void)
270 ToolkitTestApplication application;
271 tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
273 Button button = PushButton::New();
274 button.SetProperty( Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT, "END" );
275 DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::Button::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
280 int UtcDaliButtonIsDisabledP(void)
282 ToolkitTestApplication application;
284 Button button = PushButton::New();
286 button.SetDisabled( true );
288 DALI_TEST_CHECK( button.IsDisabled() );
290 button.SetDisabled( false );
292 DALI_TEST_CHECK( !button.IsDisabled() );
296 int UtcDaliButtonSetAutoRepeatingP(void)
298 ToolkitTestApplication application;
300 Button button = PushButton::New();
302 button.SetAutoRepeating( true );
304 DALI_TEST_CHECK( button.IsAutoRepeating() );
306 button.SetAutoRepeating( false );
308 DALI_TEST_CHECK( !button.IsAutoRepeating() );
310 button.SetAutoRepeating( true );
312 DALI_TEST_CHECK( button.IsAutoRepeating() );
314 button.SetAutoRepeating( false );
316 DALI_TEST_CHECK( !button.IsAutoRepeating() );
320 int UtcDaliButtonIsAutoRepeatingP(void)
322 ToolkitTestApplication application;
324 Button button = PushButton::New();
326 button.SetAutoRepeating( true );
328 DALI_TEST_CHECK( button.IsAutoRepeating() );
330 button.SetAutoRepeating( false );
332 DALI_TEST_CHECK( !button.IsAutoRepeating() );
336 int UtcDaliButtonAutoRepeatingP(void)
338 ToolkitTestApplication application;
339 tet_infoline(" UtcDaliButtonPressedSignalP Setup Autorepeating and check multiple clicked signals received\n");
341 const float AUTO_REPEATING_DELAY = 0.15f;
343 Button button = PushButton::New();
344 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
345 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
346 button.SetPosition( 240, 400 );
347 button.SetSize( 100, 100 );
348 Stage::GetCurrent().Add( button );
350 application.SendNotification();
351 application.Render();
353 button.SetProperty( Toolkit::Button::Property::AUTO_REPEATING, true );
354 button.SetProperty( Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY );
355 // connect to its touch signal
356 ConnectionTracker* testTracker = new ConnectionTracker();
357 button.PressedSignal().Connect( &ButtonCallback );
358 button.ClickedSignal().Connect( &ButtonCallback );
359 bool clickedSignal = false;
360 bool pressedSignal = false;
361 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
362 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
364 Dali::Integration::TouchEvent event;
366 // Touch point down and up inside the button.
368 gIsCalledButtonCallback = false;
369 event = Dali::Integration::TouchEvent();
370 event.AddPoint( GetPointDownInside() );
371 application.ProcessEvent( event );
373 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
374 DALI_TEST_EQUALS( pressedSignal, true, TEST_LOCATION );
375 tet_infoline("Consume first clicked signal then wait\n");
377 gIsCalledButtonCallback = false;
378 Dali::Timer timer = Timer::New( AUTO_REPEATING_DELAY );
379 timer.MockEmitSignal();
380 application.Wait( AUTO_REPEATING_DELAY*2 );
381 DALI_TEST_EQUALS( clickedSignal, true, TEST_LOCATION );
382 tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n");
384 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
386 gIsCalledButtonCallback = false;
387 event = Dali::Integration::TouchEvent();
388 event.AddPoint( GetPointUpInside() );
389 application.ProcessEvent( event );
391 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
396 int UtcDaliButtonSetInitialAutoRepeatingDelayP(void)
398 ToolkitTestApplication application;
400 Button button = PushButton::New();
402 button.SetInitialAutoRepeatingDelay( 0.5f );
404 DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
406 button.SetInitialAutoRepeatingDelay( 0.2f );
408 DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
412 int UtcDaliButtonSetNextAutoRepeatingDelayP(void)
414 ToolkitTestApplication application;
416 Button button = PushButton::New();
418 button.SetNextAutoRepeatingDelay( 0.5f );
420 DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
422 button.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 0.2f );
424 DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
428 int UtcDaliButtonSetTogglableButtonP(void)
430 ToolkitTestApplication application;
432 Button button = PushButton::New();
434 button.SetTogglableButton( true );
436 DALI_TEST_CHECK( button.IsTogglableButton() );
438 button.SetTogglableButton( false );
440 DALI_TEST_CHECK( !button.IsTogglableButton() );
444 int UtcDaliButtonSetSelectedP(void)
446 ToolkitTestApplication application;
448 Button button = PushButton::New();
449 button.SetTogglableButton( true );
451 button.SetSelected( true );
453 DALI_TEST_CHECK( button.IsSelected() );
455 button.SetSelected( false );
457 DALI_TEST_CHECK( !button.IsSelected() );
461 int UtcDaliButtonSetAnimationTimeP(void)
463 ToolkitTestApplication application;
464 tet_infoline(" UtcDaliButtonSetAnimationTimeP");
466 Button button = PushButton::New();
468 button.SetAnimationTime( ANIMATION_TIME );
470 DALI_TEST_EQUALS( button.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
474 int UtcDaliButtonSetLabelStringP(void)
476 ToolkitTestApplication application;
478 Button button = PushButton::New();
479 button.SetProperty( Toolkit::Button::Property::LABEL,
480 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
481 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
484 button.SetLabelText( "Button Label" );
486 DALI_TEST_EQUALS( button.GetLabelText(), "Button Label", TEST_LOCATION );
490 int UtcDaliButtonSetLabelPropertyP(void)
492 ToolkitTestApplication application;
494 const std::string TEST_LABEL1 = "test label one";
495 const std::string TEST_LABEL2 = "test label two";
497 Button button = PushButton::New();
499 button.SetProperty( Toolkit::Button::Property::LABEL,
500 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
501 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
504 button.SetProperty( Button::Property::LABEL_TEXT, TEST_LABEL1 );
506 std::string labelText = button.GetProperty<std::string>( Button::Property::LABEL_TEXT );
508 DALI_TEST_EQUALS( labelText, TEST_LABEL1, TEST_LOCATION );
510 Property::Map propertyMap;
511 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT );
512 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, TEST_LABEL2 );
513 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
514 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
515 button.SetProperty( Button::Property::LABEL, propertyMap );
517 labelText = button.GetProperty<std::string>( Button::Property::LABEL_TEXT );
519 DALI_TEST_EQUALS( labelText, TEST_LABEL2, TEST_LOCATION );
524 int UtcDaliButtonSetUnselectedImageP(void)
526 ToolkitTestApplication application;
527 tet_infoline(" UtcDaliButtonSetUnselectedImageP");
529 PushButton pushButton = PushButton::New();
530 Stage::GetCurrent().Add( pushButton );
532 application.SendNotification();
533 application.Render();
535 pushButton.SetUnselectedImage( "Image.jpg" );
537 application.SendNotification();
538 application.Render();
540 DALI_TEST_CHECK( pushButton );
545 int UtcDaliButtonSetSelectedImageP(void)
547 ToolkitTestApplication application;
548 tet_infoline(" UtcDaliButtonSetButtonImage");
550 PushButton pushButton = PushButton::New();
551 Stage::GetCurrent().Add( pushButton );
553 application.SendNotification();
554 application.Render();
556 pushButton.SetSelectedImage( "Image.jpg" );
558 application.SendNotification();
559 application.Render();
561 DALI_TEST_CHECK( pushButton );
566 int UtcDaliButtonPressedSignalP(void)
568 ToolkitTestApplication application;
569 tet_infoline(" UtcDaliButtonPressedSignalP");
571 Button button = PushButton::New();
572 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
573 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
574 button.SetPosition( 240, 400 );
575 button.SetSize( 100, 100 );
577 Stage::GetCurrent().Add( button );
579 application.SendNotification();
580 application.Render();
582 // connect to its touch signal
583 ConnectionTracker* testTracker = new ConnectionTracker();
584 button.PressedSignal().Connect( &ButtonCallback );
585 button.ReleasedSignal().Connect( &ButtonCallback );
586 bool pressedSignal = false;
587 bool releasedSignal = false;
588 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
589 button.ConnectSignal( testTracker, "released", CallbackFunctor(&releasedSignal) );
591 Dali::Integration::TouchEvent event;
593 // Test1. Touch point down and up inside the button.
595 gIsCalledButtonCallback = false;
596 event = Dali::Integration::TouchEvent();
597 event.AddPoint( GetPointDownInside() );
598 application.ProcessEvent( event );
600 DALI_TEST_CHECK( gIsCalledButtonCallback );
601 DALI_TEST_CHECK( pressedSignal );
603 gIsCalledButtonCallback = false;
604 event = Dali::Integration::TouchEvent();
605 event.AddPoint( GetPointUpInside() );
606 application.ProcessEvent( event );
608 DALI_TEST_CHECK( gIsCalledButtonCallback );
609 DALI_TEST_CHECK( releasedSignal );
611 // Test2. Touch point down and up outside the button.
613 pressedSignal = false;
614 releasedSignal = false;
615 gIsCalledButtonCallback = false;
616 event = Dali::Integration::TouchEvent();
617 event.AddPoint( GetPointDownOutside() );
618 application.ProcessEvent( event );
620 DALI_TEST_CHECK( !gIsCalledButtonCallback );
621 DALI_TEST_CHECK( !pressedSignal );
623 gIsCalledButtonCallback = false;
624 event = Dali::Integration::TouchEvent();
625 event.AddPoint( GetPointUpOutside() );
626 application.ProcessEvent( event );
628 DALI_TEST_CHECK( !gIsCalledButtonCallback );
629 DALI_TEST_CHECK( !releasedSignal );
631 // Test3. Touch point down inside and up outside the button.
633 gIsCalledButtonCallback = false;
634 event = Dali::Integration::TouchEvent();
635 event.AddPoint( GetPointDownInside() );
636 application.ProcessEvent( event );
638 DALI_TEST_CHECK( gIsCalledButtonCallback );
640 gIsCalledButtonCallback = false;
641 event = Dali::Integration::TouchEvent();
642 event.AddPoint( GetPointLeave() );
643 application.ProcessEvent( event );
645 event = Dali::Integration::TouchEvent();
646 event.AddPoint( GetPointUpOutside() );
647 application.ProcessEvent( event );
649 DALI_TEST_CHECK( gIsCalledButtonCallback );
651 // Test4. Touch point down outside and up inside the button.
653 gIsCalledButtonCallback = false;
654 event = Dali::Integration::TouchEvent();
655 event.AddPoint( GetPointDownOutside() );
656 application.ProcessEvent( event );
658 DALI_TEST_CHECK( !gIsCalledButtonCallback );
660 gIsCalledButtonCallback = false;
661 event = Dali::Integration::TouchEvent();
662 event.AddPoint( GetPointEnter() );
663 application.ProcessEvent( event );
665 event = Dali::Integration::TouchEvent();
666 event.AddPoint( GetPointUpInside() );
667 application.ProcessEvent( event );
669 DALI_TEST_CHECK( !gIsCalledButtonCallback );
673 int UtcDaliButtonClickedSignalP(void)
675 ToolkitTestApplication application;
676 tet_infoline(" UtcDaliButtonClickedSignalP");
678 Button button = PushButton::New();
679 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
680 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
681 button.SetPosition( 240, 400 );
682 button.SetSize( 100, 100 );
684 Stage::GetCurrent().Add( button );
686 application.SendNotification();
687 application.Render();
689 // connect to its touch signal
690 button.ClickedSignal().Connect( &ButtonCallback );
691 bool clickedSignal = false;
692 ConnectionTracker* testTracker = new ConnectionTracker();
693 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
695 Dali::Integration::TouchEvent event;
697 // Test1. Touch point down and up inside the button.
699 gIsCalledButtonCallback = false;
700 event = Dali::Integration::TouchEvent();
701 event.AddPoint( GetPointDownInside() );
702 application.ProcessEvent( event );
704 event = Dali::Integration::TouchEvent();
705 event.AddPoint( GetPointUpInside() );
706 application.ProcessEvent( event );
708 DALI_TEST_CHECK( gIsCalledButtonCallback );
709 DALI_TEST_CHECK( clickedSignal );
711 // Test2. Touch point down and up outside the button.
713 gIsCalledButtonCallback = false;
714 clickedSignal = false;
715 event = Dali::Integration::TouchEvent();
716 event.AddPoint( GetPointDownOutside() );
717 application.ProcessEvent( event );
719 event = Dali::Integration::TouchEvent();
720 event.AddPoint( GetPointUpOutside() );
721 application.ProcessEvent( event );
723 DALI_TEST_CHECK( !gIsCalledButtonCallback );
724 DALI_TEST_CHECK( !clickedSignal );
726 // Test3. Touch point down inside and up outside the button.
728 gIsCalledButtonCallback = false;
729 clickedSignal = false;
730 event = Dali::Integration::TouchEvent();
731 event.AddPoint( GetPointDownInside() );
732 application.ProcessEvent( event );
734 event = Dali::Integration::TouchEvent();
735 event.AddPoint( GetPointLeave() );
736 application.ProcessEvent( event );
738 event = Dali::Integration::TouchEvent();
739 event.AddPoint( GetPointUpOutside() );
740 application.ProcessEvent( event );
742 DALI_TEST_CHECK( !gIsCalledButtonCallback );
743 DALI_TEST_CHECK( !clickedSignal );
745 // Test4. Touch point down outside and up inside the button.
747 gIsCalledButtonCallback = false;
748 clickedSignal = false;
749 event = Dali::Integration::TouchEvent();
750 event.AddPoint( GetPointDownOutside() );
751 application.ProcessEvent( event );
753 event = Dali::Integration::TouchEvent();
754 event.AddPoint( GetPointEnter() );
755 application.ProcessEvent( event );
757 event = Dali::Integration::TouchEvent();
758 event.AddPoint( GetPointUpInside() );
759 application.ProcessEvent( event );
761 DALI_TEST_CHECK( !gIsCalledButtonCallback );
762 DALI_TEST_CHECK( !clickedSignal );
766 int UtcDaliButtonStateChangedSignalP(void)
768 ToolkitTestApplication application;
769 tet_infoline(" UtcDaliButtonStateChangedSignalP");
771 Button button = PushButton::New();
772 button.SetTogglableButton( true );
774 Stage::GetCurrent().Add( button );
776 application.SendNotification();
777 application.Render();
779 // connect to its signal
780 button.StateChangedSignal().Connect( &ButtonCallback );
781 bool stateChangedSignal = false;
782 ConnectionTracker* testTracker = new ConnectionTracker();
783 button.ConnectSignal( testTracker, "stateChanged", CallbackFunctor(&stateChangedSignal) );
785 gIsCalledButtonCallback = false;
786 button.SetSelected( true );
788 DALI_TEST_CHECK( gIsCalledButtonCallback );
789 DALI_TEST_CHECK( stateChangedSignal );
791 gIsCalledButtonCallback = false;
792 stateChangedSignal = false;
794 button.SetSelected( false );
796 DALI_TEST_CHECK( gIsCalledButtonCallback );
797 DALI_TEST_CHECK( stateChangedSignal );
801 int UtcDaliButtonSetProperty(void)
803 tet_infoline("UtcDaliButtonSetProperty: ");
804 ToolkitTestApplication application;
806 PushButton pushButton = PushButton::New();
808 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
809 DALI_TEST_CHECK( false == pushButton.IsDisabled() );
811 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
812 DALI_TEST_CHECK( true == pushButton.IsDisabled() );
817 int UtcDaliButtonSize(void)
819 ToolkitTestApplication application;
820 tet_infoline(" UtcDaliButtonSize");
822 // First an image is set, then SetSize is called.
823 PushButton pushButton = PushButton::New();
824 Stage::GetCurrent().Add( pushButton );
826 pushButton.SetBackgroundImage( "Image.jpg" );
827 pushButton.SetSize( 10.f, 10.f );
829 application.SendNotification();
830 application.Render();
832 Vector3 size = pushButton.GetCurrentSize();
834 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
835 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
839 int UtcDaliButtonSetSelectedBackgroundImageP(void)
841 ToolkitTestApplication application;
843 PushButton button = PushButton::New();
844 Stage::GetCurrent().Add( button );
848 button.SetSelectedBackgroundImage( "TestImage.jpg");
849 DALI_TEST_CHECK( true );
853 DALI_TEST_CHECK( false );
859 int UtcDaliButtonSetSelectedBackgroundImageN(void)
861 ToolkitTestApplication application;
867 button.SetSelectedBackgroundImage( "TestImage.jpg");
868 DALI_TEST_CHECK( false );
872 DALI_TEST_CHECK( true );
878 int UtcDaliButtonSetDisabledImageP(void)
880 ToolkitTestApplication application;
882 PushButton button = PushButton::New();
883 Stage::GetCurrent().Add( button );
887 button.SetDisabledImage( "TestImage.jpg");
888 DALI_TEST_CHECK( true );
892 DALI_TEST_CHECK( false );
898 int UtcDaliButtonSetDisabledImageN(void)
900 ToolkitTestApplication application;
906 button.SetDisabledImage( "TestImage.jpg");
907 DALI_TEST_CHECK( false );
911 DALI_TEST_CHECK( true );
917 int UtcDaliButtonSetDisabledSelectedImageP(void)
919 ToolkitTestApplication application;
921 PushButton button = PushButton::New();
922 Stage::GetCurrent().Add( button );
926 button.SetDisabledSelectedImage( "TestImage.jpg");
927 DALI_TEST_CHECK( true );
931 DALI_TEST_CHECK( false );
937 int UtcDaliButtonSetDisabledSelectedImageN(void)
939 ToolkitTestApplication application;
945 button.SetDisabledSelectedImage( "TestImage.jpg");
946 DALI_TEST_CHECK( false );
950 DALI_TEST_CHECK( true );
956 int UtcDaliButtonSetLabeActorlP(void)
958 ToolkitTestApplication application;
960 PushButton button = PushButton::New();
961 Stage::GetCurrent().Add( button );
965 button.SetLabel( TextLabel::New("Hello") );
966 DALI_TEST_CHECK( true );
970 DALI_TEST_CHECK( false );
976 int UtcDaliButtonSetLabelN(void)
978 ToolkitTestApplication application;
984 button.SetLabel( TextLabel::New("Hello") );
985 DALI_TEST_CHECK( false );
989 DALI_TEST_CHECK( true );
995 int UtcDaliButtonSetButtonImageP(void)
997 ToolkitTestApplication application;
999 PushButton button = PushButton::New();
1000 Stage::GetCurrent().Add( button );
1004 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1005 button.SetButtonImage( image1 );
1007 Property::Value value = button.GetProperty(Button::Property::UNSELECTED_STATE_IMAGE );
1008 DALI_TEST_CHECK( value.Get<std::string>() == TEST_IMAGE_ONE );
1012 DALI_TEST_CHECK( false );
1015 std::string imageUrl;
1017 Dali::Actor actor = button.GetButtonImage();
1019 Toolkit::ImageView imageView = Toolkit::ImageView ::DownCast( actor );
1021 tet_infoline(" UtcDaliButtonSetButtonImageP Ensure an ImageView is returned\n");
1022 DALI_TEST_CHECK ( imageView )
1027 int UtcDaliButtonSetButtonImageN(void)
1029 ToolkitTestApplication application;
1035 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1036 button.SetButtonImage( image1 );
1038 DALI_TEST_CHECK( false );
1042 DALI_TEST_CHECK( true );
1048 int UtcDaliButtonSetSelectedImageWithImageP(void)
1050 ToolkitTestApplication application;
1052 PushButton button = PushButton::New();
1053 Stage::GetCurrent().Add( button );
1054 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1058 button.SetSelectedImage( image1 );
1059 Property::Value value = button.GetProperty( Button::Property::SELECTED_STATE_IMAGE );
1060 DALI_TEST_CHECK( value.Get<std::string>() == TEST_IMAGE_ONE );
1064 DALI_TEST_CHECK( false );
1067 std::string imageUrl;
1069 Dali::Actor actor = button.GetSelectedImage();
1071 Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( actor );
1073 tet_infoline(" UtcDaliButtonSetSelectedImageWithImageP Ensure an ImageView is returned\n");
1078 int UtcDaliButtonSetSelectedImageWithImageN(void)
1080 ToolkitTestApplication application;
1086 button.SetSelectedImage( CreateBufferImage( 10, 10, Color::WHITE ) );
1087 DALI_TEST_CHECK( false );
1091 DALI_TEST_CHECK( true );
1097 int UtcDaliButtonSetSelectedColorP(void)
1099 ToolkitTestApplication application;
1100 tet_infoline(" UtcDaliButtonSetSelectedColorP");
1102 PushButton pushButton = PushButton::New();
1103 Stage::GetCurrent().Add( pushButton );
1105 application.SendNotification();
1106 application.Render();
1108 const Vector4 SET_COLOR = Color::BLUE;
1110 pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1111 pushButton.SetProperty( Button::Property::SELECTED_COLOR, SET_COLOR );
1113 application.SendNotification();
1114 application.Render();
1116 Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1118 DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
1123 int UtcDaliButtonSetUnSelectedColorP(void)
1125 ToolkitTestApplication application;
1126 tet_infoline(" UtcDaliButtonSetUnSelectedColorP");
1128 PushButton pushButton = PushButton::New();
1129 Stage::GetCurrent().Add( pushButton );
1131 application.SendNotification();
1132 application.Render();
1134 const Vector4 SET_COLOR = Color::BLUE;
1136 pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1137 pushButton.SetProperty( Button::Property::UNSELECTED_COLOR, SET_COLOR );
1139 application.SendNotification();
1140 application.Render();
1142 Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::UNSELECTED_COLOR );
1144 DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
1149 int UtcDaliButtonResetSelectedColorP(void)
1151 ToolkitTestApplication application;
1152 tet_infoline(" UtcDaliButtonSetSelectedColorP");
1154 PushButton pushButton = PushButton::New();
1155 Stage::GetCurrent().Add( pushButton );
1157 application.SendNotification();
1158 application.Render();
1160 const Vector4 FIRST_COLOR = Color::BLUE;
1161 const Vector4 SECOND_COLOR = Color::BLUE;
1163 pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1164 pushButton.SetProperty( Button::Property::SELECTED_COLOR, FIRST_COLOR );
1166 application.SendNotification();
1167 application.Render();
1169 Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1171 DALI_TEST_EQUALS( color, FIRST_COLOR, TEST_LOCATION );
1173 pushButton.SetProperty( Button::Property::SELECTED_COLOR, SECOND_COLOR );
1175 application.SendNotification();
1176 application.Render();
1178 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1180 DALI_TEST_EQUALS( color, SECOND_COLOR, TEST_LOCATION );
1185 int UtcDaliButtonSetImagesWithDeprecatedProperties(void)
1187 ToolkitTestApplication application;
1188 tet_infoline(" UtcDaliButtonSetImagesWithDeprecatedProperties");
1190 PushButton pushButton = PushButton::New();
1192 Stage::GetCurrent().Add( pushButton );
1194 Property::Map propertyMap;
1195 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1196 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1198 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1200 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, propertyMap );
1201 application.SendNotification();
1202 application.Render();
1203 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1205 tet_infoline(" Set state to selected and provide SELECTED visual");
1206 pushButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, propertyMap );
1207 pushButton.SetProperty( Toolkit::Button::Property::SELECTED, true );
1208 application.SendNotification();
1209 application.Render();
1210 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1212 tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual");
1213 pushButton.SetProperty( Toolkit::Button::Property::SELECTED, false );
1214 pushButton.SetProperty( Toolkit::Button::Property::DISABLED, true );
1215 pushButton.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, propertyMap );
1216 application.SendNotification();
1217 application.Render();
1218 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1223 int UtcDaliButtonSetGetDepreciatedPropertiesWithURL(void)
1225 ToolkitTestApplication application;
1226 tet_infoline(" UtcDaliButtonSetGetDepreciatedPropertiesWithURL");
1228 PushButton button = PushButton::New();
1229 Stage::GetCurrent().Add( button );
1231 tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual");
1232 button.SetProperty( Toolkit::Button::Property::DISABLED, true );
1233 button.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, TEST_IMAGE_ONE );
1235 Property::Value value = button.GetProperty(Button::Property::DISABLED_STATE_IMAGE );
1236 DALI_TEST_EQUALS( value.Get<std::string>(), TEST_IMAGE_ONE, TEST_LOCATION );