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.
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali-toolkit/internal/controls/buttons/button-impl.h>
28 using namespace Toolkit;
33 static bool gPushButtonToggleState = false;
34 bool PushButtonToggled( Button button, bool toggled )
36 gPushButtonToggleState = toggled && ( toggled == static_cast<PushButton&>( button ).IsToggled() );
41 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
42 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
43 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
44 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
45 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
46 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
47 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
51 //////////////////////////////////////////////////////////
55 static bool gOnTouchPointInterrupted = false;
70 * Creates a Button to test if interrupt events are handled correctly.
72 class TETButton : public Button
76 typedef Signal< bool ( Button ) > PressedSignalType;
78 PressedSignalType& PressedSignal();
81 * Default constructor.
88 TETButton( const Button& button );
91 * Assignment operator.
93 TETButton& operator=( const TETButton& button );
96 * Creates and initializes a new button.
98 static TETButton New();
101 * Down cast to TETButton.
103 static TETButton DownCast( BaseHandle handle );
106 * Creates a handle using the Toolkit::Internal implementation.
107 * @param[in] implementation The Control implementation.
109 TETButton( Internal::TETButton& implementation );
112 * Allows the creation of this Control from an Internal::CustomActor pointer.
113 * @param[in] internal A pointer to the internal CustomActor.
115 TETButton( Dali::Internal::CustomActor* internal );
122 * Internal implementation
124 class TETButton : public Button
128 * Construct a new Button.
133 * A reference counted object may only be deleted by calling Unreference()
135 virtual ~TETButton();
138 * Creates an internal button.
140 static Toolkit::TETButton New();
143 * @return the pressed signal.
145 Toolkit::TETButton::PressedSignalType& PressedSignal();
148 * Callback called when an interrupt events is received.
150 void OnTouchPointInterrupted();
153 * Callback received when a down event is received.
157 Toolkit::TETButton::PressedSignalType mPressedSignal; ///< Signal emitted when the button is pressed.
160 } // namespace Internal
162 TETButton::TETButton()
166 TETButton::TETButton( const Button& button )
171 TETButton& TETButton::operator=( const TETButton& button )
173 if( &button != this )
175 Button::operator=( button );
180 TETButton TETButton::New()
182 return Internal::TETButton::New();
185 TETButton TETButton::DownCast( BaseHandle handle )
187 return Control::DownCast<TETButton, Internal::TETButton>(handle);
190 TETButton::PressedSignalType& TETButton::PressedSignal()
192 TETButton button( *this );
193 DALI_ASSERT_ALWAYS( button );
195 Dali::RefObject& handle = button.GetImplementation();
197 return static_cast<Toolkit::Internal::TETButton&>( handle ).PressedSignal();
200 TETButton::TETButton( Internal::TETButton& implementation )
201 : Button( implementation )
204 TETButton::TETButton( Dali::Internal::CustomActor* internal )
207 VerifyCustomActorPointer<Internal::TETButton>(internal);
213 TETButton::TETButton()
219 TETButton::~TETButton()
223 Toolkit::TETButton TETButton::New()
225 // Create the implementation, temporarily owned on stack
226 IntrusivePtr< TETButton > internalTETButton = new TETButton();
228 // Pass ownership to CustomActor
229 Dali::Toolkit::TETButton tetButton( *internalTETButton );
231 // Second-phase init of the implementation
232 // This can only be done after the CustomActor connection has been made...
233 internalTETButton->Initialize();
238 Toolkit::TETButton::PressedSignalType& TETButton::PressedSignal()
240 return mPressedSignal;
243 void TETButton::OnButtonDown()
245 Toolkit::TETButton handle( GetOwner() );
248 mPressedSignal.Emit( handle );
251 void TETButton::OnTouchPointInterrupted()
253 gOnTouchPointInterrupted = true;
256 } // namespace Internal
258 } // namespace Toolkit
265 class TETButtonPressed : public Dali::ConnectionTracker
274 TETButtonPressed( Actor actor, Test test )
280 bool Callback( Button button )
286 mActor.SetSensitive( false );
291 std::cout <<"VISIBILITY false" << std::endl;
292 mActor.SetVisible( false );
307 static bool TestCallback(Actor actor, const TouchEvent& event)
314 //////////////////////////////////////////////////////////
317 int UtcDaliPushButtonInterruptEventWhenInsensitive(void)
319 ToolkitTestApplication application;
320 tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive");
322 // * Creates an actor which contains a button.
323 // * The size of the actor is bigger than the button.
324 // * The button's boundary is contained in the actor's one.
325 Actor actor = Actor::New();
326 TETButton tetButton= Toolkit::TETButton::New();
328 actor.SetName( "Actor" );
329 tetButton.SetName( "TETButton" );
331 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
332 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
333 actor.SetPosition( 0, 0 );
334 actor.SetSize( 400, 800 );
336 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
337 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
338 tetButton.SetPosition( 240, 400 );
339 tetButton.SetSize( 100, 100 );
341 actor.Add( tetButton );
342 Stage::GetCurrent().Add( actor );
344 // * Actor's touch event is connected to a callback function
345 // and this callback function consumes the event.
346 actor.TouchedSignal().Connect( &TestCallback );
348 // * Button's pressed signal is connected to a callback function
349 // which also consumes the event.
350 // * Changes the sensitiveness of the button to false.
351 TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS );
352 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
354 // Initializes TET state.
355 gOnTouchPointInterrupted = false;
356 tetButton.SetSensitive( true );
358 Dali::Integration::TouchEvent event;
362 // Test a down point inside the button which is also consumed by the actor, and an up point
363 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
366 application.SendNotification();
367 application.Render();
369 // A down event is sent inside the button's boundary.
371 event = Dali::Integration::TouchEvent();
372 event.AddPoint( pointDownInside );
374 // flush the queue and render once
375 application.SendNotification();
376 application.Render();
377 application.ProcessEvent( event );
379 // An up event is sent outside the button's boundary but inside the actor's one.
381 event = Dali::Integration::TouchEvent();
382 event.AddPoint( pointUpOutside );
384 // flush the queue and render once
385 application.SendNotification();
386 application.Render();
387 application.ProcessEvent( event );
389 DALI_TEST_CHECK( gOnTouchPointInterrupted );
391 // Test a down point inside the button which is also consumed by the actor, and a motion point
392 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
395 // Initializes TET state.
396 gOnTouchPointInterrupted = false;
397 actor.SetSensitive( true );
398 tetButton.SetSensitive( true );
400 application.SendNotification();
401 application.Render();
403 // A down event is sent inside the button's boundary.
405 event = Dali::Integration::TouchEvent();
406 event.AddPoint( pointDownInside );
408 // flush the queue and render once
409 application.SendNotification();
410 application.Render();
411 application.ProcessEvent( event );
413 // A motion event is sent outside the button's boundary but inside the actor's one.
415 event = Dali::Integration::TouchEvent();
416 event.AddPoint( pointMotionOut );
418 // flush the queue and render once
419 application.SendNotification();
420 application.Render();
421 application.ProcessEvent( event );
423 DALI_TEST_CHECK( gOnTouchPointInterrupted );
425 // Test a down point inside the button which is also consumed by the actor, and an up point
426 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
428 // Initializes TET state.
429 gOnTouchPointInterrupted = false;
430 actor.SetSensitive( true );
431 tetButton.SetSensitive( true );
433 // A down event is sent inside the button's boundary.
435 event = Dali::Integration::TouchEvent();
436 event.AddPoint( pointDownInside );
438 // flush the queue and render once
439 application.SendNotification();
440 application.Render();
441 application.ProcessEvent( event );
443 actor.SetSensitive( true );
444 // An up event is sent inside the button's boundary.
446 event = Dali::Integration::TouchEvent();
447 event.AddPoint( pointUpInside );
449 // flush the queue and render once
450 application.SendNotification();
451 application.Render();
452 application.ProcessEvent( event );
454 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
458 int UtcDaliPushButtonInterruptEventWhenNonVisible(void)
460 ToolkitTestApplication application;
461 tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible");
463 // Does same test as above but changing the visibility instead the sensitiveness.
465 // * Creates an actor which contains a button.
466 // * The size of the actor is bigger than the button.
467 // * The button's boundary is contained in the actor's one.
468 Actor actor = Actor::New();
469 TETButton tetButton = Toolkit::TETButton::New();
471 actor.SetName( "Actor" );
472 tetButton.SetName( "TETButton" );
474 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
475 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
476 actor.SetPosition( 0, 0 );
477 actor.SetSize( 400, 800 );
479 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
480 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
481 tetButton.SetPosition( 240, 400 );
482 tetButton.SetSize( 100, 100 );
484 actor.Add( tetButton );
485 Stage::GetCurrent().Add( actor );
487 // * Actor's touch event is connected to a callback function
488 // and this callback function consumes the event.
489 actor.TouchedSignal().Connect( &TestCallback );
491 // * Button's pressed signal is connected to a callback function
492 // which also consumes the event.
493 // * Changes the visibility of the button to false.
494 TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY );
495 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
497 // Initializes TET state.
498 gOnTouchPointInterrupted = false;
499 tetButton.SetVisible( true );
501 Dali::Integration::TouchEvent event;
505 // Test a down point inside the button which is also consumed by the actor, and an up point
506 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
509 application.SendNotification();
510 application.Render();
512 // A down event is sent inside the button's boundary.
514 event = Dali::Integration::TouchEvent();
515 event.AddPoint( pointDownInside );
517 // flush the queue and render once
518 application.SendNotification();
519 application.Render();
520 application.ProcessEvent( event );
522 // More renders are needed in order to allow the node of the actor to become invisible.
523 application.SendNotification();
524 application.Render();
525 application.SendNotification();
526 application.Render();
527 application.SendNotification();
528 application.Render();
530 // An up event is sent outside the button's boundary but inside the actor's one.
532 event = Dali::Integration::TouchEvent();
533 event.AddPoint( pointUpOutside );
535 // flush the queue and render once
536 application.SendNotification();
537 application.Render();
538 application.ProcessEvent( event );
540 DALI_TEST_CHECK( gOnTouchPointInterrupted );
542 // Test a down point inside the button which is also consumed by the actor, and a motion point
543 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
546 // Initializes TET state.
547 gOnTouchPointInterrupted = false;
548 tetButton.SetVisible( true );
550 application.SendNotification();
551 application.Render();
552 application.SendNotification();
553 application.Render();
554 application.SendNotification();
555 application.Render();
557 // A down event is sent inside the button's boundary.
559 event = Dali::Integration::TouchEvent();
560 event.AddPoint( pointDownInside );
562 // flush the queue and render once
563 application.SendNotification();
564 application.Render();
565 application.ProcessEvent( event );
567 // More renders are needed in order to allow the node of the actor to become invisible.
568 application.SendNotification();
569 application.Render();
570 application.SendNotification();
571 application.Render();
572 application.SendNotification();
573 application.Render();
575 // A motion event is sent outside the button's boundary but inside the actor's one.
577 event = Dali::Integration::TouchEvent();
578 event.AddPoint( pointMotionOut );
580 // flush the queue and render once
581 application.SendNotification();
582 application.Render();
583 application.ProcessEvent( event );
585 DALI_TEST_CHECK( gOnTouchPointInterrupted );
587 // Test a down point inside the button which is also consumed by the actor, and an up point
588 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
590 // Initializes TET state.
591 gOnTouchPointInterrupted = false;
592 tetButton.SetVisible( true );
594 application.SendNotification();
595 application.Render();
596 application.SendNotification();
597 application.Render();
598 application.SendNotification();
599 application.Render();
601 // A down event is sent inside the button's boundary.
603 event = Dali::Integration::TouchEvent();
604 event.AddPoint( pointDownInside );
606 // flush the queue and render once
607 application.SendNotification();
608 application.Render();
609 application.ProcessEvent( event );
611 tetButton.SetVisible( true );
613 application.SendNotification();
614 application.Render();
615 application.SendNotification();
616 application.Render();
617 application.SendNotification();
618 application.Render();
620 // An up event is sent inside the button's boundary.
622 event = Dali::Integration::TouchEvent();
623 event.AddPoint( pointUpInside );
625 // flush the queue and render once
626 application.SendNotification();
627 application.Render();
628 application.ProcessEvent( event );
630 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
634 int UtcDaliPushButtonProperties(void)
636 ToolkitTestApplication application;
638 PushButton button = PushButton::New();
639 Stage::GetCurrent().Add( button );
641 // Button::PROPERTY_AUTO_REPEATING
642 button.SetAutoRepeating( false );
643 DALI_TEST_CHECK( ! button.GetProperty< bool >( Button::PROPERTY_AUTO_REPEATING ) );
644 button.SetProperty( Button::PROPERTY_AUTO_REPEATING, true );
645 DALI_TEST_CHECK( button.IsAutoRepeating() ) ;
646 DALI_TEST_CHECK( button.GetProperty< bool >( Button::PROPERTY_AUTO_REPEATING ) );
648 // Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY
649 button.SetInitialAutoRepeatingDelay( 10.0f );
650 DALI_TEST_EQUALS( 10.0f, button.GetProperty< float >( Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
651 button.SetProperty( Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, 25.0f );
652 DALI_TEST_EQUALS( 25.0f, button.GetInitialAutoRepeatingDelay(), TEST_LOCATION );
653 DALI_TEST_EQUALS( 25.0f, button.GetProperty< float >( Button::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
655 // Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY
656 button.SetNextAutoRepeatingDelay( 3.0f );
657 DALI_TEST_EQUALS( 3.0f, button.GetProperty< float >( Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
658 button.SetProperty( Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY, 4.0f );
659 DALI_TEST_EQUALS( 4.0f, button.GetNextAutoRepeatingDelay(), TEST_LOCATION );
660 DALI_TEST_EQUALS( 4.0f, button.GetProperty< float >( Button::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
662 // Button::PROPERTY_TOGGLABLE
663 button.SetToggleButton( false );
664 DALI_TEST_CHECK( ! button.GetProperty< bool >( Button::PROPERTY_TOGGLABLE ) );
665 button.SetProperty( Button::PROPERTY_TOGGLABLE, true );
666 DALI_TEST_CHECK( button.IsToggleButton() ) ;
667 DALI_TEST_CHECK( button.GetProperty< bool >( Button::PROPERTY_TOGGLABLE ) );
669 // Button::PROPERTY_TOGGLED
670 button.SetToggled( false );
671 DALI_TEST_CHECK( ! button.GetProperty< bool >( Button::PROPERTY_TOGGLED ) );
672 button.SetProperty( Button::PROPERTY_TOGGLED, true );
673 DALI_TEST_CHECK( button.IsToggled() ) ;
674 DALI_TEST_CHECK( button.GetProperty< bool >( Button::PROPERTY_TOGGLED ) );
676 // Button::PROPERTY_NORMAL_STATE_ACTOR
678 button.SetButtonImage( Image::New( "IMAGE_PATH_1") );
679 DALI_TEST_EQUALS( "IMAGE_PATH_1", button.GetProperty( Button::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
682 map[ "type" ] = "ImageActor";
684 button.SetProperty( Button::PROPERTY_NORMAL_STATE_ACTOR, map );
685 DALI_TEST_EQUALS( "ImageActor", button.GetProperty( Button::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
688 // Button::PROPERTY_SELECTED_STATE_ACTOR
690 button.SetSelectedImage( Image::New( "IMAGE_PATH_2") );
691 DALI_TEST_EQUALS( "IMAGE_PATH_2", button.GetProperty( Button::PROPERTY_SELECTED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
694 map[ "type" ] = "Actor";
696 button.SetProperty( Button::PROPERTY_SELECTED_STATE_ACTOR, map );
697 DALI_TEST_EQUALS( "Actor", button.GetProperty( Button::PROPERTY_SELECTED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
698 DALI_TEST_CHECK( "ImageActor" != button.GetProperty( Button::PROPERTY_SELECTED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >() );
701 // Button::PROPERTY_DISABLED_STATE_ACTOR
703 button.SetDimmedImage( Image::New( "IMAGE_PATH_3") );
704 DALI_TEST_EQUALS( "IMAGE_PATH_3", button.GetProperty( Button::PROPERTY_DISABLED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
707 map[ "type" ] = "Actor";
709 button.SetProperty( Button::PROPERTY_DISABLED_STATE_ACTOR, map );
710 DALI_TEST_EQUALS( "Actor", button.GetProperty( Button::PROPERTY_DISABLED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
713 // Button::PROPERTY_LABEL_ACTOR
715 button.SetLabel( "LABEL_TEXT_CUSTOM" );
716 DALI_TEST_EQUALS( "TextView", button.GetProperty( Button::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
719 map[ "type" ] = "Actor";
721 button.SetProperty( Button::PROPERTY_LABEL_ACTOR, map );
722 DALI_TEST_EQUALS( "Actor", button.GetProperty( Button::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );