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/controls/buttons/button-devel.h>
31 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
35 using namespace Toolkit;
38 void utc_dali_toolkit_button_startup(void)
40 test_return_value = TET_UNDEF;
43 void utc_dali_toolkit_button_cleanup(void)
45 test_return_value = TET_PASS;
50 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
52 static bool gIsCalledButtonCallback = false;
54 const int RENDER_FRAME_INTERVAL = 16;
56 static bool ButtonCallback( Button button )
58 gIsCalledButtonCallback = true;
62 static std::string GetButtonText( Button button )
64 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
66 Property::Map *labelProperty = value.GetMap();
68 std::string textLabel;
72 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
73 value->Get( textLabel );
79 struct CallbackFunctor
81 CallbackFunctor(bool* callbackFlag)
82 : mCallbackFlag( callbackFlag )
88 *mCallbackFlag = true;
93 Dali::Integration::Point GetPointDownInside()
95 Dali::Integration::Point point;
96 point.SetState( PointState::DOWN );
97 point.SetScreenPosition( Vector2( 240, 400 ) );
101 Dali::Integration::Point GetPointUpInside()
103 Dali::Integration::Point point;
104 point.SetState( PointState::UP );
105 point.SetScreenPosition( Vector2( 240, 400 ) );
109 Dali::Integration::Point GetPointLeave()
111 Dali::Integration::Point point;
112 point.SetState( PointState::LEAVE );
113 point.SetScreenPosition( Vector2( 240, 400 ) );
117 Dali::Integration::Point GetPointEnter()
119 Dali::Integration::Point point;
120 point.SetState( PointState::MOTION );
121 point.SetScreenPosition( Vector2( 240, 400 ) );
125 Dali::Integration::Point GetPointDownOutside()
127 Dali::Integration::Point point;
128 point.SetState( PointState::DOWN );
129 point.SetScreenPosition( Vector2( 10, 10 ) );
133 Dali::Integration::Point GetPointUpOutside()
135 Dali::Integration::Point point;
136 point.SetState( PointState::UP );
137 point.SetScreenPosition( Vector2( 10, 10 ) );
141 static float ANIMATION_TIME( 0.5f );
145 int UtcDaliButtonConstructorP(void)
147 TestApplication application;
151 DALI_TEST_CHECK( !button );
155 int UtcDaliButtonCopyConstructorP(void)
157 TestApplication application;
159 // Initialize an object, ref count == 1
160 Button button = PushButton::New();
162 Button copy( button );
163 DALI_TEST_CHECK( copy );
167 int UtcDaliButtonAssignmentOperatorP(void)
169 TestApplication application;
171 Button button = PushButton::New();
173 Button copy( button );
174 DALI_TEST_CHECK( copy );
176 DALI_TEST_CHECK( button == copy );
180 int UtcDaliButtonDownCastP(void)
182 TestApplication application;
184 Button button = PushButton::New();
186 BaseHandle object(button);
188 Button button2 = Button::DownCast( object );
189 DALI_TEST_CHECK(button2);
191 Button button3 = DownCast< Button >(object);
192 DALI_TEST_CHECK(button3);
196 int UtcDaliButtonDownCastN(void)
198 TestApplication application;
200 BaseHandle unInitializedObject;
202 Button button1 = Button::DownCast( unInitializedObject );
203 DALI_TEST_CHECK( !button1 );
205 Button button2 = DownCast< Button >( unInitializedObject );
206 DALI_TEST_CHECK( !button2 );
210 int UtcDaliButtonSetDisabledP(void)
212 ToolkitTestApplication application;
214 Button button = PushButton::New();
216 button.SetDisabled( true );
218 DALI_TEST_CHECK( button.IsDisabled() );
220 button.SetDisabled( false );
222 DALI_TEST_CHECK( !button.IsDisabled() );
224 button.SetDisabled( true );
226 DALI_TEST_CHECK( button.IsDisabled() );
228 button.SetDisabled( false );
230 DALI_TEST_CHECK( !button.IsDisabled() );
234 int UtcDaliButtonSetDisabledWithDifferentStates01P(void)
236 ToolkitTestApplication application;
238 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n");
240 Button button = PushButton::New();
242 bool SELECTED = true;
244 button.SetProperty( Button::Property::TOGGLABLE, true);
245 button.SetProperty( Button::Property::SELECTED, SELECTED );
247 button.SetProperty( Button::Property::DISABLED, true);
249 tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n");
250 button.SetProperty( Button::Property::SELECTED, !SELECTED );
252 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
254 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
259 int UtcDaliButtonSetDisabledWithDifferentStates02P(void)
261 ToolkitTestApplication application;
263 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n");
265 Button button = PushButton::New();
267 bool SELECTED = true;
269 button.SetProperty( Button::Property::TOGGLABLE, true );
270 button.SetProperty( Button::Property::SELECTED, SELECTED );
271 button.SetProperty( Button::Property::DISABLED, true );
273 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
274 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
275 tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n");
277 button.SetProperty( Button::Property::DISABLED, false );
278 button.SetProperty( Button::Property::SELECTED, !SELECTED );
280 isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
281 DALI_TEST_EQUALS( isSelected, !SELECTED , TEST_LOCATION );
286 int UtcDaliButtonPropertyGetLabelAlignment(void)
288 ToolkitTestApplication application;
289 tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
291 Button button = PushButton::New();
292 button.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END" );
293 DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
298 int UtcDaliButtonIsDisabledP(void)
300 ToolkitTestApplication application;
302 Button button = PushButton::New();
304 button.SetDisabled( true );
306 DALI_TEST_CHECK( button.IsDisabled() );
308 button.SetDisabled( false );
310 DALI_TEST_CHECK( !button.IsDisabled() );
314 int UtcDaliButtonSetAutoRepeatingP(void)
316 ToolkitTestApplication application;
318 Button button = PushButton::New();
320 button.SetAutoRepeating( true );
322 DALI_TEST_CHECK( button.IsAutoRepeating() );
324 button.SetAutoRepeating( false );
326 DALI_TEST_CHECK( !button.IsAutoRepeating() );
328 button.SetAutoRepeating( true );
330 DALI_TEST_CHECK( button.IsAutoRepeating() );
332 button.SetAutoRepeating( false );
334 DALI_TEST_CHECK( !button.IsAutoRepeating() );
338 int UtcDaliButtonIsAutoRepeatingP(void)
340 ToolkitTestApplication application;
342 Button button = PushButton::New();
344 button.SetAutoRepeating( true );
346 DALI_TEST_CHECK( button.IsAutoRepeating() );
348 button.SetAutoRepeating( false );
350 DALI_TEST_CHECK( !button.IsAutoRepeating() );
354 int UtcDaliButtonAutoRepeatingP(void)
356 ToolkitTestApplication application;
357 tet_infoline(" UtcDaliButtonPressedSignalP Setup Autorepeating and check multiple clicked signals received\n");
359 const float AUTO_REPEATING_DELAY = 0.15f;
361 Button button = PushButton::New();
362 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
363 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
364 button.SetPosition( 240, 400 );
365 button.SetSize( 100, 100 );
366 Stage::GetCurrent().Add( button );
368 application.SendNotification();
369 application.Render();
371 button.SetProperty( Toolkit::Button::Property::AUTO_REPEATING, true );
372 button.SetProperty( Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY );
373 // connect to its touch signal
374 ConnectionTracker* testTracker = new ConnectionTracker();
375 button.PressedSignal().Connect( &ButtonCallback );
376 button.ClickedSignal().Connect( &ButtonCallback );
377 bool clickedSignal = false;
378 bool pressedSignal = false;
379 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
380 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
382 Dali::Integration::TouchEvent event;
384 // Touch point down and up inside the button.
386 gIsCalledButtonCallback = false;
387 event = Dali::Integration::TouchEvent();
388 event.AddPoint( GetPointDownInside() );
389 application.ProcessEvent( event );
391 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
392 DALI_TEST_EQUALS( pressedSignal, true, TEST_LOCATION );
393 tet_infoline("Consume first clicked signal then wait\n");
395 gIsCalledButtonCallback = false;
396 Dali::Timer timer = Timer::New( AUTO_REPEATING_DELAY );
397 timer.MockEmitSignal();
398 application.Wait( AUTO_REPEATING_DELAY*2 );
399 DALI_TEST_EQUALS( clickedSignal, true, TEST_LOCATION );
400 tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n");
402 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
404 gIsCalledButtonCallback = false;
405 event = Dali::Integration::TouchEvent();
406 event.AddPoint( GetPointUpInside() );
407 application.ProcessEvent( event );
409 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
414 int UtcDaliButtonSetInitialAutoRepeatingDelayP(void)
416 ToolkitTestApplication application;
418 Button button = PushButton::New();
420 button.SetInitialAutoRepeatingDelay( 0.5f );
422 DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
424 button.SetInitialAutoRepeatingDelay( 0.2f );
426 DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
430 int UtcDaliButtonSetNextAutoRepeatingDelayP(void)
432 ToolkitTestApplication application;
434 Button button = PushButton::New();
436 button.SetNextAutoRepeatingDelay( 0.5f );
438 DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
440 button.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 0.2f );
442 DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
446 int UtcDaliButtonSetTogglableButtonP(void)
448 ToolkitTestApplication application;
450 Button button = PushButton::New();
452 button.SetTogglableButton( true );
454 DALI_TEST_CHECK( button.IsTogglableButton() );
456 button.SetTogglableButton( false );
458 DALI_TEST_CHECK( !button.IsTogglableButton() );
462 int UtcDaliButtonSetSelectedP(void)
464 ToolkitTestApplication application;
466 Button button = PushButton::New();
467 button.SetTogglableButton( true );
469 button.SetSelected( true );
471 DALI_TEST_CHECK( button.IsSelected() );
473 button.SetSelected( false );
475 DALI_TEST_CHECK( !button.IsSelected() );
479 int UtcDaliButtonSetAnimationTimeP(void)
481 ToolkitTestApplication application;
482 tet_infoline(" UtcDaliButtonSetAnimationTimeP");
484 Button button = PushButton::New();
486 button.SetAnimationTime( ANIMATION_TIME );
488 DALI_TEST_EQUALS( button.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
492 int UtcDaliButtonSetLabelStringWithPropertyMapP(void)
494 ToolkitTestApplication application;
496 Button button = PushButton::New();
497 button.SetProperty( Toolkit::Button::Property::LABEL,
498 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
499 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
500 .Add( Toolkit::TextVisual::Property::TEXT, "Button Label")
503 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
507 int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void)
509 ToolkitTestApplication application;
511 Button button = PushButton::New();
513 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string");
515 Property::Map textVisualMapInitial;
516 textVisualMapInitial["visualType"] = "TEXT";
517 textVisualMapInitial["pointSize"] = 15.0f;
518 textVisualMapInitial["text"] = "button label initial";
520 button.SetProperty( Button::Property::LABEL, textVisualMapInitial );
522 DALI_TEST_EQUALS( GetButtonText( button ), "button label initial", TEST_LOCATION );
524 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test");
526 Property::Map propertyMap;
527 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT );
528 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, "error if this is the final text" );
529 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
531 button.SetProperty( Button::Property::LABEL, propertyMap );
533 DALI_TEST_EQUALS( GetButtonText( button ), "error if this is the final text", TEST_LOCATION );
535 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test");
537 Property::Map textVisualMap;
538 textVisualMap["visualType"] = "TEXT";
539 textVisualMap["pointSize"] = 15.0f;
540 textVisualMap["text"] = "Button Label";
542 button.SetProperty( Toolkit::Button::Property::LABEL, textVisualMap );
544 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
548 int UtcDaliButtonSetLabelWithStringP(void)
550 ToolkitTestApplication application;
552 Button button = PushButton::New();
554 // Set default point size for text visual as style sheet not available.
555 button.SetProperty( Toolkit::Button::Property::LABEL,
556 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
557 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
560 button.SetProperty( Toolkit::Button::Property::LABEL, "Button Label" );
562 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
566 int UtcDaliButtonSetLabelPropertyP(void)
568 ToolkitTestApplication application;
570 tet_infoline(" UtcDaliButtonSetLabelPropertyP Set text label and then set again with new text");
573 const std::string TEST_LABEL1 = "test label one";
574 const std::string TEST_LABEL2 = "test label two";
576 Button button = PushButton::New();
578 button.SetProperty( Toolkit::Button::Property::LABEL,
579 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
580 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
581 .Add( Toolkit::TextVisual::Property::TEXT, TEST_LABEL1 )
584 DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL1, TEST_LOCATION );
586 Property::Map propertyMap;
587 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT );
588 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, TEST_LABEL2 );
589 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
590 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
591 button.SetProperty( Button::Property::LABEL, propertyMap );
593 DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL2, TEST_LOCATION );
598 int UtcDaliButtonSetUnselectedImageP(void)
600 ToolkitTestApplication application;
601 tet_infoline(" UtcDaliButtonSetUnselectedImageP");
603 PushButton pushButton = PushButton::New();
604 Stage::GetCurrent().Add( pushButton );
606 application.SendNotification();
607 application.Render();
609 pushButton.SetUnselectedImage( "Image.jpg" );
611 application.SendNotification();
612 application.Render();
614 DALI_TEST_CHECK( pushButton );
619 int UtcDaliButtonSetSelectedImageP(void)
621 ToolkitTestApplication application;
622 tet_infoline(" UtcDaliButtonSetButtonImage");
624 PushButton pushButton = PushButton::New();
625 Stage::GetCurrent().Add( pushButton );
627 application.SendNotification();
628 application.Render();
630 pushButton.SetSelectedImage( "Image.jpg" );
632 application.SendNotification();
633 application.Render();
635 DALI_TEST_CHECK( pushButton );
640 int UtcDaliButtonPressedSignalP(void)
642 ToolkitTestApplication application;
643 tet_infoline(" UtcDaliButtonPressedSignalP");
645 Button button = PushButton::New();
646 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
647 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
648 button.SetPosition( 240, 400 );
649 button.SetSize( 100, 100 );
651 Stage::GetCurrent().Add( button );
653 application.SendNotification();
654 application.Render();
656 // connect to its touch signal
657 ConnectionTracker* testTracker = new ConnectionTracker();
658 button.PressedSignal().Connect( &ButtonCallback );
659 button.ReleasedSignal().Connect( &ButtonCallback );
660 bool pressedSignal = false;
661 bool releasedSignal = false;
662 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
663 button.ConnectSignal( testTracker, "released", CallbackFunctor(&releasedSignal) );
665 Dali::Integration::TouchEvent event;
667 // Test1. Touch point down and up inside the button.
669 gIsCalledButtonCallback = false;
670 event = Dali::Integration::TouchEvent();
671 event.AddPoint( GetPointDownInside() );
672 application.ProcessEvent( event );
674 DALI_TEST_CHECK( gIsCalledButtonCallback );
675 DALI_TEST_CHECK( pressedSignal );
677 gIsCalledButtonCallback = false;
678 event = Dali::Integration::TouchEvent();
679 event.AddPoint( GetPointUpInside() );
680 application.ProcessEvent( event );
682 DALI_TEST_CHECK( gIsCalledButtonCallback );
683 DALI_TEST_CHECK( releasedSignal );
685 // Test2. Touch point down and up outside the button.
687 pressedSignal = false;
688 releasedSignal = false;
689 gIsCalledButtonCallback = false;
690 event = Dali::Integration::TouchEvent();
691 event.AddPoint( GetPointDownOutside() );
692 application.ProcessEvent( event );
694 DALI_TEST_CHECK( !gIsCalledButtonCallback );
695 DALI_TEST_CHECK( !pressedSignal );
697 gIsCalledButtonCallback = false;
698 event = Dali::Integration::TouchEvent();
699 event.AddPoint( GetPointUpOutside() );
700 application.ProcessEvent( event );
702 DALI_TEST_CHECK( !gIsCalledButtonCallback );
703 DALI_TEST_CHECK( !releasedSignal );
705 // Test3. Touch point down inside and up outside the button.
707 gIsCalledButtonCallback = false;
708 event = Dali::Integration::TouchEvent();
709 event.AddPoint( GetPointDownInside() );
710 application.ProcessEvent( event );
712 DALI_TEST_CHECK( gIsCalledButtonCallback );
714 gIsCalledButtonCallback = false;
715 event = Dali::Integration::TouchEvent();
716 event.AddPoint( GetPointLeave() );
717 application.ProcessEvent( event );
719 event = Dali::Integration::TouchEvent();
720 event.AddPoint( GetPointUpOutside() );
721 application.ProcessEvent( event );
723 DALI_TEST_CHECK( gIsCalledButtonCallback );
725 // Test4. Touch point down outside and up inside the button.
727 gIsCalledButtonCallback = false;
728 event = Dali::Integration::TouchEvent();
729 event.AddPoint( GetPointDownOutside() );
730 application.ProcessEvent( event );
732 DALI_TEST_CHECK( !gIsCalledButtonCallback );
734 gIsCalledButtonCallback = false;
735 event = Dali::Integration::TouchEvent();
736 event.AddPoint( GetPointEnter() );
737 application.ProcessEvent( event );
739 event = Dali::Integration::TouchEvent();
740 event.AddPoint( GetPointUpInside() );
741 application.ProcessEvent( event );
743 DALI_TEST_CHECK( !gIsCalledButtonCallback );
747 int UtcDaliButtonClickedSignalP(void)
749 ToolkitTestApplication application;
750 tet_infoline(" UtcDaliButtonClickedSignalP");
752 Button button = PushButton::New();
753 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
754 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
755 button.SetPosition( 240, 400 );
756 button.SetSize( 100, 100 );
758 Stage::GetCurrent().Add( button );
760 application.SendNotification();
761 application.Render();
763 // connect to its touch signal
764 button.ClickedSignal().Connect( &ButtonCallback );
765 bool clickedSignal = false;
766 ConnectionTracker* testTracker = new ConnectionTracker();
767 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
769 Dali::Integration::TouchEvent event;
771 // Test1. Touch point down and up inside the button.
773 gIsCalledButtonCallback = false;
774 event = Dali::Integration::TouchEvent();
775 event.AddPoint( GetPointDownInside() );
776 application.ProcessEvent( event );
778 event = Dali::Integration::TouchEvent();
779 event.AddPoint( GetPointUpInside() );
780 application.ProcessEvent( event );
782 DALI_TEST_CHECK( gIsCalledButtonCallback );
783 DALI_TEST_CHECK( clickedSignal );
785 // Test2. Touch point down and up outside the button.
787 gIsCalledButtonCallback = false;
788 clickedSignal = false;
789 event = Dali::Integration::TouchEvent();
790 event.AddPoint( GetPointDownOutside() );
791 application.ProcessEvent( event );
793 event = Dali::Integration::TouchEvent();
794 event.AddPoint( GetPointUpOutside() );
795 application.ProcessEvent( event );
797 DALI_TEST_CHECK( !gIsCalledButtonCallback );
798 DALI_TEST_CHECK( !clickedSignal );
800 // Test3. Touch point down inside and up outside the button.
802 gIsCalledButtonCallback = false;
803 clickedSignal = false;
804 event = Dali::Integration::TouchEvent();
805 event.AddPoint( GetPointDownInside() );
806 application.ProcessEvent( event );
808 event = Dali::Integration::TouchEvent();
809 event.AddPoint( GetPointLeave() );
810 application.ProcessEvent( event );
812 event = Dali::Integration::TouchEvent();
813 event.AddPoint( GetPointUpOutside() );
814 application.ProcessEvent( event );
816 DALI_TEST_CHECK( !gIsCalledButtonCallback );
817 DALI_TEST_CHECK( !clickedSignal );
819 // Test4. Touch point down outside and up inside the button.
821 gIsCalledButtonCallback = false;
822 clickedSignal = false;
823 event = Dali::Integration::TouchEvent();
824 event.AddPoint( GetPointDownOutside() );
825 application.ProcessEvent( event );
827 event = Dali::Integration::TouchEvent();
828 event.AddPoint( GetPointEnter() );
829 application.ProcessEvent( event );
831 event = Dali::Integration::TouchEvent();
832 event.AddPoint( GetPointUpInside() );
833 application.ProcessEvent( event );
835 DALI_TEST_CHECK( !gIsCalledButtonCallback );
836 DALI_TEST_CHECK( !clickedSignal );
840 int UtcDaliButtonStateChangedSignalP(void)
842 ToolkitTestApplication application;
843 tet_infoline(" UtcDaliButtonStateChangedSignalP");
845 Button button = PushButton::New();
846 button.SetTogglableButton( true );
848 Stage::GetCurrent().Add( button );
850 application.SendNotification();
851 application.Render();
853 // connect to its signal
854 button.StateChangedSignal().Connect( &ButtonCallback );
855 bool stateChangedSignal = false;
856 ConnectionTracker* testTracker = new ConnectionTracker();
857 button.ConnectSignal( testTracker, "stateChanged", CallbackFunctor(&stateChangedSignal) );
859 gIsCalledButtonCallback = false;
860 button.SetSelected( true );
862 DALI_TEST_CHECK( gIsCalledButtonCallback );
863 DALI_TEST_CHECK( stateChangedSignal );
865 gIsCalledButtonCallback = false;
866 stateChangedSignal = false;
868 button.SetSelected( false );
870 DALI_TEST_CHECK( gIsCalledButtonCallback );
871 DALI_TEST_CHECK( stateChangedSignal );
875 int UtcDaliButtonSetProperty(void)
877 tet_infoline("UtcDaliButtonSetProperty: ");
878 ToolkitTestApplication application;
880 PushButton pushButton = PushButton::New();
882 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
883 DALI_TEST_CHECK( false == pushButton.IsDisabled() );
885 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
886 DALI_TEST_CHECK( true == pushButton.IsDisabled() );
891 int UtcDaliButtonSize(void)
893 ToolkitTestApplication application;
894 tet_infoline(" UtcDaliButtonSize");
896 // First an image is set, then SetSize is called.
897 PushButton pushButton = PushButton::New();
898 Stage::GetCurrent().Add( pushButton );
900 pushButton.SetBackgroundImage( "Image.jpg" );
901 pushButton.SetSize( 10.f, 10.f );
903 application.SendNotification();
904 application.Render();
906 Vector3 size = pushButton.GetCurrentSize();
908 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
909 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
913 int UtcDaliButtonSetSelectedBackgroundImageP(void)
915 ToolkitTestApplication application;
917 PushButton button = PushButton::New();
918 Stage::GetCurrent().Add( button );
922 button.SetSelectedBackgroundImage( "TestImage.jpg");
923 DALI_TEST_CHECK( true );
927 DALI_TEST_CHECK( false );
933 int UtcDaliButtonSetSelectedBackgroundImageN(void)
935 ToolkitTestApplication application;
941 button.SetSelectedBackgroundImage( "TestImage.jpg");
942 DALI_TEST_CHECK( false );
946 DALI_TEST_CHECK( true );
952 int UtcDaliButtonSetDisabledImageP(void)
954 ToolkitTestApplication application;
956 PushButton button = PushButton::New();
957 Stage::GetCurrent().Add( button );
961 button.SetDisabledImage( "TestImage.jpg");
962 DALI_TEST_CHECK( true );
966 DALI_TEST_CHECK( false );
972 int UtcDaliButtonSetDisabledImageN(void)
974 ToolkitTestApplication application;
980 button.SetDisabledImage( "TestImage.jpg");
981 DALI_TEST_CHECK( false );
985 DALI_TEST_CHECK( true );
991 int UtcDaliButtonSetDisabledSelectedImageP(void)
993 ToolkitTestApplication application;
995 PushButton button = PushButton::New();
996 Stage::GetCurrent().Add( button );
1000 button.SetDisabledSelectedImage( "TestImage.jpg");
1001 DALI_TEST_CHECK( true );
1005 DALI_TEST_CHECK( false );
1011 int UtcDaliButtonSetDisabledSelectedImageN(void)
1013 ToolkitTestApplication application;
1019 button.SetDisabledSelectedImage( "TestImage.jpg");
1020 DALI_TEST_CHECK( false );
1024 DALI_TEST_CHECK( true );
1030 int UtcDaliButtonSetLabeActorlP(void)
1032 ToolkitTestApplication application;
1034 PushButton button = PushButton::New();
1035 Stage::GetCurrent().Add( button );
1039 button.SetLabel( TextLabel::New("Hello") );
1040 DALI_TEST_CHECK( true );
1044 DALI_TEST_CHECK( false );
1050 int UtcDaliButtonSetLabelN(void)
1052 ToolkitTestApplication application;
1058 button.SetLabel( TextLabel::New("Hello") );
1059 DALI_TEST_CHECK( false );
1063 DALI_TEST_CHECK( true );
1069 int UtcDaliButtonSetButtonImageP(void)
1071 ToolkitTestApplication application;
1073 PushButton button = PushButton::New();
1074 Stage::GetCurrent().Add( button );
1078 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1079 button.SetButtonImage( image1 );
1081 Property::Value value = button.GetProperty(Button::Property::UNSELECTED_STATE_IMAGE );
1082 DALI_TEST_CHECK( value.Get<std::string>() == TEST_IMAGE_ONE );
1086 DALI_TEST_CHECK( false );
1089 std::string imageUrl;
1091 Dali::Actor actor = button.GetButtonImage();
1093 Toolkit::ImageView imageView = Toolkit::ImageView ::DownCast( actor );
1095 tet_infoline(" UtcDaliButtonSetButtonImageP Ensure an ImageView is returned\n");
1096 DALI_TEST_CHECK ( imageView )
1101 int UtcDaliButtonSetButtonImageN(void)
1103 ToolkitTestApplication application;
1109 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1110 button.SetButtonImage( image1 );
1112 DALI_TEST_CHECK( false );
1116 DALI_TEST_CHECK( true );
1122 int UtcDaliButtonSetSelectedImageWithImageP(void)
1124 ToolkitTestApplication application;
1126 PushButton button = PushButton::New();
1127 Stage::GetCurrent().Add( button );
1128 ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1132 button.SetSelectedImage( image1 );
1133 Property::Value value = button.GetProperty( Button::Property::SELECTED_STATE_IMAGE );
1134 DALI_TEST_CHECK( value.Get<std::string>() == TEST_IMAGE_ONE );
1138 DALI_TEST_CHECK( false );
1141 std::string imageUrl;
1143 Dali::Actor actor = button.GetSelectedImage();
1145 Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( actor );
1147 tet_infoline(" UtcDaliButtonSetSelectedImageWithImageP Ensure an ImageView is returned\n");
1152 int UtcDaliButtonSetSelectedImageWithImageN(void)
1154 ToolkitTestApplication application;
1160 button.SetSelectedImage( CreateBufferImage( 10, 10, Color::WHITE ) );
1161 DALI_TEST_CHECK( false );
1165 DALI_TEST_CHECK( true );
1171 int UtcDaliButtonSetSelectedColorP(void)
1173 ToolkitTestApplication application;
1174 tet_infoline(" UtcDaliButtonSetSelectedColorP");
1176 PushButton pushButton = PushButton::New();
1177 Stage::GetCurrent().Add( pushButton );
1179 application.SendNotification();
1180 application.Render();
1182 const Vector4 SET_COLOR = Color::BLUE;
1184 pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1185 pushButton.SetProperty( Button::Property::SELECTED_COLOR, SET_COLOR );
1187 application.SendNotification();
1188 application.Render();
1190 Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1192 DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
1197 int UtcDaliButtonSetUnSelectedColorP(void)
1199 ToolkitTestApplication application;
1200 tet_infoline(" UtcDaliButtonSetUnSelectedColorP");
1202 PushButton pushButton = PushButton::New();
1203 Stage::GetCurrent().Add( pushButton );
1205 application.SendNotification();
1206 application.Render();
1208 const Vector4 SET_COLOR = Color::BLUE;
1210 pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1211 pushButton.SetProperty( Button::Property::UNSELECTED_COLOR, SET_COLOR );
1213 application.SendNotification();
1214 application.Render();
1216 Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::UNSELECTED_COLOR );
1218 DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
1223 int UtcDaliButtonResetSelectedColorP(void)
1225 ToolkitTestApplication application;
1226 tet_infoline(" UtcDaliButtonSetSelectedColorP");
1228 PushButton pushButton = PushButton::New();
1229 Stage::GetCurrent().Add( pushButton );
1231 application.SendNotification();
1232 application.Render();
1234 const Vector4 FIRST_COLOR = Color::BLUE;
1235 const Vector4 SECOND_COLOR = Color::BLUE;
1237 pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1238 pushButton.SetProperty( Button::Property::SELECTED_COLOR, FIRST_COLOR );
1240 application.SendNotification();
1241 application.Render();
1243 Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1245 DALI_TEST_EQUALS( color, FIRST_COLOR, TEST_LOCATION );
1247 pushButton.SetProperty( Button::Property::SELECTED_COLOR, SECOND_COLOR );
1249 application.SendNotification();
1250 application.Render();
1252 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1254 DALI_TEST_EQUALS( color, SECOND_COLOR, TEST_LOCATION );
1259 int UtcDaliButtonSetImagesWithDeprecatedProperties(void)
1261 ToolkitTestApplication application;
1262 tet_infoline(" UtcDaliButtonSetImagesWithDeprecatedProperties");
1264 PushButton pushButton = PushButton::New();
1266 Stage::GetCurrent().Add( pushButton );
1268 Property::Map propertyMap;
1269 propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1270 propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1272 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1274 pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, propertyMap );
1275 application.SendNotification();
1276 application.Render();
1277 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1279 tet_infoline(" Set state to selected and provide SELECTED visual");
1280 pushButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, propertyMap );
1281 pushButton.SetProperty( Toolkit::Button::Property::SELECTED, true );
1282 application.SendNotification();
1283 application.Render();
1284 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1286 tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual");
1287 pushButton.SetProperty( Toolkit::Button::Property::SELECTED, false );
1288 pushButton.SetProperty( Toolkit::Button::Property::DISABLED, true );
1289 pushButton.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, propertyMap );
1290 application.SendNotification();
1291 application.Render();
1292 DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1297 int UtcDaliButtonSetGetDepreciatedPropertiesWithURL(void)
1299 ToolkitTestApplication application;
1300 tet_infoline(" UtcDaliButtonSetGetDepreciatedPropertiesWithURL");
1302 PushButton button = PushButton::New();
1303 Stage::GetCurrent().Add( button );
1305 tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual");
1306 button.SetProperty( Toolkit::Button::Property::DISABLED, true );
1307 button.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, TEST_IMAGE_ONE );
1309 Property::Value value = button.GetProperty(Button::Property::DISABLED_STATE_IMAGE );
1310 DALI_TEST_EQUALS( value.Get<std::string>(), TEST_IMAGE_ONE, TEST_LOCATION );
1315 int UtcDaliButtonSetLabelTextDeprecatedPropertyP(void)
1317 ToolkitTestApplication application;
1318 tet_infoline(" UtcDaliButtonSetLabelTextDeprecatedPropertyP");
1320 const std::string TEST_LABEL1 = "test label one";
1321 const std::string TEST_LABEL2 = "test label two";
1323 Button button = PushButton::New();
1325 button.SetProperty( Toolkit::Button::Property::LABEL,
1326 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
1327 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1330 button.SetProperty( Button::Property::LABEL_TEXT, TEST_LABEL1 );
1332 std::string labelText = button.GetProperty<std::string>( Button::Property::LABEL_TEXT );
1334 DALI_TEST_EQUALS( labelText, TEST_LABEL1, TEST_LOCATION );
1336 Property::Map propertyMap;
1337 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT );
1338 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, TEST_LABEL2 );
1339 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
1340 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
1341 button.SetProperty( Button::Property::LABEL, propertyMap );
1343 labelText = button.GetProperty<std::string>( Button::Property::LABEL_TEXT );
1345 DALI_TEST_EQUALS( labelText, TEST_LABEL2, TEST_LOCATION );