2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <dali/public-api/dali-core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include <dali-toolkit/public-api/controls/default-controls/solid-color-actor.h>
27 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
29 #include <dali-toolkit-test-suite-utils.h>
31 #include <dali-toolkit/internal/controls/buttons/button-impl.h>
34 using namespace Toolkit;
38 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
40 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
43 PixelBuffer* pixbuf = imageData.GetBuffer();
44 unsigned int size = width * height;
46 for( size_t i = 0; i < size; i++ )
48 pixbuf[i*4+0] = 0xFF * color.r;
49 pixbuf[i*4+1] = 0xFF * color.g;
50 pixbuf[i*4+2] = 0xFF * color.b;
51 pixbuf[i*4+3] = 0xFF * color.a;
59 static bool gPushButtonToggleState = false;
60 bool PushButtonToggled( Button button, bool toggled )
62 gPushButtonToggleState = toggled && ( toggled == static_cast<PushButton&>( button ).IsToggled() );
66 static bool gPushButtonPressed = false;
68 static bool PushButtonPressed( Button button )
70 gPushButtonPressed = true;
74 static bool gPushButtonReleased = false;
76 static bool PushButtonReleased( Button button )
78 gPushButtonReleased = true;
82 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
83 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
84 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
85 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
86 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
87 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
88 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
91 static void Startup();
92 static void Cleanup();
95 void (*tet_startup)() = Startup;
96 void (*tet_cleanup)() = Cleanup;
99 //////////////////////////////////////////////////////////
103 static bool gOnTouchPointInterrupted = false;
118 * Creates a Button to test if interrupt events are handled correctly.
120 class TETButton : public Button
123 // PushButton Pressed
124 typedef SignalV2< bool ( Button ) > PressedSignalV2;
126 PressedSignalV2& PressedSignal();
129 * Default constructor.
136 TETButton( const Button& button );
139 * Assignment operator.
141 TETButton& operator=( const TETButton& button );
144 * Creates and initializes a new button.
146 static TETButton New();
149 * Down cast to TETButton.
151 static TETButton DownCast( BaseHandle handle );
154 * Creates a handle using the Toolkit::Internal implementation.
155 * @param[in] implementation The Control implementation.
157 TETButton( Internal::TETButton& implementation );
160 * Allows the creation of this Control from an Internal::CustomActor pointer.
161 * @param[in] internal A pointer to the internal CustomActor.
163 TETButton( Dali::Internal::CustomActor* internal );
170 * Internal implementation
172 class TETButton : public Button
176 * Construct a new Button.
181 * A reference counted object may only be deleted by calling Unreference()
183 virtual ~TETButton();
186 * Creates an internal button.
188 static Toolkit::TETButton New();
191 * @return the pressed signal.
193 Toolkit::TETButton::PressedSignalV2& PressedSignal();
196 * Callback called when an interrupt events is received.
198 void OnTouchPointInterrupted();
201 * Callback received when a down event is received.
205 Toolkit::TETButton::PressedSignalV2 mPressedSignal; ///< Signal emitted when the button is pressed.
208 } // namespace Internal
210 TETButton::TETButton()
214 TETButton::TETButton( const Button& button )
219 TETButton& TETButton::operator=( const TETButton& button )
221 if( &button != this )
223 Button::operator=( button );
228 TETButton TETButton::New()
230 return Internal::TETButton::New();
233 TETButton TETButton::DownCast( BaseHandle handle )
235 return Control::DownCast<TETButton, Internal::TETButton>(handle);
238 TETButton::PressedSignalV2& TETButton::PressedSignal()
240 TETButton button( *this );
241 DALI_ASSERT_ALWAYS( button );
243 Dali::RefObject& handle = button.GetImplementation();
245 return static_cast<Toolkit::Internal::TETButton&>( handle ).PressedSignal();
248 TETButton::TETButton( Internal::TETButton& implementation )
249 : Button( implementation )
252 TETButton::TETButton( Dali::Internal::CustomActor* internal )
255 VerifyCustomActorPointer<Internal::TETButton>(internal);
261 TETButton::TETButton()
267 TETButton::~TETButton()
271 Toolkit::TETButton TETButton::New()
273 // Create the implementation, temporarily owned on stack
274 IntrusivePtr< TETButton > internalTETButton = new TETButton();
276 // Pass ownership to CustomActor
277 Dali::Toolkit::TETButton tetButton( *internalTETButton );
279 // Second-phase init of the implementation
280 // This can only be done after the CustomActor connection has been made...
281 internalTETButton->Initialize();
286 Toolkit::TETButton::PressedSignalV2& TETButton::PressedSignal()
288 return mPressedSignal;
291 void TETButton::OnButtonDown()
293 Toolkit::TETButton handle( GetOwner() );
296 mPressedSignal.Emit( handle );
299 void TETButton::OnTouchPointInterrupted()
301 gOnTouchPointInterrupted = true;
304 } // namespace Internal
306 } // namespace Toolkit
313 class TETButtonPressed : public Dali::ConnectionTracker
322 TETButtonPressed( Actor actor, Test test )
328 bool Callback( Button button )
334 mActor.SetSensitive( false );
339 std::cout <<"VISIBILITY false" << std::endl;
340 mActor.SetVisible( false );
355 static bool TestCallback(Actor actor, const TouchEvent& event)
362 //////////////////////////////////////////////////////////
365 POSITIVE_TC_IDX = 0x01,
369 #define MAX_NUMBER_OF_TESTS 10000
371 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
374 // Add test functionality for all APIs in the class (Positive and Negative)
375 TEST_FUNCTION( UtcDaliPushButtonSetGetAutoRepeating, POSITIVE_TC_IDX );
376 TEST_FUNCTION( UtcDaliPushButtonSetGetToggleButton, POSITIVE_TC_IDX );
377 TEST_FUNCTION( UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton, POSITIVE_TC_IDX );
378 TEST_FUNCTION( UtcDaliPushButtonSetGetToggled01, POSITIVE_TC_IDX );
379 TEST_FUNCTION( UtcDaliPushButtonSetGetToggled02, POSITIVE_TC_IDX );
380 TEST_FUNCTION( UtcDaliPushButtonSetGetAutorepeatingDelayValues01, POSITIVE_TC_IDX );
381 TEST_FUNCTION( UtcDaliPushButtonSetGetAutorepeatingDelayValues02, NEGATIVE_TC_IDX );
382 TEST_FUNCTION( UtcDaliPushButtonSetImages, POSITIVE_TC_IDX );
383 TEST_FUNCTION( UtcDaliPushButtonSetLabelText, POSITIVE_TC_IDX );
384 TEST_FUNCTION( UtcDaliPushButtonPressed, POSITIVE_TC_IDX );
385 TEST_FUNCTION( UtcDaliPushButtonReleased, POSITIVE_TC_IDX );
386 TEST_FUNCTION( UtcDaliPushButtonToggled, POSITIVE_TC_IDX );
387 TEST_FUNCTION( UtcDaliPushButtonInterruptEventWhenInsensitive, POSITIVE_TC_IDX );
388 TEST_FUNCTION( UtcDaliPushButtonInterruptEventWhenNonVisible, POSITIVE_TC_IDX );
389 TEST_FUNCTION( UtcDaliPushButtonProperties, POSITIVE_TC_IDX );
391 // Called only once before first test is run.
392 static void Startup()
396 // Called only once after last test is run
397 static void Cleanup()
402 static void UtcDaliPushButtonSetGetAutoRepeating()
404 ToolkitTestApplication application;
405 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
407 PushButton pushButton = PushButton::New();
409 pushButton.SetAutoRepeating( true );
411 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
413 pushButton.SetAutoRepeating( false );
415 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
417 pushButton.SetAutoRepeating( true );
419 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
422 static void UtcDaliPushButtonSetGetToggleButton()
424 ToolkitTestApplication application;
425 tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
427 PushButton pushButton = PushButton::New();
429 pushButton.SetToggleButton( true );
431 DALI_TEST_CHECK( pushButton.IsToggleButton() );
433 pushButton.SetToggleButton( false );
435 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
437 pushButton.SetToggleButton( true );
439 DALI_TEST_CHECK( pushButton.IsToggleButton() );
442 static void UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton()
444 ToolkitTestApplication application;
445 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
447 PushButton pushButton = PushButton::New();
449 pushButton.SetAutoRepeating( true );
450 pushButton.SetToggleButton( true );
452 DALI_TEST_CHECK( pushButton.IsToggleButton() );
453 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
455 pushButton.SetToggleButton( true );
456 pushButton.SetAutoRepeating( true );
458 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
459 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
462 static void UtcDaliPushButtonSetGetToggled01()
464 ToolkitTestApplication application;
465 tet_infoline(" UtcDaliPushButtonSetGetToggled01");
467 PushButton pushButton = PushButton::New();
469 pushButton.SetToggleButton( true );
470 pushButton.ToggledSignal().Connect( &PushButtonToggled );
472 gPushButtonToggleState = false;
473 pushButton.SetToggled( true );
475 DALI_TEST_CHECK( pushButton.IsToggled() );
476 DALI_TEST_CHECK( gPushButtonToggleState );
478 pushButton.SetToggled( false );
480 DALI_TEST_CHECK( !pushButton.IsToggled() );
481 DALI_TEST_CHECK( !gPushButtonToggleState );
483 pushButton.SetToggled( true );
485 DALI_TEST_CHECK( pushButton.IsToggled() );
486 DALI_TEST_CHECK( gPushButtonToggleState );
489 static void UtcDaliPushButtonSetGetToggled02()
491 ToolkitTestApplication application;
492 tet_infoline(" UtcDaliPushButtonSetGetToggled02");
494 PushButton pushButton = PushButton::New();
496 pushButton.SetToggleButton( false );
497 pushButton.ToggledSignal().Connect( &PushButtonToggled );
499 gPushButtonToggleState = false;
500 pushButton.SetToggled( true );
502 DALI_TEST_CHECK( !pushButton.IsToggled() );
503 DALI_TEST_CHECK( !gPushButtonToggleState );
505 pushButton.SetToggled( false );
507 DALI_TEST_CHECK( !pushButton.IsToggled() );
508 DALI_TEST_CHECK( !gPushButtonToggleState );
510 pushButton.SetToggled( true );
512 DALI_TEST_CHECK( !pushButton.IsToggled() );
513 DALI_TEST_CHECK( !gPushButtonToggleState );
516 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues01()
518 ToolkitTestApplication application;
519 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
521 PushButton pushButton = PushButton::New();
523 pushButton.SetAutoRepeating( true );
525 pushButton.SetInitialAutoRepeatingDelay( 1.f );
526 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
528 pushButton.SetNextAutoRepeatingDelay( 1.f );
529 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
532 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues02()
534 ToolkitTestApplication application;
535 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
537 PushButton pushButton = PushButton::New();
539 bool assert1( false );
540 bool assert2( false );
542 pushButton.SetAutoRepeating( true );
546 pushButton.SetInitialAutoRepeatingDelay( -1.f );
548 catch( Dali::DaliException& e )
550 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
551 DALI_TEST_EQUALS(e.mCondition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
557 pushButton.SetNextAutoRepeatingDelay( -1.f );
559 catch( Dali::DaliException& e )
561 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
562 DALI_TEST_EQUALS(e.mCondition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
566 DALI_TEST_CHECK( assert1 && assert2 );
569 static void UtcDaliPushButtonSetImages()
571 ToolkitTestApplication application;
572 tet_infoline(" UtcDaliPushButtonSetImages");
576 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
577 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
578 imageActor01.SetSize( 20.f, 20.f );
580 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
581 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
582 imageActor02.SetSize( 40.f, 40.f );
584 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
585 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
586 imageActor03.SetSize( 60.f, 60.f );
588 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
589 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
590 imageActor04.SetSize( 80.f, 80.f );
592 Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
593 ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
594 imageActor05.SetSize( 100.f, 100.f );
597 PushButton pushButton = PushButton::New();
599 application.SendNotification();
600 application.Render();
602 // Just check if check box button size changes when a bigger image is set.
604 pushButton.SetButtonImage( image01 );
606 application.SendNotification();
607 application.Render();
609 size = pushButton.GetButtonImage().GetCurrentSize();
611 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
612 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
614 pushButton.SetButtonImage( imageActor01 );
616 application.SendNotification();
617 application.Render();
619 size = pushButton.GetButtonImage().GetCurrentSize();
621 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
622 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
624 pushButton.SetBackgroundImage( image02 );
626 application.SendNotification();
627 application.Render();
629 size = pushButton.GetBackgroundImage().GetCurrentSize();
631 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
632 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
634 pushButton.SetBackgroundImage( imageActor02 );
636 application.SendNotification();
637 application.Render();
639 size = pushButton.GetBackgroundImage().GetCurrentSize();
641 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
642 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
644 pushButton.SetPressedImage( image03 );
646 application.SendNotification();
647 application.Render();
649 size = pushButton.GetPressedImage().GetCurrentSize();
651 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
652 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
654 pushButton.SetPressedImage( imageActor03 );
656 application.SendNotification();
657 application.Render();
659 size = pushButton.GetPressedImage().GetCurrentSize();
661 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
662 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
664 pushButton.SetDimmedBackgroundImage( image04 );
666 application.SendNotification();
667 application.Render();
669 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
671 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
672 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
674 pushButton.SetDimmedBackgroundImage( imageActor04 );
676 application.SendNotification();
677 application.Render();
679 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
681 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
682 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
684 pushButton.SetDimmedImage( image05 );
686 application.SendNotification();
687 application.Render();
689 size = pushButton.GetDimmedImage().GetCurrentSize();
691 DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
692 DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
694 pushButton.SetDimmedImage( imageActor05 );
696 application.SendNotification();
697 application.Render();
699 size = pushButton.GetDimmedImage().GetCurrentSize();
701 DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
702 DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
705 static void UtcDaliPushButtonSetLabelText()
707 ToolkitTestApplication application;
708 tet_infoline(" UtcDaliPushButtonSetLabelText");
710 const std::string STR( "Hola!" );
712 PushButton pushButton = PushButton::New();
714 application.SendNotification();
715 application.Render();
719 pushButton.SetLabelText( STR );
721 textView = TextView::DownCast( pushButton.GetLabelText() );
722 DALI_TEST_CHECK( STR == textView.GetText() );
724 TextView text = TextView::New( STR );
725 pushButton.SetLabelText( text );
727 textView = TextView::DownCast( pushButton.GetLabelText() );
728 DALI_TEST_CHECK( STR == textView.GetText() );
731 static void UtcDaliPushButtonPressed()
733 ToolkitTestApplication application;
734 tet_infoline(" UtcDaliPushButtonPressed");
736 PushButton pushButton = PushButton::New();
737 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
738 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
739 pushButton.SetPosition( 240, 400 );
740 pushButton.SetSize( 100, 100 );
742 Stage::GetCurrent().Add( pushButton );
744 application.SendNotification();
745 application.Render();
747 gPushButtonPressed = false;
749 // connect to its touch signal
750 pushButton.PressedSignal().Connect( &PushButtonPressed );
752 Dali::Integration::TouchEvent eventDown;
753 eventDown.AddPoint( pointDownInside );
755 // flush the queue and render once
756 application.SendNotification();
757 application.Render();
758 application.ProcessEvent( eventDown );
760 DALI_TEST_CHECK( gPushButtonPressed );
763 static void UtcDaliPushButtonReleased()
765 ToolkitTestApplication application;
766 tet_infoline(" UtcDaliPushButtonReleased");
768 PushButton pushButton = PushButton::New();
769 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
770 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
771 pushButton.SetPosition( 240, 400 );
772 pushButton.SetSize( 100, 100 );
774 Stage::GetCurrent().Add( pushButton );
776 application.SendNotification();
777 application.Render();
779 // connect to its touch signal
780 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
782 Dali::Integration::TouchEvent event;
784 // Test1. Touch point down and up inside the button.
786 gPushButtonReleased = false;
787 event = Dali::Integration::TouchEvent();
788 event.AddPoint( pointDownInside );
789 application.ProcessEvent( event );
791 event = Dali::Integration::TouchEvent();
792 event.AddPoint( pointUpInside );
793 application.ProcessEvent( event );
795 DALI_TEST_CHECK( gPushButtonReleased );
797 // Test2. Touch point down and up outside the button.
799 gPushButtonReleased = false;
800 event = Dali::Integration::TouchEvent();
801 event.AddPoint( pointDownOutside );
802 application.ProcessEvent( event );
804 event = Dali::Integration::TouchEvent();
805 event.AddPoint( pointUpOutside );
806 application.ProcessEvent( event );
808 DALI_TEST_CHECK( !gPushButtonReleased );
810 // Test3. Touch point down inside and up outside the button.
812 gPushButtonReleased = false;
813 event = Dali::Integration::TouchEvent();
814 event.AddPoint( pointDownInside );
815 application.ProcessEvent( event );
817 event = Dali::Integration::TouchEvent();
818 event.AddPoint( pointLeave );
819 application.ProcessEvent( event );
821 event = Dali::Integration::TouchEvent();
822 event.AddPoint( pointUpOutside );
823 application.ProcessEvent( event );
825 DALI_TEST_CHECK( gPushButtonReleased );
827 // Test4. Touch point down outside and up inside the button.
829 gPushButtonReleased = false;
830 event = Dali::Integration::TouchEvent();
831 event.AddPoint( pointDownOutside );
832 application.ProcessEvent( event );
834 event = Dali::Integration::TouchEvent();
835 event.AddPoint( pointEnter );
836 application.ProcessEvent( event );
838 event = Dali::Integration::TouchEvent();
839 event.AddPoint( pointUpInside );
840 application.ProcessEvent( event );
842 DALI_TEST_CHECK( !gPushButtonReleased );
845 static void UtcDaliPushButtonToggled()
847 ToolkitTestApplication application;
848 tet_infoline(" UtcDaliPushButtonToggled");
850 PushButton pushButton = PushButton::New();
851 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
852 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
853 pushButton.SetPosition( 240, 400 );
854 pushButton.SetSize( 100, 100 );
856 Stage::GetCurrent().Add( pushButton );
858 application.SendNotification();
859 application.Render();
861 // connect to its touch signal
862 pushButton.ToggledSignal().Connect( &PushButtonToggled );
864 Dali::Integration::TouchEvent event;
866 // Test1. No toggle button.
868 gPushButtonToggleState = false;
869 event = Dali::Integration::TouchEvent();
870 event.AddPoint( pointDownInside );
871 application.ProcessEvent( event );
873 event = Dali::Integration::TouchEvent();
874 event.AddPoint( pointUpInside );
875 application.ProcessEvent( event );
877 DALI_TEST_CHECK( !gPushButtonToggleState );
879 // Set toggle property.
880 pushButton.SetToggleButton( true );
882 // Test2. Touch point down and up inside the button twice.
883 gPushButtonToggleState = false;
884 event = Dali::Integration::TouchEvent();
885 event.AddPoint( pointDownInside );
886 application.ProcessEvent( event );
888 event = Dali::Integration::TouchEvent();
889 event.AddPoint( pointUpInside );
890 application.ProcessEvent( event );
892 DALI_TEST_CHECK( gPushButtonToggleState );
894 event = Dali::Integration::TouchEvent();
895 event.AddPoint( pointDownInside );
896 application.ProcessEvent( event );
898 event = Dali::Integration::TouchEvent();
899 event.AddPoint( pointUpInside );
900 application.ProcessEvent( event );
902 DALI_TEST_CHECK( !gPushButtonToggleState );
904 // Test3. Touch point down and up outside the button.
906 gPushButtonToggleState = false;
907 event = Dali::Integration::TouchEvent();
908 event.AddPoint( pointDownOutside );
909 application.ProcessEvent( event );
911 event = Dali::Integration::TouchEvent();
912 event.AddPoint( pointUpOutside );
913 application.ProcessEvent( event );
915 DALI_TEST_CHECK( !gPushButtonToggleState );
917 // Test4. Touch point down inside and up outside the button.
919 gPushButtonToggleState = false;
920 event = Dali::Integration::TouchEvent();
921 event.AddPoint( pointDownInside );
922 application.ProcessEvent( event );
924 event = Dali::Integration::TouchEvent();
925 event.AddPoint( pointLeave );
926 application.ProcessEvent( event );
928 event = Dali::Integration::TouchEvent();
929 event.AddPoint( pointUpOutside );
930 application.ProcessEvent( event );
932 DALI_TEST_CHECK( !gPushButtonToggleState );
934 // Test5. Touch point down outside and up inside the button.
936 gPushButtonToggleState = false;
937 event = Dali::Integration::TouchEvent();
938 event.AddPoint( pointDownOutside );
939 application.ProcessEvent( event );
941 event = Dali::Integration::TouchEvent();
942 event.AddPoint( pointEnter );
943 application.ProcessEvent( event );
945 event = Dali::Integration::TouchEvent();
946 event.AddPoint( pointUpInside );
947 application.ProcessEvent( event );
949 DALI_TEST_CHECK( !gPushButtonToggleState );
952 static void UtcDaliPushButtonInterruptEventWhenInsensitive()
954 ToolkitTestApplication application;
955 tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive");
957 // * Creates an actor which contains a button.
958 // * The size of the actor is bigger than the button.
959 // * The button's boundary is contained in the actor's one.
960 Actor actor = Actor::New();
961 TETButton tetButton= Toolkit::TETButton::New();
963 actor.SetName( "Actor" );
964 tetButton.SetName( "TETButton" );
966 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
967 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
968 actor.SetPosition( 0, 0 );
969 actor.SetSize( 400, 800 );
971 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
972 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
973 tetButton.SetPosition( 240, 400 );
974 tetButton.SetSize( 100, 100 );
976 actor.Add( tetButton );
977 Stage::GetCurrent().Add( actor );
979 // * Actor's touch event is connected to a callback function
980 // and this callback function consumes the event.
981 actor.TouchedSignal().Connect( &TestCallback );
983 // * Button's pressed signal is connected to a callback function
984 // which also consumes the event.
985 // * Changes the sensitiveness of the button to false.
986 TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS );
987 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
989 // Initializes TET state.
990 gOnTouchPointInterrupted = false;
991 tetButton.SetSensitive( true );
993 Dali::Integration::TouchEvent event;
997 // Test a down point inside the button which is also consumed by the actor, and an up point
998 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1001 application.SendNotification();
1002 application.Render();
1004 // A down event is sent inside the button's boundary.
1006 event = Dali::Integration::TouchEvent();
1007 event.AddPoint( pointDownInside );
1009 // flush the queue and render once
1010 application.SendNotification();
1011 application.Render();
1012 application.ProcessEvent( event );
1014 // An up event is sent outside the button's boundary but inside the actor's one.
1016 event = Dali::Integration::TouchEvent();
1017 event.AddPoint( pointUpOutside );
1019 // flush the queue and render once
1020 application.SendNotification();
1021 application.Render();
1022 application.ProcessEvent( event );
1024 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1026 // Test a down point inside the button which is also consumed by the actor, and a motion point
1027 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1030 // Initializes TET state.
1031 gOnTouchPointInterrupted = false;
1032 actor.SetSensitive( true );
1033 tetButton.SetSensitive( true );
1035 application.SendNotification();
1036 application.Render();
1038 // A down event is sent inside the button's boundary.
1040 event = Dali::Integration::TouchEvent();
1041 event.AddPoint( pointDownInside );
1043 // flush the queue and render once
1044 application.SendNotification();
1045 application.Render();
1046 application.ProcessEvent( event );
1048 // A motion event is sent outside the button's boundary but inside the actor's one.
1050 event = Dali::Integration::TouchEvent();
1051 event.AddPoint( pointMotionOut );
1053 // flush the queue and render once
1054 application.SendNotification();
1055 application.Render();
1056 application.ProcessEvent( event );
1058 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1060 // Test a down point inside the button which is also consumed by the actor, and an up point
1061 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
1063 // Initializes TET state.
1064 gOnTouchPointInterrupted = false;
1065 actor.SetSensitive( true );
1066 tetButton.SetSensitive( true );
1068 // A down event is sent inside the button's boundary.
1070 event = Dali::Integration::TouchEvent();
1071 event.AddPoint( pointDownInside );
1073 // flush the queue and render once
1074 application.SendNotification();
1075 application.Render();
1076 application.ProcessEvent( event );
1078 actor.SetSensitive( true );
1079 // An up event is sent inside the button's boundary.
1081 event = Dali::Integration::TouchEvent();
1082 event.AddPoint( pointUpInside );
1084 // flush the queue and render once
1085 application.SendNotification();
1086 application.Render();
1087 application.ProcessEvent( event );
1089 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1092 static void UtcDaliPushButtonInterruptEventWhenNonVisible()
1094 ToolkitTestApplication application;
1095 tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible");
1097 // Does same test as above but changing the visibility instead the sensitiveness.
1099 // * Creates an actor which contains a button.
1100 // * The size of the actor is bigger than the button.
1101 // * The button's boundary is contained in the actor's one.
1102 Actor actor = Actor::New();
1103 TETButton tetButton = Toolkit::TETButton::New();
1105 actor.SetName( "Actor" );
1106 tetButton.SetName( "TETButton" );
1108 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1109 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1110 actor.SetPosition( 0, 0 );
1111 actor.SetSize( 400, 800 );
1113 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1114 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1115 tetButton.SetPosition( 240, 400 );
1116 tetButton.SetSize( 100, 100 );
1118 actor.Add( tetButton );
1119 Stage::GetCurrent().Add( actor );
1121 // * Actor's touch event is connected to a callback function
1122 // and this callback function consumes the event.
1123 actor.TouchedSignal().Connect( &TestCallback );
1125 // * Button's pressed signal is connected to a callback function
1126 // which also consumes the event.
1127 // * Changes the visibility of the button to false.
1128 TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY );
1129 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
1131 // Initializes TET state.
1132 gOnTouchPointInterrupted = false;
1133 tetButton.SetVisible( true );
1135 Dali::Integration::TouchEvent event;
1139 // Test a down point inside the button which is also consumed by the actor, and an up point
1140 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1143 application.SendNotification();
1144 application.Render();
1146 // A down event is sent inside the button's boundary.
1148 event = Dali::Integration::TouchEvent();
1149 event.AddPoint( pointDownInside );
1151 // flush the queue and render once
1152 application.SendNotification();
1153 application.Render();
1154 application.ProcessEvent( event );
1156 // More renders are needed in order to allow the node of the actor to become invisible.
1157 application.SendNotification();
1158 application.Render();
1159 application.SendNotification();
1160 application.Render();
1161 application.SendNotification();
1162 application.Render();
1164 // An up event is sent outside the button's boundary but inside the actor's one.
1166 event = Dali::Integration::TouchEvent();
1167 event.AddPoint( pointUpOutside );
1169 // flush the queue and render once
1170 application.SendNotification();
1171 application.Render();
1172 application.ProcessEvent( event );
1174 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1176 // Test a down point inside the button which is also consumed by the actor, and a motion point
1177 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
1180 // Initializes TET state.
1181 gOnTouchPointInterrupted = false;
1182 tetButton.SetVisible( true );
1184 application.SendNotification();
1185 application.Render();
1186 application.SendNotification();
1187 application.Render();
1188 application.SendNotification();
1189 application.Render();
1191 // A down event is sent inside the button's boundary.
1193 event = Dali::Integration::TouchEvent();
1194 event.AddPoint( pointDownInside );
1196 // flush the queue and render once
1197 application.SendNotification();
1198 application.Render();
1199 application.ProcessEvent( event );
1201 // More renders are needed in order to allow the node of the actor to become invisible.
1202 application.SendNotification();
1203 application.Render();
1204 application.SendNotification();
1205 application.Render();
1206 application.SendNotification();
1207 application.Render();
1209 // A motion event is sent outside the button's boundary but inside the actor's one.
1211 event = Dali::Integration::TouchEvent();
1212 event.AddPoint( pointMotionOut );
1214 // flush the queue and render once
1215 application.SendNotification();
1216 application.Render();
1217 application.ProcessEvent( event );
1219 DALI_TEST_CHECK( gOnTouchPointInterrupted );
1221 // Test a down point inside the button which is also consumed by the actor, and an up point
1222 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
1224 // Initializes TET state.
1225 gOnTouchPointInterrupted = false;
1226 tetButton.SetVisible( true );
1228 application.SendNotification();
1229 application.Render();
1230 application.SendNotification();
1231 application.Render();
1232 application.SendNotification();
1233 application.Render();
1235 // A down event is sent inside the button's boundary.
1237 event = Dali::Integration::TouchEvent();
1238 event.AddPoint( pointDownInside );
1240 // flush the queue and render once
1241 application.SendNotification();
1242 application.Render();
1243 application.ProcessEvent( event );
1245 tetButton.SetVisible( true );
1247 application.SendNotification();
1248 application.Render();
1249 application.SendNotification();
1250 application.Render();
1251 application.SendNotification();
1252 application.Render();
1254 // An up event is sent inside the button's boundary.
1256 event = Dali::Integration::TouchEvent();
1257 event.AddPoint( pointUpInside );
1259 // flush the queue and render once
1260 application.SendNotification();
1261 application.Render();
1262 application.ProcessEvent( event );
1264 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1267 void UtcDaliPushButtonProperties()
1269 ToolkitTestApplication application;
1271 PushButton button = PushButton::New();
1272 Stage::GetCurrent().Add( button );
1274 // PushButton::PROPERTY_AUTO_REPEATING
1275 button.SetAutoRepeating( false );
1276 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
1277 button.SetProperty( PushButton::PROPERTY_AUTO_REPEATING, true );
1278 DALI_TEST_CHECK( button.IsAutoRepeating() ) ;
1279 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
1281 // PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY
1282 button.SetInitialAutoRepeatingDelay( 10.0f );
1283 DALI_TEST_EQUALS( 10.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1284 button.SetProperty( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, 25.0f );
1285 DALI_TEST_EQUALS( 25.0f, button.GetInitialAutoRepeatingDelay(), TEST_LOCATION );
1286 DALI_TEST_EQUALS( 25.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1288 // PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY
1289 button.SetNextAutoRepeatingDelay( 3.0f );
1290 DALI_TEST_EQUALS( 3.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1291 button.SetProperty( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY, 4.0f );
1292 DALI_TEST_EQUALS( 4.0f, button.GetNextAutoRepeatingDelay(), TEST_LOCATION );
1293 DALI_TEST_EQUALS( 4.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1295 // PushButton::PROPERTY_TOGGLABLE
1296 button.SetToggleButton( false );
1297 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
1298 button.SetProperty( PushButton::PROPERTY_TOGGLABLE, true );
1299 DALI_TEST_CHECK( button.IsToggleButton() ) ;
1300 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
1302 // PushButton::PROPERTY_TOGGLE
1303 button.SetToggled( false );
1304 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
1305 button.SetProperty( PushButton::PROPERTY_TOGGLE, true );
1306 DALI_TEST_CHECK( button.IsToggled() ) ;
1307 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
1309 // PushButton::PROPERTY_NORMAL_STATE_ACTOR
1311 button.SetButtonImage( Image::New( "IMAGE_PATH_1") );
1312 DALI_TEST_EQUALS( "IMAGE_PATH_1", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1315 map.push_back( Property::StringValuePair( "type", "ImageActor" ) );
1317 button.SetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR, map );
1318 DALI_TEST_EQUALS( "ImageActor", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1321 // PushButton::PROPERTY_PRESSED_IMAGE
1323 button.SetPressedImage( Image::New( "IMAGE_PATH_2") );
1324 DALI_TEST_EQUALS( "IMAGE_PATH_2", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1327 map.push_back( Property::StringValuePair( "type", "TextActor" ) );
1329 button.SetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR, map );
1330 DALI_TEST_EQUALS( "TextActor", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1333 // PushButton::PROPERTY_DIMMED_STATE_ACTOR
1335 button.SetDimmedImage( Image::New( "IMAGE_PATH_3") );
1336 DALI_TEST_EQUALS( "IMAGE_PATH_3", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1339 map.push_back( Property::StringValuePair( "type", "Actor" ) );
1341 button.SetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR, map );
1342 DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1345 // PushButton::PROPERTY_LABEL_ACTOR
1347 button.SetLabelText( "LABEL_TEXT_CUSTOM" );
1348 DALI_TEST_EQUALS( "TextView", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1351 map.push_back( Property::StringValuePair( "type", "Actor" ) );
1353 button.SetProperty( PushButton::PROPERTY_LABEL_ACTOR, map );
1354 DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );