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 );
388 TEST_FUNCTION( UtcDaliPushButtonProperties, POSITIVE_TC_IDX );
390 // Called only once before first test is run.
391 static void Startup()
395 // Called only once after last test is run
396 static void Cleanup()
401 static void UtcDaliPushButtonSetGetAutoRepeating()
403 ToolkitTestApplication application;
404 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
406 PushButton pushButton = PushButton::New();
408 pushButton.SetAutoRepeating( true );
410 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
412 pushButton.SetAutoRepeating( false );
414 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
416 pushButton.SetAutoRepeating( true );
418 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
421 static void UtcDaliPushButtonSetGetToggleButton()
423 ToolkitTestApplication application;
424 tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
426 PushButton pushButton = PushButton::New();
428 pushButton.SetToggleButton( true );
430 DALI_TEST_CHECK( pushButton.IsToggleButton() );
432 pushButton.SetToggleButton( false );
434 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
436 pushButton.SetToggleButton( true );
438 DALI_TEST_CHECK( pushButton.IsToggleButton() );
441 static void UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton()
443 ToolkitTestApplication application;
444 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
446 PushButton pushButton = PushButton::New();
448 pushButton.SetAutoRepeating( true );
449 pushButton.SetToggleButton( true );
451 DALI_TEST_CHECK( pushButton.IsToggleButton() );
452 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
454 pushButton.SetToggleButton( true );
455 pushButton.SetAutoRepeating( true );
457 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
458 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
461 static void UtcDaliPushButtonSetGetToggled01()
463 ToolkitTestApplication application;
464 tet_infoline(" UtcDaliPushButtonSetGetToggled01");
466 PushButton pushButton = PushButton::New();
468 pushButton.SetToggleButton( true );
469 pushButton.ToggledSignal().Connect( &PushButtonToggled );
471 gPushButtonToggleState = false;
472 pushButton.SetToggled( true );
474 DALI_TEST_CHECK( pushButton.IsToggled() );
475 DALI_TEST_CHECK( gPushButtonToggleState );
477 pushButton.SetToggled( false );
479 DALI_TEST_CHECK( !pushButton.IsToggled() );
480 DALI_TEST_CHECK( !gPushButtonToggleState );
482 pushButton.SetToggled( true );
484 DALI_TEST_CHECK( pushButton.IsToggled() );
485 DALI_TEST_CHECK( gPushButtonToggleState );
488 static void UtcDaliPushButtonSetGetToggled02()
490 ToolkitTestApplication application;
491 tet_infoline(" UtcDaliPushButtonSetGetToggled02");
493 PushButton pushButton = PushButton::New();
495 pushButton.SetToggleButton( false );
496 pushButton.ToggledSignal().Connect( &PushButtonToggled );
498 gPushButtonToggleState = false;
499 pushButton.SetToggled( true );
501 DALI_TEST_CHECK( !pushButton.IsToggled() );
502 DALI_TEST_CHECK( !gPushButtonToggleState );
504 pushButton.SetToggled( false );
506 DALI_TEST_CHECK( !pushButton.IsToggled() );
507 DALI_TEST_CHECK( !gPushButtonToggleState );
509 pushButton.SetToggled( true );
511 DALI_TEST_CHECK( !pushButton.IsToggled() );
512 DALI_TEST_CHECK( !gPushButtonToggleState );
515 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues01()
517 ToolkitTestApplication application;
518 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
520 PushButton pushButton = PushButton::New();
522 pushButton.SetAutoRepeating( true );
524 pushButton.SetInitialAutoRepeatingDelay( 1.f );
525 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
527 pushButton.SetNextAutoRepeatingDelay( 1.f );
528 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
531 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues02()
533 ToolkitTestApplication application;
534 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
536 PushButton pushButton = PushButton::New();
538 bool assert1( false );
539 bool assert2( false );
541 pushButton.SetAutoRepeating( true );
545 pushButton.SetInitialAutoRepeatingDelay( -1.f );
547 catch( Dali::DaliException& e )
549 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
550 DALI_TEST_EQUALS(e.mCondition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
556 pushButton.SetNextAutoRepeatingDelay( -1.f );
558 catch( Dali::DaliException& e )
560 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
561 DALI_TEST_EQUALS(e.mCondition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
565 DALI_TEST_CHECK( assert1 && assert2 );
568 static void UtcDaliPushButtonSetImages()
570 ToolkitTestApplication application;
571 tet_infoline(" UtcDaliPushButtonSetImages");
575 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
576 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
577 imageActor01.SetSize( 20.f, 20.f );
579 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
580 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
581 imageActor02.SetSize( 40.f, 40.f );
583 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
584 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
585 imageActor03.SetSize( 60.f, 60.f );
587 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
588 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
589 imageActor04.SetSize( 80.f, 80.f );
591 Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
592 ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
593 imageActor05.SetSize( 100.f, 100.f );
596 PushButton pushButton = PushButton::New();
598 application.SendNotification();
599 application.Render();
601 // Just check if check box button size changes when a bigger image is set.
603 pushButton.SetButtonImage( image01 );
605 application.SendNotification();
606 application.Render();
608 size = pushButton.GetButtonImage().GetCurrentSize();
610 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
611 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
613 pushButton.SetButtonImage( imageActor01 );
615 application.SendNotification();
616 application.Render();
618 size = pushButton.GetButtonImage().GetCurrentSize();
620 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
621 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
623 pushButton.SetBackgroundImage( image02 );
625 application.SendNotification();
626 application.Render();
628 size = pushButton.GetBackgroundImage().GetCurrentSize();
630 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
631 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
633 pushButton.SetBackgroundImage( imageActor02 );
635 application.SendNotification();
636 application.Render();
638 size = pushButton.GetBackgroundImage().GetCurrentSize();
640 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
641 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
643 pushButton.SetPressedImage( image03 );
645 application.SendNotification();
646 application.Render();
648 size = pushButton.GetPressedImage().GetCurrentSize();
650 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
651 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
653 pushButton.SetPressedImage( imageActor03 );
655 application.SendNotification();
656 application.Render();
658 size = pushButton.GetPressedImage().GetCurrentSize();
660 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
661 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
663 pushButton.SetDimmedBackgroundImage( image04 );
665 application.SendNotification();
666 application.Render();
668 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
670 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
671 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
673 pushButton.SetDimmedBackgroundImage( imageActor04 );
675 application.SendNotification();
676 application.Render();
678 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
680 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
681 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
683 pushButton.SetDimmedImage( image05 );
685 application.SendNotification();
686 application.Render();
688 size = pushButton.GetDimmedImage().GetCurrentSize();
690 DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
691 DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
693 pushButton.SetDimmedImage( imageActor05 );
695 application.SendNotification();
696 application.Render();
698 size = pushButton.GetDimmedImage().GetCurrentSize();
700 DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
701 DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
704 static void UtcDaliPushButtonSetLabelText()
706 ToolkitTestApplication application;
707 tet_infoline(" UtcDaliPushButtonSetLabelText");
709 const std::string STR( "Hola!" );
711 PushButton pushButton = PushButton::New();
713 application.SendNotification();
714 application.Render();
718 pushButton.SetLabelText( STR );
720 textView = TextView::DownCast( pushButton.GetLabelText() );
721 DALI_TEST_CHECK( STR == textView.GetText() );
723 TextView text = TextView::New( STR );
724 pushButton.SetLabelText( text );
726 textView = TextView::DownCast( pushButton.GetLabelText() );
727 DALI_TEST_CHECK( STR == textView.GetText() );
730 static void UtcDaliPushButtonPressed()
732 ToolkitTestApplication application;
733 tet_infoline(" UtcDaliPushButtonPressed");
735 PushButton pushButton = PushButton::New();
736 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
737 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
738 pushButton.SetPosition( 240, 400 );
739 pushButton.SetSize( 100, 100 );
741 Stage::GetCurrent().Add( pushButton );
743 application.SendNotification();
744 application.Render();
746 gPushButtonPressed = false;
748 // connect to its touch signal
749 pushButton.PressedSignal().Connect( &PushButtonPressed );
751 Dali::Integration::TouchEvent eventDown;
752 eventDown.AddPoint( pointDownInside );
754 // flush the queue and render once
755 application.SendNotification();
756 application.Render();
757 application.ProcessEvent( eventDown );
759 DALI_TEST_CHECK( gPushButtonPressed );
762 static void UtcDaliPushButtonReleased()
764 ToolkitTestApplication application;
765 tet_infoline(" UtcDaliPushButtonReleased");
767 PushButton pushButton = PushButton::New();
768 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
769 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
770 pushButton.SetPosition( 240, 400 );
771 pushButton.SetSize( 100, 100 );
773 Stage::GetCurrent().Add( pushButton );
775 application.SendNotification();
776 application.Render();
778 // connect to its touch signal
779 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
781 Dali::Integration::TouchEvent event;
783 // Test1. Touch point down and up inside the button.
785 gPushButtonReleased = false;
786 event = Dali::Integration::TouchEvent();
787 event.AddPoint( pointDownInside );
788 application.ProcessEvent( event );
790 event = Dali::Integration::TouchEvent();
791 event.AddPoint( pointUpInside );
792 application.ProcessEvent( event );
794 DALI_TEST_CHECK( gPushButtonReleased );
796 // Test2. Touch point down and up outside the button.
798 gPushButtonReleased = false;
799 event = Dali::Integration::TouchEvent();
800 event.AddPoint( pointDownOutside );
801 application.ProcessEvent( event );
803 event = Dali::Integration::TouchEvent();
804 event.AddPoint( pointUpOutside );
805 application.ProcessEvent( event );
807 DALI_TEST_CHECK( !gPushButtonReleased );
809 // Test3. Touch point down inside and up outside the button.
811 gPushButtonReleased = false;
812 event = Dali::Integration::TouchEvent();
813 event.AddPoint( pointDownInside );
814 application.ProcessEvent( event );
816 event = Dali::Integration::TouchEvent();
817 event.AddPoint( pointLeave );
818 application.ProcessEvent( event );
820 event = Dali::Integration::TouchEvent();
821 event.AddPoint( pointUpOutside );
822 application.ProcessEvent( event );
824 DALI_TEST_CHECK( gPushButtonReleased );
826 // Test4. Touch point down outside and up inside the button.
828 gPushButtonReleased = false;
829 event = Dali::Integration::TouchEvent();
830 event.AddPoint( pointDownOutside );
831 application.ProcessEvent( event );
833 event = Dali::Integration::TouchEvent();
834 event.AddPoint( pointEnter );
835 application.ProcessEvent( event );
837 event = Dali::Integration::TouchEvent();
838 event.AddPoint( pointUpInside );
839 application.ProcessEvent( event );
841 DALI_TEST_CHECK( !gPushButtonReleased );
844 static void UtcDaliPushButtonToggled()
846 ToolkitTestApplication application;
847 tet_infoline(" UtcDaliPushButtonToggled");
849 PushButton pushButton = PushButton::New();
850 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
851 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
852 pushButton.SetPosition( 240, 400 );
853 pushButton.SetSize( 100, 100 );
855 Stage::GetCurrent().Add( pushButton );
857 application.SendNotification();
858 application.Render();
860 // connect to its touch signal
861 pushButton.ToggledSignal().Connect( &PushButtonToggled );
863 Dali::Integration::TouchEvent event;
865 // Test1. No toggle button.
867 gPushButtonToggleState = false;
868 event = Dali::Integration::TouchEvent();
869 event.AddPoint( pointDownInside );
870 application.ProcessEvent( event );
872 event = Dali::Integration::TouchEvent();
873 event.AddPoint( pointUpInside );
874 application.ProcessEvent( event );
876 DALI_TEST_CHECK( !gPushButtonToggleState );
878 // Set toggle property.
879 pushButton.SetToggleButton( true );
881 // Test2. Touch point down and up inside the button twice.
882 gPushButtonToggleState = false;
883 event = Dali::Integration::TouchEvent();
884 event.AddPoint( pointDownInside );
885 application.ProcessEvent( event );
887 event = Dali::Integration::TouchEvent();
888 event.AddPoint( pointUpInside );
889 application.ProcessEvent( event );
891 DALI_TEST_CHECK( gPushButtonToggleState );
893 event = Dali::Integration::TouchEvent();
894 event.AddPoint( pointDownInside );
895 application.ProcessEvent( event );
897 event = Dali::Integration::TouchEvent();
898 event.AddPoint( pointUpInside );
899 application.ProcessEvent( event );
901 DALI_TEST_CHECK( !gPushButtonToggleState );
903 // Test3. Touch point down and up outside the button.
905 gPushButtonToggleState = false;
906 event = Dali::Integration::TouchEvent();
907 event.AddPoint( pointDownOutside );
908 application.ProcessEvent( event );
910 event = Dali::Integration::TouchEvent();
911 event.AddPoint( pointUpOutside );
912 application.ProcessEvent( event );
914 DALI_TEST_CHECK( !gPushButtonToggleState );
916 // Test4. Touch point down inside and up outside the button.
918 gPushButtonToggleState = false;
919 event = Dali::Integration::TouchEvent();
920 event.AddPoint( pointDownInside );
921 application.ProcessEvent( event );
923 event = Dali::Integration::TouchEvent();
924 event.AddPoint( pointLeave );
925 application.ProcessEvent( event );
927 event = Dali::Integration::TouchEvent();
928 event.AddPoint( pointUpOutside );
929 application.ProcessEvent( event );
931 DALI_TEST_CHECK( !gPushButtonToggleState );
933 // Test5. Touch point down outside and up inside the button.
935 gPushButtonToggleState = false;
936 event = Dali::Integration::TouchEvent();
937 event.AddPoint( pointDownOutside );
938 application.ProcessEvent( event );
940 event = Dali::Integration::TouchEvent();
941 event.AddPoint( pointEnter );
942 application.ProcessEvent( event );
944 event = Dali::Integration::TouchEvent();
945 event.AddPoint( pointUpInside );
946 application.ProcessEvent( event );
948 DALI_TEST_CHECK( !gPushButtonToggleState );
951 static void UtcDaliPushButtonInterruptEventWhenInsensitive()
953 ToolkitTestApplication application;
954 tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive");
956 // * Creates an actor which contains a button.
957 // * The size of the actor is bigger than the button.
958 // * The button's boundary is contained in the actor's one.
959 Actor actor = Actor::New();
960 TETButton tetButton= Toolkit::TETButton::New();
962 actor.SetName( "Actor" );
963 tetButton.SetName( "TETButton" );
965 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
966 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
967 actor.SetPosition( 0, 0 );
968 actor.SetSize( 400, 800 );
970 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
971 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
972 tetButton.SetPosition( 240, 400 );
973 tetButton.SetSize( 100, 100 );
975 actor.Add( tetButton );
976 Stage::GetCurrent().Add( actor );
978 // * Actor's touch event is connected to a callback function
979 // and this callback function consumes the event.
980 actor.TouchedSignal().Connect( &TestCallback );
982 // * Button's pressed signal is connected to a callback function
983 // which also consumes the event.
984 // * Changes the sensitiveness of the button to false.
985 TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS );
986 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
988 // Initializes TET state.
989 gOnTouchPointInterrupted = false;
990 tetButton.SetSensitive( true );
992 Dali::Integration::TouchEvent event;
996 // Test a down point inside the button which is also consumed by the actor, and an up point
997 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1000 application.SendNotification();
1001 application.Render();
1003 // A down event is sent inside the button's boundary.
1005 event = Dali::Integration::TouchEvent();
1006 event.AddPoint( pointDownInside );
1008 // flush the queue and render once
1009 application.SendNotification();
1010 application.Render();
1011 application.ProcessEvent( event );
1013 // An up event is sent outside the button's boundary but inside the actor's one.
1015 event = Dali::Integration::TouchEvent();
1016 event.AddPoint( pointUpOutside );
1018 // flush the queue and render once
1019 application.SendNotification();
1020 application.Render();
1021 application.ProcessEvent( event );
1023 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1025 // Test a down point inside the button which is also consumed by the actor, and a motion point
1026 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1029 // Initializes TET state.
1030 gOnTouchPointInterrupted = false;
1031 actor.SetSensitive( true );
1032 tetButton.SetSensitive( true );
1034 application.SendNotification();
1035 application.Render();
1037 // A down event is sent inside the button's boundary.
1039 event = Dali::Integration::TouchEvent();
1040 event.AddPoint( pointDownInside );
1042 // flush the queue and render once
1043 application.SendNotification();
1044 application.Render();
1045 application.ProcessEvent( event );
1047 // A motion event is sent outside the button's boundary but inside the actor's one.
1049 event = Dali::Integration::TouchEvent();
1050 event.AddPoint( pointMotionOut );
1052 // flush the queue and render once
1053 application.SendNotification();
1054 application.Render();
1055 application.ProcessEvent( event );
1057 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1059 // Test a down point inside the button which is also consumed by the actor, and an up point
1060 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
1062 // Initializes TET state.
1063 gOnTouchPointInterrupted = false;
1064 actor.SetSensitive( true );
1065 tetButton.SetSensitive( true );
1067 // A down event is sent inside the button's boundary.
1069 event = Dali::Integration::TouchEvent();
1070 event.AddPoint( pointDownInside );
1072 // flush the queue and render once
1073 application.SendNotification();
1074 application.Render();
1075 application.ProcessEvent( event );
1077 actor.SetSensitive( true );
1078 // An up event is sent inside the button's boundary.
1080 event = Dali::Integration::TouchEvent();
1081 event.AddPoint( pointUpInside );
1083 // flush the queue and render once
1084 application.SendNotification();
1085 application.Render();
1086 application.ProcessEvent( event );
1088 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1091 static void UtcDaliPushButtonInterruptEventWhenNonVisible()
1093 ToolkitTestApplication application;
1094 tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible");
1096 // Does same test as above but changing the visibility instead the sensitiveness.
1098 // * Creates an actor which contains a button.
1099 // * The size of the actor is bigger than the button.
1100 // * The button's boundary is contained in the actor's one.
1101 Actor actor = Actor::New();
1102 TETButton tetButton = Toolkit::TETButton::New();
1104 actor.SetName( "Actor" );
1105 tetButton.SetName( "TETButton" );
1107 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1108 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1109 actor.SetPosition( 0, 0 );
1110 actor.SetSize( 400, 800 );
1112 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1113 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1114 tetButton.SetPosition( 240, 400 );
1115 tetButton.SetSize( 100, 100 );
1117 actor.Add( tetButton );
1118 Stage::GetCurrent().Add( actor );
1120 // * Actor's touch event is connected to a callback function
1121 // and this callback function consumes the event.
1122 actor.TouchedSignal().Connect( &TestCallback );
1124 // * Button's pressed signal is connected to a callback function
1125 // which also consumes the event.
1126 // * Changes the visibility of the button to false.
1127 TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY );
1128 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
1130 // Initializes TET state.
1131 gOnTouchPointInterrupted = false;
1132 tetButton.SetVisible( true );
1134 Dali::Integration::TouchEvent event;
1138 // Test a down point inside the button which is also consumed by the actor, and an up point
1139 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1142 application.SendNotification();
1143 application.Render();
1145 // A down event is sent inside the button's boundary.
1147 event = Dali::Integration::TouchEvent();
1148 event.AddPoint( pointDownInside );
1150 // flush the queue and render once
1151 application.SendNotification();
1152 application.Render();
1153 application.ProcessEvent( event );
1155 // More renders are needed in order to allow the node of the actor to become invisible.
1156 application.SendNotification();
1157 application.Render();
1158 application.SendNotification();
1159 application.Render();
1160 application.SendNotification();
1161 application.Render();
1163 // An up event is sent outside the button's boundary but inside the actor's one.
1165 event = Dali::Integration::TouchEvent();
1166 event.AddPoint( pointUpOutside );
1168 // flush the queue and render once
1169 application.SendNotification();
1170 application.Render();
1171 application.ProcessEvent( event );
1173 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1175 // Test a down point inside the button which is also consumed by the actor, and a motion point
1176 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1179 // Initializes TET state.
1180 gOnTouchPointInterrupted = false;
1181 tetButton.SetVisible( true );
1183 application.SendNotification();
1184 application.Render();
1185 application.SendNotification();
1186 application.Render();
1187 application.SendNotification();
1188 application.Render();
1190 // A down event is sent inside the button's boundary.
1192 event = Dali::Integration::TouchEvent();
1193 event.AddPoint( pointDownInside );
1195 // flush the queue and render once
1196 application.SendNotification();
1197 application.Render();
1198 application.ProcessEvent( event );
1200 // More renders are needed in order to allow the node of the actor to become invisible.
1201 application.SendNotification();
1202 application.Render();
1203 application.SendNotification();
1204 application.Render();
1205 application.SendNotification();
1206 application.Render();
1208 // A motion event is sent outside the button's boundary but inside the actor's one.
1210 event = Dali::Integration::TouchEvent();
1211 event.AddPoint( pointMotionOut );
1213 // flush the queue and render once
1214 application.SendNotification();
1215 application.Render();
1216 application.ProcessEvent( event );
1218 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1220 // Test a down point inside the button which is also consumed by the actor, and an up point
1221 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
1223 // Initializes TET state.
1224 gOnTouchPointInterrupted = false;
1225 tetButton.SetVisible( true );
1227 application.SendNotification();
1228 application.Render();
1229 application.SendNotification();
1230 application.Render();
1231 application.SendNotification();
1232 application.Render();
1234 // A down event is sent inside the button's boundary.
1236 event = Dali::Integration::TouchEvent();
1237 event.AddPoint( pointDownInside );
1239 // flush the queue and render once
1240 application.SendNotification();
1241 application.Render();
1242 application.ProcessEvent( event );
1244 tetButton.SetVisible( true );
1246 application.SendNotification();
1247 application.Render();
1248 application.SendNotification();
1249 application.Render();
1250 application.SendNotification();
1251 application.Render();
1253 // An up event is sent inside the button's boundary.
1255 event = Dali::Integration::TouchEvent();
1256 event.AddPoint( pointUpInside );
1258 // flush the queue and render once
1259 application.SendNotification();
1260 application.Render();
1261 application.ProcessEvent( event );
1263 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1266 void UtcDaliPushButtonProperties()
1268 ToolkitTestApplication application;
1270 PushButton button = PushButton::New();
1271 Stage::GetCurrent().Add( button );
1273 // PushButton::PROPERTY_AUTO_REPEATING
1274 button.SetAutoRepeating( false );
1275 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
1276 button.SetProperty( PushButton::PROPERTY_AUTO_REPEATING, true );
1277 DALI_TEST_CHECK( button.IsAutoRepeating() ) ;
1278 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
1280 // PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY
1281 button.SetInitialAutoRepeatingDelay( 10.0f );
1282 DALI_TEST_EQUALS( 10.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1283 button.SetProperty( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, 25.0f );
1284 DALI_TEST_EQUALS( 25.0f, button.GetInitialAutoRepeatingDelay(), TEST_LOCATION );
1285 DALI_TEST_EQUALS( 25.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1287 // PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY
1288 button.SetNextAutoRepeatingDelay( 3.0f );
1289 DALI_TEST_EQUALS( 3.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1290 button.SetProperty( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY, 4.0f );
1291 DALI_TEST_EQUALS( 4.0f, button.GetNextAutoRepeatingDelay(), TEST_LOCATION );
1292 DALI_TEST_EQUALS( 4.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1294 // PushButton::PROPERTY_TOGGLABLE
1295 button.SetToggleButton( false );
1296 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
1297 button.SetProperty( PushButton::PROPERTY_TOGGLABLE, true );
1298 DALI_TEST_CHECK( button.IsToggleButton() ) ;
1299 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
1301 // PushButton::PROPERTY_TOGGLE
1302 button.SetToggled( false );
1303 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
1304 button.SetProperty( PushButton::PROPERTY_TOGGLE, true );
1305 DALI_TEST_CHECK( button.IsToggled() ) ;
1306 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
1308 // PushButton::PROPERTY_NORMAL_STATE_ACTOR
1310 button.SetButtonImage( Image::New( "IMAGE_PATH_1") );
1311 DALI_TEST_EQUALS( "IMAGE_PATH_1", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1314 map.push_back( Property::StringValuePair( "type", "ImageActor" ) );
1316 button.SetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR, map );
1317 DALI_TEST_EQUALS( "ImageActor", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1320 // PushButton::PROPERTY_PRESSED_IMAGE
1322 button.SetPressedImage( Image::New( "IMAGE_PATH_2") );
1323 DALI_TEST_EQUALS( "IMAGE_PATH_2", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1326 map.push_back( Property::StringValuePair( "type", "TextActor" ) );
1328 button.SetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR, map );
1329 DALI_TEST_EQUALS( "TextActor", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1332 // PushButton::PROPERTY_DIMMED_STATE_ACTOR
1334 button.SetDimmedImage( Image::New( "IMAGE_PATH_3") );
1335 DALI_TEST_EQUALS( "IMAGE_PATH_3", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1338 map.push_back( Property::StringValuePair( "type", "Actor" ) );
1340 button.SetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR, map );
1341 DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1344 // PushButton::PROPERTY_LABEL_ACTOR
1346 button.SetLabelText( "LABEL_TEXT_CUSTOM" );
1347 DALI_TEST_EQUALS( "TextView", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1350 map.push_back( Property::StringValuePair( "type", "Actor" ) );
1352 button.SetProperty( PushButton::PROPERTY_LABEL_ACTOR, map );
1353 DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );