2 * Copyright (c) 2020 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 ToolkitTestApplication application;
150 DALI_TEST_CHECK( !button );
154 int UtcDaliButtonCopyConstructorP(void)
156 ToolkitTestApplication application;
158 // Initialize an object, ref count == 1
159 Button button = PushButton::New();
161 Button copy( button );
162 DALI_TEST_CHECK( copy );
166 int UtcDaliButtonMoveConstructor(void)
168 ToolkitTestApplication application;
170 Button button = PushButton::New();
171 DALI_TEST_EQUALS( 1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION );
172 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), false , TEST_LOCATION );
173 button.SetProperty( Button::Property::TOGGLABLE, true );
174 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), true , TEST_LOCATION );
176 Button moved = std::move( button );
177 DALI_TEST_CHECK( moved );
178 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
179 DALI_TEST_EQUALS( moved.GetProperty<bool>( Button::Property::TOGGLABLE ), true , TEST_LOCATION );
180 DALI_TEST_CHECK( !button );
185 int UtcDaliButtonAssignmentOperatorP(void)
187 ToolkitTestApplication application;
189 Button button = PushButton::New();
191 Button copy( button );
192 DALI_TEST_CHECK( copy );
194 DALI_TEST_CHECK( button == copy );
198 int UtcDaliButtonMoveAssignment(void)
200 ToolkitTestApplication application;
202 Button button = PushButton::New();
203 DALI_TEST_EQUALS( 1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION );
204 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), false , TEST_LOCATION );
205 button.SetProperty( Button::Property::TOGGLABLE, true );
206 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::TOGGLABLE ), true , TEST_LOCATION );
209 moved = std::move( button );
210 DALI_TEST_CHECK( moved );
211 DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
212 DALI_TEST_EQUALS( moved.GetProperty<bool>( Button::Property::TOGGLABLE ), true , TEST_LOCATION );
213 DALI_TEST_CHECK( !button );
218 int UtcDaliButtonDownCastP(void)
220 ToolkitTestApplication application;
222 Button button = PushButton::New();
224 BaseHandle object(button);
226 Button button2 = Button::DownCast( object );
227 DALI_TEST_CHECK(button2);
229 Button button3 = DownCast< Button >(object);
230 DALI_TEST_CHECK(button3);
234 int UtcDaliButtonDownCastN(void)
236 ToolkitTestApplication application;
238 BaseHandle unInitializedObject;
240 Button button1 = Button::DownCast( unInitializedObject );
241 DALI_TEST_CHECK( !button1 );
243 Button button2 = DownCast< Button >( unInitializedObject );
244 DALI_TEST_CHECK( !button2 );
248 int UtcDaliButtonDisabledPropertyP(void)
250 ToolkitTestApplication application;
252 Button button = PushButton::New();
255 button.SetProperty( button.GetPropertyIndex("disabled"), true );
257 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), true, TEST_LOCATION );
259 button.SetProperty( button.GetPropertyIndex("disabled"), false );
261 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), false, TEST_LOCATION );
263 button.SetProperty( button.GetPropertyIndex("disabled"), true );
265 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), true, TEST_LOCATION );
267 button.SetProperty( button.GetPropertyIndex("disabled"), false );
269 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), false, TEST_LOCATION );
274 int UtcDaliButtonSetDisabledWithDifferentStates01P(void)
276 ToolkitTestApplication application;
278 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n");
280 Button button = PushButton::New();
282 bool SELECTED = true;
284 button.SetProperty( Button::Property::TOGGLABLE, true);
285 button.SetProperty( Button::Property::SELECTED, SELECTED );
287 button.SetProperty( Button::Property::DISABLED, true);
289 tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n");
290 button.SetProperty( Button::Property::SELECTED, !SELECTED );
292 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
294 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
299 int UtcDaliButtonSetDisabledWithDifferentStates02P(void)
301 ToolkitTestApplication application;
303 tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n");
305 Button button = PushButton::New();
307 bool SELECTED = true;
309 button.SetProperty( Button::Property::TOGGLABLE, true );
310 button.SetProperty( Button::Property::SELECTED, SELECTED );
311 button.SetProperty( Button::Property::DISABLED, true );
313 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
314 DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
315 tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n");
317 button.SetProperty( Button::Property::DISABLED, false);
318 button.SetProperty( Button::Property::SELECTED, !SELECTED );
320 isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
321 DALI_TEST_EQUALS( isSelected, !SELECTED , TEST_LOCATION );
326 int UtcDaliButtonPropertyGetLabelAlignment(void)
328 ToolkitTestApplication application;
329 tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
331 Button button = PushButton::New();
332 button.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END" );
333 DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
338 int UtcDaliButtonIsDisabledP(void)
340 ToolkitTestApplication application;
342 Button button = PushButton::New();
344 button.SetProperty( Button::Property::DISABLED, true);
346 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::DISABLED ), true, TEST_LOCATION );
348 button.SetProperty( Button::Property::DISABLED, false);
350 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::DISABLED ), false, TEST_LOCATION );
354 int UtcDaliButtonAutoRepeatingPropertyP(void)
356 ToolkitTestApplication application;
358 Button button = PushButton::New();
360 button.SetProperty( button.GetPropertyIndex("autoRepeating"), true );
362 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
364 button.SetProperty( button.GetPropertyIndex("autoRepeating"), false );
366 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
368 button.SetProperty( button.GetPropertyIndex("autoRepeating"), true );
370 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
375 int UtcDaliButtonIsAutoRepeatingP(void)
377 ToolkitTestApplication application;
379 Button button = PushButton::New();
381 button.SetProperty( Button::Property::AUTO_REPEATING, true);
383 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
385 button.SetProperty( Button::Property::AUTO_REPEATING, false);
387 DALI_TEST_EQUALS( button.GetProperty<bool>( Button::Property::AUTO_REPEATING ), false, TEST_LOCATION );
392 int UtcDaliButtonAutoRepeatingP(void)
394 ToolkitTestApplication application;
395 tet_infoline(" UtcDaliButtonPressedSignalP Setup Autorepeating and check multiple clicked signals received\n");
397 const float AUTO_REPEATING_DELAY = 0.15f;
399 Button button = PushButton::New();
400 button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
401 button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
402 button.SetProperty( Actor::Property::POSITION, Vector2( 240, 400 ));
403 button.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
404 application.GetScene().Add( button );
406 application.SendNotification();
407 application.Render();
409 button.SetProperty( Toolkit::Button::Property::AUTO_REPEATING, true );
410 button.SetProperty( Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY );
411 // connect to its touch signal
412 ConnectionTracker* testTracker = new ConnectionTracker();
413 button.PressedSignal().Connect( &ButtonCallback );
414 button.ClickedSignal().Connect( &ButtonCallback );
415 bool clickedSignal = false;
416 bool pressedSignal = false;
417 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
418 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
420 Dali::Integration::TouchEvent event;
422 // Touch point down and up inside the button.
424 gIsCalledButtonCallback = false;
425 event = Dali::Integration::TouchEvent();
426 event.AddPoint( GetPointDownInside() );
427 application.ProcessEvent( event );
429 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
430 DALI_TEST_EQUALS( pressedSignal, true, TEST_LOCATION );
431 tet_infoline("Consume first clicked signal then wait\n");
433 gIsCalledButtonCallback = false;
434 Dali::Timer timer = Timer::New( AUTO_REPEATING_DELAY );
435 timer.MockEmitSignal();
436 application.Wait( AUTO_REPEATING_DELAY*2 );
437 DALI_TEST_EQUALS( clickedSignal, true, TEST_LOCATION );
438 tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n");
440 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
442 gIsCalledButtonCallback = false;
443 event = Dali::Integration::TouchEvent();
444 event.AddPoint( GetPointUpInside() );
445 application.ProcessEvent( event );
447 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
452 int UtcDaliButtonInitialAutoRepeatingDelayPropertyP(void)
454 ToolkitTestApplication application;
456 Button button = PushButton::New();
458 button.SetProperty( button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.5f );
460 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.5f, TEST_LOCATION );
462 button.SetProperty( button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.2f );
464 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.2f, TEST_LOCATION );
469 int UtcDaliButtonNextAutoRepeatingDelayPropertyP(void)
471 ToolkitTestApplication application;
473 Button button = PushButton::New();
475 button.SetProperty( button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.5f );
477 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.5f, TEST_LOCATION );
479 button.SetProperty( button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.2f );
481 DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.2f, TEST_LOCATION );
485 int UtcDaliButtonTogglableButtonPropertyP(void)
487 ToolkitTestApplication application;
489 Button button = PushButton::New();
491 button.SetProperty( button.GetPropertyIndex("togglable"), true );
493 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("togglable")), true, TEST_LOCATION );
495 button.SetProperty( button.GetPropertyIndex("togglable"), false );
497 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("togglable")), false, TEST_LOCATION );
501 int UtcDaliButtonSelectedPropertyP(void)
503 ToolkitTestApplication application;
505 Button button = PushButton::New();
506 button.SetProperty( button.GetPropertyIndex("togglable"), true );
508 button.SetProperty( button.GetPropertyIndex("selected"), true );
510 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("selected")), true, TEST_LOCATION );
512 button.SetProperty( button.GetPropertyIndex("selected"), false );
514 DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("selected")), false, TEST_LOCATION );
518 int UtcDaliButtonSetLabelStringWithPropertyMapP(void)
520 ToolkitTestApplication application;
522 Button button = PushButton::New();
523 button.SetProperty( Toolkit::Button::Property::LABEL,
524 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
525 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
526 .Add( Toolkit::TextVisual::Property::TEXT, "Button Label")
529 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
533 int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void)
535 ToolkitTestApplication application;
537 Button button = PushButton::New();
539 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string");
541 Property::Map textVisualMapInitial;
542 textVisualMapInitial["visualType"] = "TEXT";
543 textVisualMapInitial["pointSize"] = 15.0f;
544 textVisualMapInitial["text"] = "button label initial";
546 button.SetProperty( Button::Property::LABEL, textVisualMapInitial );
548 DALI_TEST_EQUALS( GetButtonText( button ), "button label initial", TEST_LOCATION );
550 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test");
552 Property::Map propertyMap;
553 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
554 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, "error if this is the final text" );
555 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
557 button.SetProperty( Button::Property::LABEL, propertyMap );
559 DALI_TEST_EQUALS( GetButtonText( button ), "error if this is the final text", TEST_LOCATION );
561 tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test");
563 Property::Map textVisualMap;
564 textVisualMap["visualType"] = "TEXT";
565 textVisualMap["pointSize"] = 15.0f;
566 textVisualMap["text"] = "Button Label";
568 button.SetProperty( Toolkit::Button::Property::LABEL, textVisualMap );
570 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
574 int UtcDaliButtonSetLabelWithStringP(void)
576 ToolkitTestApplication application;
578 Button button = PushButton::New();
580 // Set default point size for text visual as style sheet not available.
581 button.SetProperty( Toolkit::Button::Property::LABEL,
582 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
583 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
586 button.SetProperty( Toolkit::Button::Property::LABEL, "Button Label" );
588 DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
592 int UtcDaliButtonSetLabelPropertyP(void)
594 ToolkitTestApplication application;
596 tet_infoline(" UtcDaliButtonSetLabelPropertyP Set text label and then set again with new text");
599 const std::string TEST_LABEL1 = "test label one";
600 const std::string TEST_LABEL2 = "test label two";
602 Button button = PushButton::New();
604 button.SetProperty( Toolkit::Button::Property::LABEL,
605 Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
606 .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
607 .Add( Toolkit::TextVisual::Property::TEXT, TEST_LABEL1 )
610 DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL1, TEST_LOCATION );
612 Property::Map propertyMap;
613 propertyMap.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT );
614 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT, TEST_LABEL2 );
615 propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
616 propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
617 button.SetProperty( Button::Property::LABEL, propertyMap );
619 DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL2, TEST_LOCATION );
624 int UtcDaliButtonPressedSignalP(void)
626 ToolkitTestApplication application;
627 tet_infoline(" UtcDaliButtonPressedSignalP");
629 Button button = PushButton::New();
630 button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
631 button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
632 button.SetProperty( Actor::Property::POSITION, Vector2( 240, 400 ));
633 button.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
635 application.GetScene().Add( button );
637 application.SendNotification();
638 application.Render();
640 // connect to its touch signal
641 ConnectionTracker* testTracker = new ConnectionTracker();
642 button.PressedSignal().Connect( &ButtonCallback );
643 button.ReleasedSignal().Connect( &ButtonCallback );
644 bool pressedSignal = false;
645 bool releasedSignal = false;
646 button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
647 button.ConnectSignal( testTracker, "released", CallbackFunctor(&releasedSignal) );
649 Dali::Integration::TouchEvent event;
651 // Test1. Touch point down and up inside the button.
653 gIsCalledButtonCallback = false;
654 event = Dali::Integration::TouchEvent();
655 event.AddPoint( GetPointDownInside() );
656 application.ProcessEvent( event );
658 DALI_TEST_CHECK( gIsCalledButtonCallback );
659 DALI_TEST_CHECK( pressedSignal );
661 gIsCalledButtonCallback = false;
662 event = Dali::Integration::TouchEvent();
663 event.AddPoint( GetPointUpInside() );
664 application.ProcessEvent( event );
666 DALI_TEST_CHECK( gIsCalledButtonCallback );
667 DALI_TEST_CHECK( releasedSignal );
669 // Test2. Touch point down and up outside the button.
671 pressedSignal = false;
672 releasedSignal = false;
673 gIsCalledButtonCallback = false;
674 event = Dali::Integration::TouchEvent();
675 event.AddPoint( GetPointDownOutside() );
676 application.ProcessEvent( event );
678 DALI_TEST_CHECK( !gIsCalledButtonCallback );
679 DALI_TEST_CHECK( !pressedSignal );
681 gIsCalledButtonCallback = false;
682 event = Dali::Integration::TouchEvent();
683 event.AddPoint( GetPointUpOutside() );
684 application.ProcessEvent( event );
686 DALI_TEST_CHECK( !gIsCalledButtonCallback );
687 DALI_TEST_CHECK( !releasedSignal );
689 // Test3. Touch point down inside and up outside the button.
691 gIsCalledButtonCallback = false;
692 event = Dali::Integration::TouchEvent();
693 event.AddPoint( GetPointDownInside() );
694 application.ProcessEvent( event );
696 DALI_TEST_CHECK( gIsCalledButtonCallback );
698 gIsCalledButtonCallback = false;
699 event = Dali::Integration::TouchEvent();
700 event.AddPoint( GetPointLeave() );
701 application.ProcessEvent( event );
703 event = Dali::Integration::TouchEvent();
704 event.AddPoint( GetPointUpOutside() );
705 application.ProcessEvent( event );
707 DALI_TEST_CHECK( gIsCalledButtonCallback );
709 // Test4. Touch point down outside and up inside the button.
711 gIsCalledButtonCallback = false;
712 event = Dali::Integration::TouchEvent();
713 event.AddPoint( GetPointDownOutside() );
714 application.ProcessEvent( event );
716 DALI_TEST_CHECK( !gIsCalledButtonCallback );
718 gIsCalledButtonCallback = false;
719 event = Dali::Integration::TouchEvent();
720 event.AddPoint( GetPointEnter() );
721 application.ProcessEvent( event );
723 event = Dali::Integration::TouchEvent();
724 event.AddPoint( GetPointUpInside() );
725 application.ProcessEvent( event );
727 DALI_TEST_CHECK( !gIsCalledButtonCallback );
731 int UtcDaliButtonClickedSignalP(void)
733 ToolkitTestApplication application;
734 tet_infoline(" UtcDaliButtonClickedSignalP");
736 Button button = PushButton::New();
737 button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
738 button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
739 button.SetProperty( Actor::Property::POSITION, Vector2( 240, 400 ));
740 button.SetProperty( Actor::Property::SIZE, Vector2( 100, 100 ) );
742 application.GetScene().Add( button );
744 application.SendNotification();
745 application.Render();
747 // connect to its touch signal
748 button.ClickedSignal().Connect( &ButtonCallback );
749 bool clickedSignal = false;
750 ConnectionTracker* testTracker = new ConnectionTracker();
751 button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
753 Dali::Integration::TouchEvent event;
755 // Test1. Touch point down and up inside the button.
757 gIsCalledButtonCallback = false;
758 event = Dali::Integration::TouchEvent();
759 event.AddPoint( GetPointDownInside() );
760 application.ProcessEvent( event );
762 event = Dali::Integration::TouchEvent();
763 event.AddPoint( GetPointUpInside() );
764 application.ProcessEvent( event );
766 DALI_TEST_CHECK( gIsCalledButtonCallback );
767 DALI_TEST_CHECK( clickedSignal );
769 // Test2. Touch point down and up outside the button.
771 gIsCalledButtonCallback = false;
772 clickedSignal = false;
773 event = Dali::Integration::TouchEvent();
774 event.AddPoint( GetPointDownOutside() );
775 application.ProcessEvent( event );
777 event = Dali::Integration::TouchEvent();
778 event.AddPoint( GetPointUpOutside() );
779 application.ProcessEvent( event );
781 DALI_TEST_CHECK( !gIsCalledButtonCallback );
782 DALI_TEST_CHECK( !clickedSignal );
784 // Test3. Touch point down inside and up outside the button.
786 gIsCalledButtonCallback = false;
787 clickedSignal = false;
788 event = Dali::Integration::TouchEvent();
789 event.AddPoint( GetPointDownInside() );
790 application.ProcessEvent( event );
792 event = Dali::Integration::TouchEvent();
793 event.AddPoint( GetPointLeave() );
794 application.ProcessEvent( event );
796 event = Dali::Integration::TouchEvent();
797 event.AddPoint( GetPointUpOutside() );
798 application.ProcessEvent( event );
800 DALI_TEST_CHECK( !gIsCalledButtonCallback );
801 DALI_TEST_CHECK( !clickedSignal );
803 // Test4. Touch point down outside and up inside the button.
805 gIsCalledButtonCallback = false;
806 clickedSignal = false;
807 event = Dali::Integration::TouchEvent();
808 event.AddPoint( GetPointDownOutside() );
809 application.ProcessEvent( event );
811 event = Dali::Integration::TouchEvent();
812 event.AddPoint( GetPointEnter() );
813 application.ProcessEvent( event );
815 event = Dali::Integration::TouchEvent();
816 event.AddPoint( GetPointUpInside() );
817 application.ProcessEvent( event );
819 DALI_TEST_CHECK( !gIsCalledButtonCallback );
820 DALI_TEST_CHECK( !clickedSignal );
824 int UtcDaliButtonStateChangedSignalP(void)
826 ToolkitTestApplication application;
827 tet_infoline(" UtcDaliButtonStateChangedSignalP");
829 Button button = PushButton::New();
831 button.SetProperty( Button::Property::TOGGLABLE, true);
833 application.GetScene().Add( button );
835 application.SendNotification();
836 application.Render();
838 // connect to its signal
839 button.StateChangedSignal().Connect( &ButtonCallback );
840 bool stateChangedSignal = false;
841 ConnectionTracker* testTracker = new ConnectionTracker();
842 button.ConnectSignal( testTracker, "stateChanged", CallbackFunctor(&stateChangedSignal) );
844 gIsCalledButtonCallback = false;
845 button.SetProperty( Button::Property::SELECTED, true);
847 DALI_TEST_CHECK( gIsCalledButtonCallback );
848 DALI_TEST_CHECK( stateChangedSignal );
850 gIsCalledButtonCallback = false;
851 stateChangedSignal = false;
853 button.SetProperty( Button::Property::SELECTED, false);
854 DALI_TEST_CHECK( gIsCalledButtonCallback );
855 DALI_TEST_CHECK( stateChangedSignal );
859 int UtcDaliButtonSetProperty(void)
861 tet_infoline("UtcDaliButtonSetProperty: ");
862 ToolkitTestApplication application;
864 PushButton pushButton = PushButton::New();
866 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
868 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( pushButton.GetPropertyIndex("disabled")), false, TEST_LOCATION );
870 pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
871 DALI_TEST_EQUALS( pushButton.GetProperty<bool>( pushButton.GetPropertyIndex("disabled")), true, TEST_LOCATION );
876 int UtcDaliButtonEventConsumption(void)
882 * Child parented and positioned under parent.
883 * Touch up and down performed on child.
884 * Should only trigger signal on child.
887 ToolkitTestApplication application;
889 Button parentButton = PushButton::New();
890 parentButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
891 parentButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
892 parentButton.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) );
893 application.GetScene().Add( parentButton );
895 Button childButton = PushButton::New();
896 childButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
897 childButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::BOTTOM_LEFT );
898 childButton.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) );
899 parentButton.Add( childButton );
901 // Reset signal flags
902 gIsCalledChildButtonCallback = false;
903 gIsCalledButtonCallback = false;
905 parentButton.ClickedSignal().Connect( &ButtonCallback );
906 childButton.ClickedSignal().Connect( &ChildButtonCallback );
908 // Peform a button click at coordinates (10,30) which is the child.
909 Dali::Integration::TouchEvent event;
910 event = Dali::Integration::TouchEvent();
911 Dali::Integration::Point point;
912 point.SetState( PointState::DOWN );
913 point.SetScreenPosition( Vector2( 10, 30 ) );
914 event.AddPoint( point );
915 // flush the queue and render once
916 application.SendNotification();
917 application.Render();
918 application.ProcessEvent( event );
920 event = Dali::Integration::TouchEvent();
921 point.SetState( PointState::UP );
922 point.SetScreenPosition( Vector2( 10, 30 ) );
923 event.AddPoint( point );
924 // flush the queue and render once
925 application.SendNotification();
926 application.Render();
927 application.ProcessEvent( event );
929 DALI_TEST_EQUALS( gIsCalledChildButtonCallback, true, TEST_LOCATION );
930 DALI_TEST_EQUALS( ! gIsCalledButtonCallback, true, TEST_LOCATION );
935 int UtcDaliButtonRelease(void)
938 * Down event followed by interrupted event should signal Release.
941 ToolkitTestApplication application;
943 Button parentButton = PushButton::New();
944 parentButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
945 parentButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
946 parentButton.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) );
947 application.GetScene().Add( parentButton );
948 parentButton.ReleasedSignal().Connect( &ButtonCallback );
950 // Reset signal flags
951 gIsCalledButtonCallback = false;
953 // Peform a button down and then button interrupted at coordinates (10,10).
954 Dali::Integration::TouchEvent event;
955 event = Dali::Integration::TouchEvent();
956 Dali::Integration::Point point;
957 point.SetState( PointState::DOWN );
958 point.SetScreenPosition( Vector2( 10, 10 ) );
959 event.AddPoint( point );
960 // flush the queue and render once
961 application.SendNotification();
962 application.Render();
963 application.ProcessEvent( event );
965 event = Dali::Integration::TouchEvent();
966 point.SetState( PointState::INTERRUPTED );
967 event.AddPoint( point );
968 // flush the queue and render once
969 application.SendNotification();
970 application.Render();
971 application.ProcessEvent( event );
973 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
978 int UtcDaliButtonMultiTouch(void)
981 * Down event followed by a multi touch point event should signal Release.
984 ToolkitTestApplication application;
986 Button button = PushButton::New();
987 button.SetProperty( Button::Property::TOGGLABLE, true);
989 button.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
990 button.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
991 button.SetProperty( Actor::Property::SIZE, Vector2( 20, 20 ) );
992 application.GetScene().Add( button );
993 button.ReleasedSignal().Connect( &ButtonCallback );
995 // Reset signal flags
996 gIsCalledButtonCallback = false;
998 // Peform a button down and then button interrupted at coordinates (10,10).
999 Dali::Integration::TouchEvent downEvent;
1000 downEvent = Dali::Integration::TouchEvent();
1001 Dali::Integration::Point point;
1004 point.SetState( PointState::DOWN );
1005 point.SetScreenPosition( Vector2( 15, 15 ) );
1006 downEvent.AddPoint( point );
1007 // flush the queue and render once
1008 application.SendNotification();
1009 application.Render();
1010 application.ProcessEvent( downEvent );
1013 Dali::Integration::TouchEvent upEvent;
1014 upEvent = Dali::Integration::TouchEvent();
1015 point.SetState( PointState::UP );
1016 point.SetScreenPosition( Vector2( 15, 15 ) );
1017 upEvent.AddPoint( point );
1018 // flush the queue and render once
1019 application.SendNotification();
1020 application.Render();
1021 application.ProcessEvent( upEvent );
1023 tet_infoline("Button should now be selected\n");
1024 bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
1025 DALI_TEST_EQUALS( isSelected, true, TEST_LOCATION );
1028 Dali::Integration::TouchEvent multiEvent;
1029 multiEvent = Dali::Integration::TouchEvent();
1030 point.SetState( PointState::DOWN );
1031 point.SetScreenPosition( Vector2( 10, 10 ) );
1032 multiEvent.AddPoint( point );
1035 point.SetState( PointState::DOWN );
1036 point.SetScreenPosition( Vector2( 15, 15 ) );
1037 multiEvent.AddPoint( point );
1039 tet_infoline("Before a multi touch event\n");
1041 // flush the queue and render once
1042 application.SendNotification();
1043 application.Render();
1044 application.ProcessEvent( multiEvent );
1046 DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );