2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
25 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
26 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
28 #include <dali-toolkit-test-suite-utils.h>
30 #include <dali-toolkit/internal/controls/buttons/button-impl.h>
33 using namespace Toolkit;
37 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
39 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
42 PixelBuffer* pixbuf = imageData.GetBuffer();
43 unsigned int size = width * height;
45 for( size_t i = 0; i < size; i++ )
47 pixbuf[i*4+0] = 0xFF * color.r;
48 pixbuf[i*4+1] = 0xFF * color.g;
49 pixbuf[i*4+2] = 0xFF * color.b;
50 pixbuf[i*4+3] = 0xFF * color.a;
58 static bool gPushButtonToggleState = false;
59 bool PushButtonToggled( Button button, bool toggled )
61 gPushButtonToggleState = toggled && ( toggled == static_cast<PushButton&>( button ).IsToggled() );
65 static bool gPushButtonPressed = false;
67 static bool PushButtonPressed( Button button )
69 gPushButtonPressed = true;
73 static bool gPushButtonReleased = false;
75 static bool PushButtonReleased( Button button )
77 gPushButtonReleased = true;
81 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
82 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
83 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
84 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
85 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
86 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
87 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
90 static void Startup();
91 static void Cleanup();
94 void (*tet_startup)() = Startup;
95 void (*tet_cleanup)() = Cleanup;
98 //////////////////////////////////////////////////////////
102 static bool gOnTouchPointInterrupted = false;
117 * Creates a Button to test if interrupt events are handled correctly.
119 class TETButton : public Button
122 // PushButton Pressed
123 typedef SignalV2< bool ( Button ) > PressedSignalV2;
125 PressedSignalV2& PressedSignal();
128 * Default constructor.
135 TETButton( const Button& button );
138 * Assignment operator.
140 TETButton& operator=( const TETButton& button );
143 * Creates and initializes a new button.
145 static TETButton New();
148 * Down cast to TETButton.
150 static TETButton DownCast( BaseHandle handle );
153 * Creates a handle using the Toolkit::Internal implementation.
154 * @param[in] implementation The Control implementation.
156 TETButton( Internal::TETButton& implementation );
159 * Allows the creation of this Control from an Internal::CustomActor pointer.
160 * @param[in] internal A pointer to the internal CustomActor.
162 TETButton( Dali::Internal::CustomActor* internal );
169 * Internal implementation
171 class TETButton : public Button
175 * Construct a new Button.
180 * A reference counted object may only be deleted by calling Unreference()
182 virtual ~TETButton();
185 * Creates an internal button.
187 static Toolkit::TETButton New();
190 * @return the pressed signal.
192 Toolkit::TETButton::PressedSignalV2& PressedSignal();
195 * Callback called when an interrupt events is received.
197 void OnTouchPointInterrupted();
200 * Callback received when a down event is received.
204 Toolkit::TETButton::PressedSignalV2 mPressedSignal; ///< Signal emitted when the button is pressed.
207 } // namespace Internal
209 TETButton::TETButton()
213 TETButton::TETButton( const Button& button )
218 TETButton& TETButton::operator=( const TETButton& button )
220 if( &button != this )
222 Button::operator=( button );
227 TETButton TETButton::New()
229 return Internal::TETButton::New();
232 TETButton TETButton::DownCast( BaseHandle handle )
234 return Control::DownCast<TETButton, Internal::TETButton>(handle);
237 TETButton::PressedSignalV2& TETButton::PressedSignal()
239 TETButton button( *this );
240 DALI_ASSERT_ALWAYS( button );
242 Dali::RefObject& handle = button.GetImplementation();
244 return static_cast<Toolkit::Internal::TETButton&>( handle ).PressedSignal();
247 TETButton::TETButton( Internal::TETButton& implementation )
248 : Button( implementation )
251 TETButton::TETButton( Dali::Internal::CustomActor* internal )
254 VerifyCustomActorPointer<Internal::TETButton>(internal);
260 TETButton::TETButton()
266 TETButton::~TETButton()
270 Toolkit::TETButton TETButton::New()
272 // Create the implementation, temporarily owned on stack
273 IntrusivePtr< TETButton > internalTETButton = new TETButton();
275 // Pass ownership to CustomActor
276 Dali::Toolkit::TETButton tetButton( *internalTETButton );
278 // Second-phase init of the implementation
279 // This can only be done after the CustomActor connection has been made...
280 internalTETButton->Initialize();
285 Toolkit::TETButton::PressedSignalV2& TETButton::PressedSignal()
287 return mPressedSignal;
290 void TETButton::OnButtonDown()
292 Toolkit::TETButton handle( GetOwner() );
295 mPressedSignal.Emit( handle );
298 void TETButton::OnTouchPointInterrupted()
300 gOnTouchPointInterrupted = true;
303 } // namespace Internal
305 } // namespace Toolkit
312 class TETButtonPressed : public Dali::ConnectionTracker
321 TETButtonPressed( Actor actor, Test test )
327 bool Callback( Button button )
333 mActor.SetSensitive( false );
338 std::cout <<"VISIBILITY false" << std::endl;
339 mActor.SetVisible( false );
354 static bool TestCallback(Actor actor, const TouchEvent& event)
361 //////////////////////////////////////////////////////////
364 POSITIVE_TC_IDX = 0x01,
368 #define MAX_NUMBER_OF_TESTS 10000
370 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
373 // Add test functionality for all APIs in the class (Positive and Negative)
374 TEST_FUNCTION( UtcDaliPushButtonSetGetAutoRepeating, POSITIVE_TC_IDX );
375 TEST_FUNCTION( UtcDaliPushButtonSetGetToggleButton, POSITIVE_TC_IDX );
376 TEST_FUNCTION( UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton, POSITIVE_TC_IDX );
377 TEST_FUNCTION( UtcDaliPushButtonSetGetToggled01, POSITIVE_TC_IDX );
378 TEST_FUNCTION( UtcDaliPushButtonSetGetToggled02, POSITIVE_TC_IDX );
379 TEST_FUNCTION( UtcDaliPushButtonSetGetAutorepeatingDelayValues01, POSITIVE_TC_IDX );
380 TEST_FUNCTION( UtcDaliPushButtonSetGetAutorepeatingDelayValues02, NEGATIVE_TC_IDX );
381 TEST_FUNCTION( UtcDaliPushButtonSetImages, POSITIVE_TC_IDX );
382 TEST_FUNCTION( UtcDaliPushButtonSetLabelText, POSITIVE_TC_IDX );
383 TEST_FUNCTION( UtcDaliPushButtonPressed, POSITIVE_TC_IDX );
384 TEST_FUNCTION( UtcDaliPushButtonReleased, POSITIVE_TC_IDX );
385 TEST_FUNCTION( UtcDaliPushButtonToggled, POSITIVE_TC_IDX );
386 TEST_FUNCTION( UtcDaliPushButtonInterruptEventWhenInsensitive, POSITIVE_TC_IDX );
387 TEST_FUNCTION( UtcDaliPushButtonInterruptEventWhenNonVisible, POSITIVE_TC_IDX );
389 // Called only once before first test is run.
390 static void Startup()
394 // Called only once after last test is run
395 static void Cleanup()
400 static void UtcDaliPushButtonSetGetAutoRepeating()
402 ToolkitTestApplication application;
403 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
405 PushButton pushButton = PushButton::New();
407 pushButton.SetAutoRepeating( true );
409 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
411 pushButton.SetAutoRepeating( false );
413 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
415 pushButton.SetAutoRepeating( true );
417 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
420 static void UtcDaliPushButtonSetGetToggleButton()
422 ToolkitTestApplication application;
423 tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
425 PushButton pushButton = PushButton::New();
427 pushButton.SetToggleButton( true );
429 DALI_TEST_CHECK( pushButton.IsToggleButton() );
431 pushButton.SetToggleButton( false );
433 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
435 pushButton.SetToggleButton( true );
437 DALI_TEST_CHECK( pushButton.IsToggleButton() );
440 static void UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton()
442 ToolkitTestApplication application;
443 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
445 PushButton pushButton = PushButton::New();
447 pushButton.SetAutoRepeating( true );
448 pushButton.SetToggleButton( true );
450 DALI_TEST_CHECK( pushButton.IsToggleButton() );
451 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
453 pushButton.SetToggleButton( true );
454 pushButton.SetAutoRepeating( true );
456 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
457 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
460 static void UtcDaliPushButtonSetGetToggled01()
462 ToolkitTestApplication application;
463 tet_infoline(" UtcDaliPushButtonSetGetToggled01");
465 PushButton pushButton = PushButton::New();
467 pushButton.SetToggleButton( true );
468 pushButton.ToggledSignal().Connect( &PushButtonToggled );
470 gPushButtonToggleState = false;
471 pushButton.SetToggled( true );
473 DALI_TEST_CHECK( pushButton.IsToggled() );
474 DALI_TEST_CHECK( gPushButtonToggleState );
476 pushButton.SetToggled( false );
478 DALI_TEST_CHECK( !pushButton.IsToggled() );
479 DALI_TEST_CHECK( !gPushButtonToggleState );
481 pushButton.SetToggled( true );
483 DALI_TEST_CHECK( pushButton.IsToggled() );
484 DALI_TEST_CHECK( gPushButtonToggleState );
487 static void UtcDaliPushButtonSetGetToggled02()
489 ToolkitTestApplication application;
490 tet_infoline(" UtcDaliPushButtonSetGetToggled02");
492 PushButton pushButton = PushButton::New();
494 pushButton.SetToggleButton( false );
495 pushButton.ToggledSignal().Connect( &PushButtonToggled );
497 gPushButtonToggleState = false;
498 pushButton.SetToggled( true );
500 DALI_TEST_CHECK( !pushButton.IsToggled() );
501 DALI_TEST_CHECK( !gPushButtonToggleState );
503 pushButton.SetToggled( false );
505 DALI_TEST_CHECK( !pushButton.IsToggled() );
506 DALI_TEST_CHECK( !gPushButtonToggleState );
508 pushButton.SetToggled( true );
510 DALI_TEST_CHECK( !pushButton.IsToggled() );
511 DALI_TEST_CHECK( !gPushButtonToggleState );
514 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues01()
516 ToolkitTestApplication application;
517 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
519 PushButton pushButton = PushButton::New();
521 pushButton.SetAutoRepeating( true );
523 pushButton.SetInitialAutoRepeatingDelay( 1.f );
524 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
526 pushButton.SetNextAutoRepeatingDelay( 1.f );
527 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
530 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues02()
532 ToolkitTestApplication application;
533 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
535 PushButton pushButton = PushButton::New();
537 bool assert1( false );
538 bool assert2( false );
540 pushButton.SetAutoRepeating( true );
544 pushButton.SetInitialAutoRepeatingDelay( -1.f );
546 catch( Dali::DaliException& e )
548 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
549 DALI_TEST_EQUALS(e.mCondition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
555 pushButton.SetNextAutoRepeatingDelay( -1.f );
557 catch( Dali::DaliException& e )
559 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
560 DALI_TEST_EQUALS(e.mCondition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
564 DALI_TEST_CHECK( assert1 && assert2 );
567 static void UtcDaliPushButtonSetImages()
569 ToolkitTestApplication application;
570 tet_infoline(" UtcDaliPushButtonSetImages");
574 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
575 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
576 imageActor01.SetSize( 20.f, 20.f );
578 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
579 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
580 imageActor02.SetSize( 40.f, 40.f );
582 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
583 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
584 imageActor03.SetSize( 60.f, 60.f );
586 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
587 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
588 imageActor04.SetSize( 80.f, 80.f );
590 Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
591 ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
592 imageActor05.SetSize( 100.f, 100.f );
595 PushButton pushButton = PushButton::New();
597 application.SendNotification();
598 application.Render();
600 // Just check if check box button size changes when a bigger image is set.
602 pushButton.SetButtonImage( image01 );
604 application.SendNotification();
605 application.Render();
607 size = pushButton.GetButtonImage().GetCurrentSize();
609 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
610 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
612 pushButton.SetButtonImage( imageActor01 );
614 application.SendNotification();
615 application.Render();
617 size = pushButton.GetButtonImage().GetCurrentSize();
619 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
620 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
622 pushButton.SetBackgroundImage( image02 );
624 application.SendNotification();
625 application.Render();
627 size = pushButton.GetBackgroundImage().GetCurrentSize();
629 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
630 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
632 pushButton.SetBackgroundImage( imageActor02 );
634 application.SendNotification();
635 application.Render();
637 size = pushButton.GetBackgroundImage().GetCurrentSize();
639 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
640 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
642 pushButton.SetPressedImage( image03 );
644 application.SendNotification();
645 application.Render();
647 size = pushButton.GetPressedImage().GetCurrentSize();
649 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
650 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
652 pushButton.SetPressedImage( imageActor03 );
654 application.SendNotification();
655 application.Render();
657 size = pushButton.GetPressedImage().GetCurrentSize();
659 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
660 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
662 pushButton.SetDimmedBackgroundImage( image04 );
664 application.SendNotification();
665 application.Render();
667 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
669 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
670 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
672 pushButton.SetDimmedBackgroundImage( imageActor04 );
674 application.SendNotification();
675 application.Render();
677 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
679 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
680 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
682 pushButton.SetDimmedImage( image05 );
684 application.SendNotification();
685 application.Render();
687 size = pushButton.GetDimmedImage().GetCurrentSize();
689 DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
690 DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
692 pushButton.SetDimmedImage( imageActor05 );
694 application.SendNotification();
695 application.Render();
697 size = pushButton.GetDimmedImage().GetCurrentSize();
699 DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
700 DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
703 static void UtcDaliPushButtonSetLabelText()
705 ToolkitTestApplication application;
706 tet_infoline(" UtcDaliPushButtonSetLabelText");
708 const std::string STR( "Hola!" );
710 PushButton pushButton = PushButton::New();
712 application.SendNotification();
713 application.Render();
717 pushButton.SetLabelText( STR );
719 textView = TextView::DownCast( pushButton.GetLabelText() );
720 DALI_TEST_CHECK( STR == textView.GetText() );
722 TextView text = TextView::New( STR );
723 pushButton.SetLabelText( text );
725 textView = TextView::DownCast( pushButton.GetLabelText() );
726 DALI_TEST_CHECK( STR == textView.GetText() );
729 static void UtcDaliPushButtonPressed()
731 ToolkitTestApplication application;
732 tet_infoline(" UtcDaliPushButtonPressed");
734 PushButton pushButton = PushButton::New();
735 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
736 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
737 pushButton.SetPosition( 240, 400 );
738 pushButton.SetSize( 100, 100 );
740 Stage::GetCurrent().Add( pushButton );
742 application.SendNotification();
743 application.Render();
745 gPushButtonPressed = false;
747 // connect to its touch signal
748 pushButton.PressedSignal().Connect( &PushButtonPressed );
750 Dali::Integration::TouchEvent eventDown;
751 eventDown.AddPoint( pointDownInside );
753 // flush the queue and render once
754 application.SendNotification();
755 application.Render();
756 application.GetCore().SendEvent( eventDown );
758 DALI_TEST_CHECK( gPushButtonPressed );
761 static void UtcDaliPushButtonReleased()
763 ToolkitTestApplication application;
764 tet_infoline(" UtcDaliPushButtonReleased");
766 PushButton pushButton = PushButton::New();
767 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
768 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
769 pushButton.SetPosition( 240, 400 );
770 pushButton.SetSize( 100, 100 );
772 Stage::GetCurrent().Add( pushButton );
774 application.SendNotification();
775 application.Render();
777 // connect to its touch signal
778 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
780 Dali::Integration::TouchEvent event;
782 // Test1. Touch point down and up inside the button.
784 gPushButtonReleased = false;
785 event = Dali::Integration::TouchEvent();
786 event.AddPoint( pointDownInside );
787 application.GetCore().SendEvent( event );
789 event = Dali::Integration::TouchEvent();
790 event.AddPoint( pointUpInside );
791 application.GetCore().SendEvent( event );
793 DALI_TEST_CHECK( gPushButtonReleased );
795 // Test2. Touch point down and up outside the button.
797 gPushButtonReleased = false;
798 event = Dali::Integration::TouchEvent();
799 event.AddPoint( pointDownOutside );
800 application.GetCore().SendEvent( event );
802 event = Dali::Integration::TouchEvent();
803 event.AddPoint( pointUpOutside );
804 application.GetCore().SendEvent( event );
806 DALI_TEST_CHECK( !gPushButtonReleased );
808 // Test3. Touch point down inside and up outside the button.
810 gPushButtonReleased = false;
811 event = Dali::Integration::TouchEvent();
812 event.AddPoint( pointDownInside );
813 application.GetCore().SendEvent( event );
815 event = Dali::Integration::TouchEvent();
816 event.AddPoint( pointLeave );
817 application.GetCore().SendEvent( event );
819 event = Dali::Integration::TouchEvent();
820 event.AddPoint( pointUpOutside );
821 application.GetCore().SendEvent( event );
823 DALI_TEST_CHECK( gPushButtonReleased );
825 // Test4. Touch point down outside and up inside the button.
827 gPushButtonReleased = false;
828 event = Dali::Integration::TouchEvent();
829 event.AddPoint( pointDownOutside );
830 application.GetCore().SendEvent( event );
832 event = Dali::Integration::TouchEvent();
833 event.AddPoint( pointEnter );
834 application.GetCore().SendEvent( event );
836 event = Dali::Integration::TouchEvent();
837 event.AddPoint( pointUpInside );
838 application.GetCore().SendEvent( event );
840 DALI_TEST_CHECK( !gPushButtonReleased );
843 static void UtcDaliPushButtonToggled()
845 ToolkitTestApplication application;
846 tet_infoline(" UtcDaliPushButtonToggled");
848 PushButton pushButton = PushButton::New();
849 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
850 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
851 pushButton.SetPosition( 240, 400 );
852 pushButton.SetSize( 100, 100 );
854 Stage::GetCurrent().Add( pushButton );
856 application.SendNotification();
857 application.Render();
859 // connect to its touch signal
860 pushButton.ToggledSignal().Connect( &PushButtonToggled );
862 Dali::Integration::TouchEvent event;
864 // Test1. No toggle button.
866 gPushButtonToggleState = false;
867 event = Dali::Integration::TouchEvent();
868 event.AddPoint( pointDownInside );
869 application.GetCore().SendEvent( event );
871 event = Dali::Integration::TouchEvent();
872 event.AddPoint( pointUpInside );
873 application.GetCore().SendEvent( event );
875 DALI_TEST_CHECK( !gPushButtonToggleState );
877 // Set toggle property.
878 pushButton.SetToggleButton( true );
880 // Test2. Touch point down and up inside the button twice.
881 gPushButtonToggleState = false;
882 event = Dali::Integration::TouchEvent();
883 event.AddPoint( pointDownInside );
884 application.GetCore().SendEvent( event );
886 event = Dali::Integration::TouchEvent();
887 event.AddPoint( pointUpInside );
888 application.GetCore().SendEvent( event );
890 DALI_TEST_CHECK( gPushButtonToggleState );
892 event = Dali::Integration::TouchEvent();
893 event.AddPoint( pointDownInside );
894 application.GetCore().SendEvent( event );
896 event = Dali::Integration::TouchEvent();
897 event.AddPoint( pointUpInside );
898 application.GetCore().SendEvent( event );
900 DALI_TEST_CHECK( !gPushButtonToggleState );
902 // Test3. Touch point down and up outside the button.
904 gPushButtonToggleState = false;
905 event = Dali::Integration::TouchEvent();
906 event.AddPoint( pointDownOutside );
907 application.GetCore().SendEvent( event );
909 event = Dali::Integration::TouchEvent();
910 event.AddPoint( pointUpOutside );
911 application.GetCore().SendEvent( event );
913 DALI_TEST_CHECK( !gPushButtonToggleState );
915 // Test4. Touch point down inside and up outside the button.
917 gPushButtonToggleState = false;
918 event = Dali::Integration::TouchEvent();
919 event.AddPoint( pointDownInside );
920 application.GetCore().SendEvent( event );
922 event = Dali::Integration::TouchEvent();
923 event.AddPoint( pointLeave );
924 application.GetCore().SendEvent( event );
926 event = Dali::Integration::TouchEvent();
927 event.AddPoint( pointUpOutside );
928 application.GetCore().SendEvent( event );
930 DALI_TEST_CHECK( !gPushButtonToggleState );
932 // Test5. Touch point down outside and up inside the button.
934 gPushButtonToggleState = false;
935 event = Dali::Integration::TouchEvent();
936 event.AddPoint( pointDownOutside );
937 application.GetCore().SendEvent( event );
939 event = Dali::Integration::TouchEvent();
940 event.AddPoint( pointEnter );
941 application.GetCore().SendEvent( event );
943 event = Dali::Integration::TouchEvent();
944 event.AddPoint( pointUpInside );
945 application.GetCore().SendEvent( event );
947 DALI_TEST_CHECK( !gPushButtonToggleState );
950 static void UtcDaliPushButtonInterruptEventWhenInsensitive()
952 ToolkitTestApplication application;
953 tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive");
955 // * Creates an actor which contains a button.
956 // * The size of the actor is bigger than the button.
957 // * The button's boundary is contained in the actor's one.
958 Actor actor = Actor::New();
959 TETButton tetButton= Toolkit::TETButton::New();
961 actor.SetName( "Actor" );
962 tetButton.SetName( "TETButton" );
964 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
965 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
966 actor.SetPosition( 0, 0 );
967 actor.SetSize( 400, 800 );
969 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
970 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
971 tetButton.SetPosition( 240, 400 );
972 tetButton.SetSize( 100, 100 );
974 actor.Add( tetButton );
975 Stage::GetCurrent().Add( actor );
977 // * Actor's touch event is connected to a callback function
978 // and this callback function consumes the event.
979 actor.TouchedSignal().Connect( &TestCallback );
981 // * Button's pressed signal is connected to a callback function
982 // which also consumes the event.
983 // * Changes the sensitiveness of the button to false.
984 TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS );
985 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
987 // Initializes TET state.
988 gOnTouchPointInterrupted = false;
989 tetButton.SetSensitive( true );
991 Dali::Integration::TouchEvent event;
995 // Test a down point inside the button which is also consumed by the actor, and an up point
996 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
999 application.SendNotification();
1000 application.Render();
1002 // A down event is sent inside the button's boundary.
1004 event = Dali::Integration::TouchEvent();
1005 event.AddPoint( pointDownInside );
1007 // flush the queue and render once
1008 application.SendNotification();
1009 application.Render();
1010 application.GetCore().SendEvent( event );
1012 // An up event is sent outside the button's boundary but inside the actor's one.
1014 event = Dali::Integration::TouchEvent();
1015 event.AddPoint( pointUpOutside );
1017 // flush the queue and render once
1018 application.SendNotification();
1019 application.Render();
1020 application.GetCore().SendEvent( event );
1022 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1024 // Test a down point inside the button which is also consumed by the actor, and a motion point
1025 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1028 // Initializes TET state.
1029 gOnTouchPointInterrupted = false;
1030 actor.SetSensitive( true );
1031 tetButton.SetSensitive( true );
1033 application.SendNotification();
1034 application.Render();
1036 // A down event is sent inside the button's boundary.
1038 event = Dali::Integration::TouchEvent();
1039 event.AddPoint( pointDownInside );
1041 // flush the queue and render once
1042 application.SendNotification();
1043 application.Render();
1044 application.GetCore().SendEvent( event );
1046 // A motion event is sent outside the button's boundary but inside the actor's one.
1048 event = Dali::Integration::TouchEvent();
1049 event.AddPoint( pointMotionOut );
1051 // flush the queue and render once
1052 application.SendNotification();
1053 application.Render();
1054 application.GetCore().SendEvent( event );
1056 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1058 // Test a down point inside the button which is also consumed by the actor, and an up point
1059 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
1061 // Initializes TET state.
1062 gOnTouchPointInterrupted = false;
1063 actor.SetSensitive( true );
1064 tetButton.SetSensitive( true );
1066 // A down event is sent inside the button's boundary.
1068 event = Dali::Integration::TouchEvent();
1069 event.AddPoint( pointDownInside );
1071 // flush the queue and render once
1072 application.SendNotification();
1073 application.Render();
1074 application.GetCore().SendEvent( event );
1076 actor.SetSensitive( true );
1077 // An up event is sent inside the button's boundary.
1079 event = Dali::Integration::TouchEvent();
1080 event.AddPoint( pointUpInside );
1082 // flush the queue and render once
1083 application.SendNotification();
1084 application.Render();
1085 application.GetCore().SendEvent( event );
1087 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1090 static void UtcDaliPushButtonInterruptEventWhenNonVisible()
1092 ToolkitTestApplication application;
1093 tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible");
1095 // Does same test as above but changing the visibility instead the sensitiveness.
1097 // * Creates an actor which contains a button.
1098 // * The size of the actor is bigger than the button.
1099 // * The button's boundary is contained in the actor's one.
1100 Actor actor = Actor::New();
1101 TETButton tetButton = Toolkit::TETButton::New();
1103 actor.SetName( "Actor" );
1104 tetButton.SetName( "TETButton" );
1106 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1107 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1108 actor.SetPosition( 0, 0 );
1109 actor.SetSize( 400, 800 );
1111 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1112 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1113 tetButton.SetPosition( 240, 400 );
1114 tetButton.SetSize( 100, 100 );
1116 actor.Add( tetButton );
1117 Stage::GetCurrent().Add( actor );
1119 // * Actor's touch event is connected to a callback function
1120 // and this callback function consumes the event.
1121 actor.TouchedSignal().Connect( &TestCallback );
1123 // * Button's pressed signal is connected to a callback function
1124 // which also consumes the event.
1125 // * Changes the visibility of the button to false.
1126 TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY );
1127 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
1129 // Initializes TET state.
1130 gOnTouchPointInterrupted = false;
1131 tetButton.SetVisible( true );
1133 Dali::Integration::TouchEvent event;
1137 // Test a down point inside the button which is also consumed by the actor, and an up point
1138 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1141 application.SendNotification();
1142 application.Render();
1144 // A down event is sent inside the button's boundary.
1146 event = Dali::Integration::TouchEvent();
1147 event.AddPoint( pointDownInside );
1149 // flush the queue and render once
1150 application.SendNotification();
1151 application.Render();
1152 application.GetCore().SendEvent( event );
1154 // More renders are needed in order to allow the node of the actor to become invisible.
1155 application.SendNotification();
1156 application.Render();
1157 application.SendNotification();
1158 application.Render();
1159 application.SendNotification();
1160 application.Render();
1162 // An up event is sent outside the button's boundary but inside the actor's one.
1164 event = Dali::Integration::TouchEvent();
1165 event.AddPoint( pointUpOutside );
1167 // flush the queue and render once
1168 application.SendNotification();
1169 application.Render();
1170 application.GetCore().SendEvent( event );
1172 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1174 // Test a down point inside the button which is also consumed by the actor, and a motion point
1175 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1178 // Initializes TET state.
1179 gOnTouchPointInterrupted = false;
1180 tetButton.SetVisible( true );
1182 application.SendNotification();
1183 application.Render();
1184 application.SendNotification();
1185 application.Render();
1186 application.SendNotification();
1187 application.Render();
1189 // A down event is sent inside the button's boundary.
1191 event = Dali::Integration::TouchEvent();
1192 event.AddPoint( pointDownInside );
1194 // flush the queue and render once
1195 application.SendNotification();
1196 application.Render();
1197 application.GetCore().SendEvent( event );
1199 // More renders are needed in order to allow the node of the actor to become invisible.
1200 application.SendNotification();
1201 application.Render();
1202 application.SendNotification();
1203 application.Render();
1204 application.SendNotification();
1205 application.Render();
1207 // A motion event is sent outside the button's boundary but inside the actor's one.
1209 event = Dali::Integration::TouchEvent();
1210 event.AddPoint( pointMotionOut );
1212 // flush the queue and render once
1213 application.SendNotification();
1214 application.Render();
1215 application.GetCore().SendEvent( event );
1217 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1219 // Test a down point inside the button which is also consumed by the actor, and an up point
1220 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
1222 // Initializes TET state.
1223 gOnTouchPointInterrupted = false;
1224 tetButton.SetVisible( true );
1226 application.SendNotification();
1227 application.Render();
1228 application.SendNotification();
1229 application.Render();
1230 application.SendNotification();
1231 application.Render();
1233 // A down event is sent inside the button's boundary.
1235 event = Dali::Integration::TouchEvent();
1236 event.AddPoint( pointDownInside );
1238 // flush the queue and render once
1239 application.SendNotification();
1240 application.Render();
1241 application.GetCore().SendEvent( event );
1243 tetButton.SetVisible( true );
1245 application.SendNotification();
1246 application.Render();
1247 application.SendNotification();
1248 application.Render();
1249 application.SendNotification();
1250 application.Render();
1252 // An up event is sent inside the button's boundary.
1254 event = Dali::Integration::TouchEvent();
1255 event.AddPoint( pointUpInside );
1257 // flush the queue and render once
1258 application.SendNotification();
1259 application.Render();
1260 application.GetCore().SendEvent( event );
1262 DALI_TEST_CHECK( !gOnTouchPointInterrupted );