2 * Copyright (c) 2019 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>
33 using namespace Toolkit;
36 void utc_dali_toolkit_button_startup(void)
38 test_return_value = TET_UNDEF;
41 void utc_dali_toolkit_button_cleanup(void)
43 test_return_value = TET_PASS;
48 static bool gIsCalledButtonCallback = false;
49 static bool gIsCalledChildButtonCallback = false;
51 static bool ButtonCallback( Button button )
53 gIsCalledButtonCallback = true;
57 static bool ChildButtonCallback( Button button )
59 gIsCalledChildButtonCallback = true;
63 static std::string GetButtonText( Button button )
65 Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
67 Property::Map *labelProperty = value.GetMap();
69 std::string textLabel;
73 Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
74 value->Get( textLabel );
80 struct CallbackFunctor
82 CallbackFunctor(bool* callbackFlag)
83 : mCallbackFlag( callbackFlag )
89 *mCallbackFlag = true;
94 Dali::Integration::Point GetPointDownInside()
96 Dali::Integration::Point point;
97 point.SetState( PointState::DOWN );
98 point.SetScreenPosition( Vector2( 240, 400 ) );
102 Dali::Integration::Point GetPointUpInside()
104 Dali::Integration::Point point;
105 point.SetState( PointState::UP );
106 point.SetScreenPosition( Vector2( 240, 400 ) );
110 Dali::Integration::Point GetPointLeave()
112 Dali::Integration::Point point;
113 point.SetState( PointState::LEAVE );
114 point.SetScreenPosition( Vector2( 240, 400 ) );
118 Dali::Integration::Point GetPointEnter()
120 Dali::Integration::Point point;
121 point.SetState( PointState::MOTION );
122 point.SetScreenPosition( Vector2( 240, 400 ) );
126 Dali::Integration::Point GetPointDownOutside()
128 Dali::Integration::Point point;
129 point.SetState( PointState::DOWN );
130 point.SetScreenPosition( Vector2( 10, 10 ) );
134 Dali::Integration::Point GetPointUpOutside()
136 Dali::Integration::Point point;
137 point.SetState( PointState::UP );
138 point.SetScreenPosition( Vector2( 10, 10 ) );
144 int UtcDaliButtonConstructorP(void)
146 TestApplication application;
150 DALI_TEST_CHECK( !button );
154 int UtcDaliButtonCopyConstructorP(void)
156 TestApplication application;
158 // Initialize an object, ref count == 1
159 Button button = PushButton::New();
161 Button copy( button );
162 DALI_TEST_CHECK( copy );
166 int UtcDaliButtonAssignmentOperatorP(void)
168 TestApplication application;
170 Button button = PushButton::New();
172 Button copy( button );
173 DALI_TEST_CHECK( copy );
175 DALI_TEST_CHECK( button == copy );
179 int UtcDaliButtonDownCastP(void)
181 TestApplication application;
183 Button button = PushButton::New();
185 BaseHandle object(button);
187 Button button2 = Button::DownCast( object );
188 DALI_TEST_CHECK(button2);
190 Button button3 = DownCast< Button >(object);
191 DALI_TEST_CHECK(button3);
195 int UtcDaliButtonDownCastN(void)
197 TestApplication application;
199 BaseHandle unInitializedObject;
201 Button button1 = Button::DownCast( unInitializedObject );
202 DALI_TEST_CHECK( !button1 );
204 Button button2 = DownCast< Button >( unInitializedObject );
205 DALI_TEST_CHECK( !button2 );
209 int UtcDaliButtonDisabledPropertyP(void)
211 ToolkitTestApplication application;
213 Button button = PushButton::New();
216 button.SetProperty( button.GetPropertyIndex("disabled"), true );
218 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), true, TEST_LOCATION );
220 button.SetProperty( button.GetPropertyIndex("disabled"), false );
222 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), false, TEST_LOCATION );
224 button.SetProperty( button.GetPropertyIndex("disabled"), true );
226 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), true, TEST_LOCATION );
228 button.SetProperty( button.GetPropertyIndex("disabled"), false );
230 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), false, TEST_LOCATION );
235 int UtcDaliButtonSetDisabledWithDifferentStates01P(void)
237 ToolkitTestApplication application;
239 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n");
241 Button button = PushButton::New();
243 bool SELECTED = true;
245 button.SetProperty( Button::Property::TOGGLABLE, true);
246 button.SetProperty( Button::Property::SELECTED, SELECTED );
248 button.SetProperty( Button::Property::DISABLED, true);
250 tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n");
251 button.SetProperty( Button::Property::SELECTED, !SELECTED );
253 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
255 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
260 int UtcDaliButtonSetDisabledWithDifferentStates02P(void)
262 ToolkitTestApplication application;
264 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n");
266 Button button = PushButton::New();
268 bool SELECTED = true;
270 button.SetProperty( Button::Property::TOGGLABLE, true );
271 button.SetProperty( Button::Property::SELECTED, SELECTED );
272 button.SetProperty( Button::Property::DISABLED, true );
274 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
275 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
276 tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n");
278 button.SetProperty( Button::Property::DISABLED, false);
279 button.SetProperty( Button::Property::SELECTED, !SELECTED );
281 isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
282 DALI_TEST_EQUALS( isSelected, !SELECTED , TEST_LOCATION );
287 int UtcDaliButtonPropertyGetLabelAlignment(void)
289 ToolkitTestApplication application;
290 tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
292 Button button = PushButton::New();
293 button.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END" );
294 DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
299 int UtcDaliButtonIsDisabledP(void)
301 ToolkitTestApplication application;
303 Button button = PushButton::New();
305 button.SetProperty( Button::Property::DISABLED, true);
307 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::DISABLED ), true, TEST_LOCATION );
309 button.SetProperty( Button::Property::DISABLED, false);
311 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::DISABLED ), false, TEST_LOCATION );
315 int UtcDaliButtonAutoRepeatingPropertyP(void)
317 ToolkitTestApplication application;
319 Button button = PushButton::New();
321 button.SetProperty( button.GetPropertyIndex("autoRepeating"), true );
323 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
325 button.SetProperty( button.GetPropertyIndex("autoRepeating"), false );
327 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
329 button.SetProperty( button.GetPropertyIndex("autoRepeating"), true );
331 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
336 int UtcDaliButtonIsAutoRepeatingP(void)
338 ToolkitTestApplication application;
340 Button button = PushButton::New();
342 button.SetProperty( Button::Property::AUTO_REPEATING, true);
344 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
346 button.SetProperty( Button::Property::AUTO_REPEATING, false);
348 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::AUTO_REPEATING ), false, TEST_LOCATION );
353 int UtcDaliButtonAutoRepeatingP(void)
355 ToolkitTestApplication application;
356 tet_infoline(" UtcDaliButtonPressedSignalP Setup Autorepeating and check multiple clicked signals received\n");
358 const float AUTO_REPEATING_DELAY = 0.15f;
360 Button button = PushButton::New();
361 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
362 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
363 button.SetPosition( 240, 400 );
364 button.SetSize( 100, 100 );
365 Stage::GetCurrent().Add( button );
367 application.SendNotification();
368 application.Render();
370 button.SetProperty( Toolkit::Button::Property::AUTO_REPEATING, true );
371 button.SetProperty( Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY );
372 // connect to its touch signal
373 ConnectionTracker* testTracker = new ConnectionTracker();
374 button.PressedSignal().Connect( &ButtonCallback );
375 button.ClickedSignal().Connect( &ButtonCallback );
376 bool clickedSignal = false;
377 bool pressedSignal = false;
378 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
379 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
381 Dali::Integration::TouchEvent event;
383 // Touch point down and up inside the button.
385 gIsCalledButtonCallback = false;
386 event = Dali::Integration::TouchEvent();
387 event.AddPoint( GetPointDownInside() );
388 application.ProcessEvent( event );
390 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
391 DALI_TEST_EQUALS( pressedSignal, true, TEST_LOCATION );
392 tet_infoline("Consume first clicked signal then wait\n");
394 gIsCalledButtonCallback = false;
395 Dali::Timer timer = Timer::New( AUTO_REPEATING_DELAY );
396 timer.MockEmitSignal();
397 application.Wait( AUTO_REPEATING_DELAY*2 );
398 DALI_TEST_EQUALS( clickedSignal, true, TEST_LOCATION );
399 tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n");
401 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
403 gIsCalledButtonCallback = false;
404 event = Dali::Integration::TouchEvent();
405 event.AddPoint( GetPointUpInside() );
406 application.ProcessEvent( event );
408 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
413 int UtcDaliButtonInitialAutoRepeatingDelayPropertyP(void)
415 ToolkitTestApplication application;
417 Button button = PushButton::New();
419 button.SetProperty( button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.5f );
421 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.5f, TEST_LOCATION );
423 button.SetProperty( button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.2f );
425 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.2f, TEST_LOCATION );
430 int UtcDaliButtonNextAutoRepeatingDelayPropertyP(void)
432 ToolkitTestApplication application;
434 Button button = PushButton::New();
436 button.SetProperty( button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.5f );
438 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.5f, TEST_LOCATION );
440 button.SetProperty( button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.2f );
442 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.2f, TEST_LOCATION );
446 int UtcDaliButtonTogglableButtonPropertyP(void)
448 ToolkitTestApplication application;
450 Button button = PushButton::New();
452 button.SetProperty( button.GetPropertyIndex("togglable"), true );
454 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("togglable")), true, TEST_LOCATION );
456 button.SetProperty( button.GetPropertyIndex("togglable"), false );
458 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("togglable")), false, TEST_LOCATION );
462 int UtcDaliButtonSelectedPropertyP(void)
464 ToolkitTestApplication application;
466 Button button = PushButton::New();
467 button.SetProperty( button.GetPropertyIndex("togglable"), true );
469 button.SetProperty( button.GetPropertyIndex("selected"), true );
471 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("selected")), true, TEST_LOCATION );
473 button.SetProperty( button.GetPropertyIndex("selected"), false );
475 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("selected")), false, TEST_LOCATION );
479 int UtcDaliButtonSetLabelStringWithPropertyMapP(void)
481 ToolkitTestApplication application;
483 Button button = PushButton::New();
484 button.SetProperty( Toolkit::Button::Property::LABEL,
485 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
486 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
487 .Add( Toolkit::TextVisual::Property::TEXT, "Button Label")
490 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
494 int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void)
496 ToolkitTestApplication application;
498 Button button = PushButton::New();
500 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string");
502 Property::Map textVisualMapInitial;
503 textVisualMapInitial["visualType"] = "TEXT";
504 textVisualMapInitial["pointSize"] = 15.0f;
505 textVisualMapInitial["text"] = "button label initial";
507 button.SetProperty( Button::Property::LABEL, textVisualMapInitial );
509 DALI_TEST_EQUALS( GetButtonText( button ), "button label initial", TEST_LOCATION );
511 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test");
513 Property::Map propertyMap;
514 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
515 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, "error if this is the final text" );
516 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
518 button.SetProperty( Button::Property::LABEL, propertyMap );
520 DALI_TEST_EQUALS( GetButtonText( button ), "error if this is the final text", TEST_LOCATION );
522 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test");
524 Property::Map textVisualMap;
525 textVisualMap["visualType"] = "TEXT";
526 textVisualMap["pointSize"] = 15.0f;
527 textVisualMap["text"] = "Button Label";
529 button.SetProperty( Toolkit::Button::Property::LABEL, textVisualMap );
531 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
535 int UtcDaliButtonSetLabelWithStringP(void)
537 ToolkitTestApplication application;
539 Button button = PushButton::New();
541 // Set default point size for text visual as style sheet not available.
542 button.SetProperty( Toolkit::Button::Property::LABEL,
543 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
544 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
547 button.SetProperty( Toolkit::Button::Property::LABEL, "Button Label" );
549 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
553 int UtcDaliButtonSetLabelPropertyP(void)
555 ToolkitTestApplication application;
557 tet_infoline(" UtcDaliButtonSetLabelPropertyP Set text label and then set again with new text");
560 const std::string TEST_LABEL1 = "test label one";
561 const std::string TEST_LABEL2 = "test label two";
563 Button button = PushButton::New();
565 button.SetProperty( Toolkit::Button::Property::LABEL,
566 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
567 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
568 .Add( Toolkit::TextVisual::Property::TEXT, TEST_LABEL1 )
571 DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL1, TEST_LOCATION );
573 Property::Map propertyMap;
574 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
575 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, TEST_LABEL2 );
576 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
577 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
578 button.SetProperty( Button::Property::LABEL, propertyMap );
580 DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL2, TEST_LOCATION );
585 int UtcDaliButtonPressedSignalP(void)
587 ToolkitTestApplication application;
588 tet_infoline(" UtcDaliButtonPressedSignalP");
590 Button button = PushButton::New();
591 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
592 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
593 button.SetPosition( 240, 400 );
594 button.SetSize( 100, 100 );
596 Stage::GetCurrent().Add( button );
598 application.SendNotification();
599 application.Render();
601 // connect to its touch signal
602 ConnectionTracker* testTracker = new ConnectionTracker();
603 button.PressedSignal().Connect( &ButtonCallback );
604 button.ReleasedSignal().Connect( &ButtonCallback );
605 bool pressedSignal = false;
606 bool releasedSignal = false;
607 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
608 button.ConnectSignal( testTracker, "released", CallbackFunctor(&releasedSignal) );
610 Dali::Integration::TouchEvent event;
612 // Test1. Touch point down and up inside the button.
614 gIsCalledButtonCallback = false;
615 event = Dali::Integration::TouchEvent();
616 event.AddPoint( GetPointDownInside() );
617 application.ProcessEvent( event );
619 DALI_TEST_CHECK( gIsCalledButtonCallback );
620 DALI_TEST_CHECK( pressedSignal );
622 gIsCalledButtonCallback = false;
623 event = Dali::Integration::TouchEvent();
624 event.AddPoint( GetPointUpInside() );
625 application.ProcessEvent( event );
627 DALI_TEST_CHECK( gIsCalledButtonCallback );
628 DALI_TEST_CHECK( releasedSignal );
630 // Test2. Touch point down and up outside the button.
632 pressedSignal = false;
633 releasedSignal = false;
634 gIsCalledButtonCallback = false;
635 event = Dali::Integration::TouchEvent();
636 event.AddPoint( GetPointDownOutside() );
637 application.ProcessEvent( event );
639 DALI_TEST_CHECK( !gIsCalledButtonCallback );
640 DALI_TEST_CHECK( !pressedSignal );
642 gIsCalledButtonCallback = false;
643 event = Dali::Integration::TouchEvent();
644 event.AddPoint( GetPointUpOutside() );
645 application.ProcessEvent( event );
647 DALI_TEST_CHECK( !gIsCalledButtonCallback );
648 DALI_TEST_CHECK( !releasedSignal );
650 // Test3. Touch point down inside and up outside the button.
652 gIsCalledButtonCallback = false;
653 event = Dali::Integration::TouchEvent();
654 event.AddPoint( GetPointDownInside() );
655 application.ProcessEvent( event );
657 DALI_TEST_CHECK( gIsCalledButtonCallback );
659 gIsCalledButtonCallback = false;
660 event = Dali::Integration::TouchEvent();
661 event.AddPoint( GetPointLeave() );
662 application.ProcessEvent( event );
664 event = Dali::Integration::TouchEvent();
665 event.AddPoint( GetPointUpOutside() );
666 application.ProcessEvent( event );
668 DALI_TEST_CHECK( gIsCalledButtonCallback );
670 // Test4. Touch point down outside and up inside the button.
672 gIsCalledButtonCallback = false;
673 event = Dali::Integration::TouchEvent();
674 event.AddPoint( GetPointDownOutside() );
675 application.ProcessEvent( event );
677 DALI_TEST_CHECK( !gIsCalledButtonCallback );
679 gIsCalledButtonCallback = false;
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( !gIsCalledButtonCallback );
692 int UtcDaliButtonClickedSignalP(void)
694 ToolkitTestApplication application;
695 tet_infoline(" UtcDaliButtonClickedSignalP");
697 Button button = PushButton::New();
698 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
699 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
700 button.SetPosition( 240, 400 );
701 button.SetSize( 100, 100 );
703 Stage::GetCurrent().Add( button );
705 application.SendNotification();
706 application.Render();
708 // connect to its touch signal
709 button.ClickedSignal().Connect( &ButtonCallback );
710 bool clickedSignal = false;
711 ConnectionTracker* testTracker = new ConnectionTracker();
712 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
714 Dali::Integration::TouchEvent event;
716 // Test1. Touch point down and up inside the button.
718 gIsCalledButtonCallback = false;
719 event = Dali::Integration::TouchEvent();
720 event.AddPoint( GetPointDownInside() );
721 application.ProcessEvent( event );
723 event = Dali::Integration::TouchEvent();
724 event.AddPoint( GetPointUpInside() );
725 application.ProcessEvent( event );
727 DALI_TEST_CHECK( gIsCalledButtonCallback );
728 DALI_TEST_CHECK( clickedSignal );
730 // Test2. Touch point down and up outside the button.
732 gIsCalledButtonCallback = false;
733 clickedSignal = false;
734 event = Dali::Integration::TouchEvent();
735 event.AddPoint( GetPointDownOutside() );
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 // Test3. Touch point down inside and up outside the button.
747 gIsCalledButtonCallback = false;
748 clickedSignal = false;
749 event = Dali::Integration::TouchEvent();
750 event.AddPoint( GetPointDownInside() );
751 application.ProcessEvent( event );
753 event = Dali::Integration::TouchEvent();
754 event.AddPoint( GetPointLeave() );
755 application.ProcessEvent( event );
757 event = Dali::Integration::TouchEvent();
758 event.AddPoint( GetPointUpOutside() );
759 application.ProcessEvent( event );
761 DALI_TEST_CHECK( !gIsCalledButtonCallback );
762 DALI_TEST_CHECK( !clickedSignal );
764 // Test4. Touch point down outside and up inside the button.
766 gIsCalledButtonCallback = false;
767 clickedSignal = false;
768 event = Dali::Integration::TouchEvent();
769 event.AddPoint( GetPointDownOutside() );
770 application.ProcessEvent( event );
772 event = Dali::Integration::TouchEvent();
773 event.AddPoint( GetPointEnter() );
774 application.ProcessEvent( event );
776 event = Dali::Integration::TouchEvent();
777 event.AddPoint( GetPointUpInside() );
778 application.ProcessEvent( event );
780 DALI_TEST_CHECK( !gIsCalledButtonCallback );
781 DALI_TEST_CHECK( !clickedSignal );
785 int UtcDaliButtonStateChangedSignalP(void)
787 ToolkitTestApplication application;
788 tet_infoline(" UtcDaliButtonStateChangedSignalP");
790 Button button = PushButton::New();
792 button.SetProperty( Button::Property::TOGGLABLE, true);
794 Stage::GetCurrent().Add( button );
796 application.SendNotification();
797 application.Render();
799 // connect to its signal
800 button.StateChangedSignal().Connect( &ButtonCallback );
801 bool stateChangedSignal = false;
802 ConnectionTracker* testTracker = new ConnectionTracker();
803 button.ConnectSignal( testTracker, "stateChanged", CallbackFunctor(&stateChangedSignal) );
805 gIsCalledButtonCallback = false;
806 button.SetProperty( Button::Property::SELECTED, true);
808 DALI_TEST_CHECK( gIsCalledButtonCallback );
809 DALI_TEST_CHECK( stateChangedSignal );
811 gIsCalledButtonCallback = false;
812 stateChangedSignal = false;
814 button.SetProperty( Button::Property::SELECTED, false);
815 DALI_TEST_CHECK( gIsCalledButtonCallback );
816 DALI_TEST_CHECK( stateChangedSignal );
820 int UtcDaliButtonSetProperty(void)
822 tet_infoline("UtcDaliButtonSetProperty: ");
823 ToolkitTestApplication application;
825 PushButton pushButton = PushButton::New();
827 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
829 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( pushButton.GetPropertyIndex("disabled")), false, TEST_LOCATION );
831 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
832 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( pushButton.GetPropertyIndex("disabled")), true, TEST_LOCATION );
837 int UtcDaliButtonEventConsumption(void)
843 * Child parented and positioned under parent.
844 * Touch up and down performed on child.
845 * Should only trigger signal on child.
848 ToolkitTestApplication application;
850 Button parentButton = PushButton::New();
851 parentButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
852 parentButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
853 parentButton.SetSize( 20, 20 );
854 Stage::GetCurrent().Add( parentButton );
856 Button childButton = PushButton::New();
857 childButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
858 childButton.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
859 childButton.SetSize( 20, 20 );
860 parentButton.Add( childButton );
862 // Reset signal flags
863 gIsCalledChildButtonCallback = false;
864 gIsCalledButtonCallback = false;
866 parentButton.ClickedSignal().Connect( &ButtonCallback );
867 childButton.ClickedSignal().Connect( &ChildButtonCallback );
869 // Peform a button click at coordinates (10,30) which is the child.
870 Dali::Integration::TouchEvent event;
871 event = Dali::Integration::TouchEvent();
872 Dali::Integration::Point point;
873 point.SetState( PointState::DOWN );
874 point.SetScreenPosition( Vector2( 10, 30 ) );
875 event.AddPoint( point );
876 // flush the queue and render once
877 application.SendNotification();
878 application.Render();
879 application.ProcessEvent( event );
881 event = Dali::Integration::TouchEvent();
882 point.SetState( PointState::UP );
883 point.SetScreenPosition( Vector2( 10, 30 ) );
884 event.AddPoint( point );
885 // flush the queue and render once
886 application.SendNotification();
887 application.Render();
888 application.ProcessEvent( event );
890 DALI_TEST_EQUALS( gIsCalledChildButtonCallback, true, TEST_LOCATION );
891 DALI_TEST_EQUALS( ! gIsCalledButtonCallback, true, TEST_LOCATION );
896 int UtcDaliButtonRelease(void)
899 * Down event followed by interrupted event should signal Release.
902 ToolkitTestApplication application;
904 Button parentButton = PushButton::New();
905 parentButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
906 parentButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
907 parentButton.SetSize( 20, 20 );
908 Stage::GetCurrent().Add( parentButton );
909 parentButton.ReleasedSignal().Connect( &ButtonCallback );
911 // Reset signal flags
912 gIsCalledButtonCallback = false;
914 // Peform a button down and then button interrupted at coordinates (10,10).
915 Dali::Integration::TouchEvent event;
916 event = Dali::Integration::TouchEvent();
917 Dali::Integration::Point point;
918 point.SetState( PointState::DOWN );
919 point.SetScreenPosition( Vector2( 10, 10 ) );
920 event.AddPoint( point );
921 // flush the queue and render once
922 application.SendNotification();
923 application.Render();
924 application.ProcessEvent( event );
926 event = Dali::Integration::TouchEvent();
927 point.SetState( PointState::INTERRUPTED );
928 event.AddPoint( point );
929 // flush the queue and render once
930 application.SendNotification();
931 application.Render();
932 application.ProcessEvent( event );
934 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
939 int UtcDaliButtonMultiTouch(void)
942 * Down event followed by a multi touch point event should signal Release.
945 ToolkitTestApplication application;
947 Button button = PushButton::New();
948 button.SetProperty( Button::Property::TOGGLABLE, true);
950 button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
951 button.SetParentOrigin( ParentOrigin::TOP_LEFT );
952 button.SetSize( 20, 20 );
953 Stage::GetCurrent().Add( button );
954 button.ReleasedSignal().Connect( &ButtonCallback );
956 // Reset signal flags
957 gIsCalledButtonCallback = false;
959 // Peform a button down and then button interrupted at coordinates (10,10).
960 Dali::Integration::TouchEvent downEvent;
961 downEvent = Dali::Integration::TouchEvent();
962 Dali::Integration::Point point;
965 point.SetState( PointState::DOWN );
966 point.SetScreenPosition( Vector2( 15, 15 ) );
967 downEvent.AddPoint( point );
968 // flush the queue and render once
969 application.SendNotification();
970 application.Render();
971 application.ProcessEvent( downEvent );
974 Dali::Integration::TouchEvent upEvent;
975 upEvent = Dali::Integration::TouchEvent();
976 point.SetState( PointState::UP );
977 point.SetScreenPosition( Vector2( 15, 15 ) );
978 upEvent.AddPoint( point );
979 // flush the queue and render once
980 application.SendNotification();
981 application.Render();
982 application.ProcessEvent( upEvent );
984 tet_infoline("Button should now be selected\n");
985 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
986 DALI_TEST_EQUALS( isSelected, true, TEST_LOCATION );
989 Dali::Integration::TouchEvent multiEvent;
990 multiEvent = Dali::Integration::TouchEvent();
991 point.SetState( PointState::DOWN );
992 point.SetScreenPosition( Vector2( 10, 10 ) );
993 multiEvent.AddPoint( point );
996 point.SetState( PointState::DOWN );
997 point.SetScreenPosition( Vector2( 15, 15 ) );
998 multiEvent.AddPoint( point );
1000 tet_infoline("Before a multi touch event\n");
1002 // flush the queue and render once
1003 application.SendNotification();
1004 application.Render();
1005 application.ProcessEvent( multiEvent );
1007 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );