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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
23 #include <dali-toolkit/internal/controls/buttons/button-impl.h>
27 using namespace Toolkit;
32 static bool gPushButtonToggleState = false;
33 bool PushButtonToggled( Button button, bool toggled )
35 gPushButtonToggleState = toggled && ( toggled == static_cast<PushButton&>( button ).IsToggled() );
40 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
41 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
42 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
43 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
44 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
45 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
46 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
50 //////////////////////////////////////////////////////////
54 static bool gOnTouchPointInterrupted = false;
69 * Creates a Button to test if interrupt events are handled correctly.
71 class TETButton : public Button
75 typedef SignalV2< bool ( Button ) > PressedSignalV2;
77 PressedSignalV2& PressedSignal();
80 * Default constructor.
87 TETButton( const Button& button );
90 * Assignment operator.
92 TETButton& operator=( const TETButton& button );
95 * Creates and initializes a new button.
97 static TETButton New();
100 * Down cast to TETButton.
102 static TETButton DownCast( BaseHandle handle );
105 * Creates a handle using the Toolkit::Internal implementation.
106 * @param[in] implementation The Control implementation.
108 TETButton( Internal::TETButton& implementation );
111 * Allows the creation of this Control from an Internal::CustomActor pointer.
112 * @param[in] internal A pointer to the internal CustomActor.
114 TETButton( Dali::Internal::CustomActor* internal );
121 * Internal implementation
123 class TETButton : public Button
127 * Construct a new Button.
132 * A reference counted object may only be deleted by calling Unreference()
134 virtual ~TETButton();
137 * Creates an internal button.
139 static Toolkit::TETButton New();
142 * @return the pressed signal.
144 Toolkit::TETButton::PressedSignalV2& PressedSignal();
147 * Callback called when an interrupt events is received.
149 void OnTouchPointInterrupted();
152 * Callback received when a down event is received.
156 Toolkit::TETButton::PressedSignalV2 mPressedSignal; ///< Signal emitted when the button is pressed.
159 } // namespace Internal
161 TETButton::TETButton()
165 TETButton::TETButton( const Button& button )
170 TETButton& TETButton::operator=( const TETButton& button )
172 if( &button != this )
174 Button::operator=( button );
179 TETButton TETButton::New()
181 return Internal::TETButton::New();
184 TETButton TETButton::DownCast( BaseHandle handle )
186 return Control::DownCast<TETButton, Internal::TETButton>(handle);
189 TETButton::PressedSignalV2& TETButton::PressedSignal()
191 TETButton button( *this );
192 DALI_ASSERT_ALWAYS( button );
194 Dali::RefObject& handle = button.GetImplementation();
196 return static_cast<Toolkit::Internal::TETButton&>( handle ).PressedSignal();
199 TETButton::TETButton( Internal::TETButton& implementation )
200 : Button( implementation )
203 TETButton::TETButton( Dali::Internal::CustomActor* internal )
206 VerifyCustomActorPointer<Internal::TETButton>(internal);
212 TETButton::TETButton()
218 TETButton::~TETButton()
222 Toolkit::TETButton TETButton::New()
224 // Create the implementation, temporarily owned on stack
225 IntrusivePtr< TETButton > internalTETButton = new TETButton();
227 // Pass ownership to CustomActor
228 Dali::Toolkit::TETButton tetButton( *internalTETButton );
230 // Second-phase init of the implementation
231 // This can only be done after the CustomActor connection has been made...
232 internalTETButton->Initialize();
237 Toolkit::TETButton::PressedSignalV2& TETButton::PressedSignal()
239 return mPressedSignal;
242 void TETButton::OnButtonDown()
244 Toolkit::TETButton handle( GetOwner() );
247 mPressedSignal.Emit( handle );
250 void TETButton::OnTouchPointInterrupted()
252 gOnTouchPointInterrupted = true;
255 } // namespace Internal
257 } // namespace Toolkit
264 class TETButtonPressed : public Dali::ConnectionTracker
273 TETButtonPressed( Actor actor, Test test )
279 bool Callback( Button button )
285 mActor.SetSensitive( false );
290 std::cout <<"VISIBILITY false" << std::endl;
291 mActor.SetVisible( false );
306 static bool TestCallback(Actor actor, const TouchEvent& event)
313 //////////////////////////////////////////////////////////
316 int UtcDaliPushButtonInterruptEventWhenInsensitive(void)
318 ToolkitTestApplication application;
319 tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive");
321 // * Creates an actor which contains a button.
322 // * The size of the actor is bigger than the button.
323 // * The button's boundary is contained in the actor's one.
324 Actor actor = Actor::New();
325 TETButton tetButton= Toolkit::TETButton::New();
327 actor.SetName( "Actor" );
328 tetButton.SetName( "TETButton" );
330 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
331 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
332 actor.SetPosition( 0, 0 );
333 actor.SetSize( 400, 800 );
335 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
336 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
337 tetButton.SetPosition( 240, 400 );
338 tetButton.SetSize( 100, 100 );
340 actor.Add( tetButton );
341 Stage::GetCurrent().Add( actor );
343 // * Actor's touch event is connected to a callback function
344 // and this callback function consumes the event.
345 actor.TouchedSignal().Connect( &TestCallback );
347 // * Button's pressed signal is connected to a callback function
348 // which also consumes the event.
349 // * Changes the sensitiveness of the button to false.
350 TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS );
351 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
353 // Initializes TET state.
354 gOnTouchPointInterrupted = false;
355 tetButton.SetSensitive( true );
357 Dali::Integration::TouchEvent event;
361 // Test a down point inside the button which is also consumed by the actor, and an up point
362 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
365 application.SendNotification();
366 application.Render();
368 // A down event is sent inside the button's boundary.
370 event = Dali::Integration::TouchEvent();
371 event.AddPoint( pointDownInside );
373 // flush the queue and render once
374 application.SendNotification();
375 application.Render();
376 application.ProcessEvent( event );
378 // An up event is sent outside the button's boundary but inside the actor's one.
380 event = Dali::Integration::TouchEvent();
381 event.AddPoint( pointUpOutside );
383 // flush the queue and render once
384 application.SendNotification();
385 application.Render();
386 application.ProcessEvent( event );
388 DALI_TEST_CHECK( gOnTouchPointInterrupted );
390 // Test a down point inside the button which is also consumed by the actor, and a motion point
391 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
394 // Initializes TET state.
395 gOnTouchPointInterrupted = false;
396 actor.SetSensitive( true );
397 tetButton.SetSensitive( true );
399 application.SendNotification();
400 application.Render();
402 // A down event is sent inside the button's boundary.
404 event = Dali::Integration::TouchEvent();
405 event.AddPoint( pointDownInside );
407 // flush the queue and render once
408 application.SendNotification();
409 application.Render();
410 application.ProcessEvent( event );
412 // A motion event is sent outside the button's boundary but inside the actor's one.
414 event = Dali::Integration::TouchEvent();
415 event.AddPoint( pointMotionOut );
417 // flush the queue and render once
418 application.SendNotification();
419 application.Render();
420 application.ProcessEvent( event );
422 DALI_TEST_CHECK( gOnTouchPointInterrupted );
424 // Test a down point inside the button which is also consumed by the actor, and an up point
425 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
427 // Initializes TET state.
428 gOnTouchPointInterrupted = false;
429 actor.SetSensitive( true );
430 tetButton.SetSensitive( true );
432 // A down event is sent inside the button's boundary.
434 event = Dali::Integration::TouchEvent();
435 event.AddPoint( pointDownInside );
437 // flush the queue and render once
438 application.SendNotification();
439 application.Render();
440 application.ProcessEvent( event );
442 actor.SetSensitive( true );
443 // An up event is sent inside the button's boundary.
445 event = Dali::Integration::TouchEvent();
446 event.AddPoint( pointUpInside );
448 // flush the queue and render once
449 application.SendNotification();
450 application.Render();
451 application.ProcessEvent( event );
453 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
457 int UtcDaliPushButtonInterruptEventWhenNonVisible(void)
459 ToolkitTestApplication application;
460 tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible");
462 // Does same test as above but changing the visibility instead the sensitiveness.
464 // * Creates an actor which contains a button.
465 // * The size of the actor is bigger than the button.
466 // * The button's boundary is contained in the actor's one.
467 Actor actor = Actor::New();
468 TETButton tetButton = Toolkit::TETButton::New();
470 actor.SetName( "Actor" );
471 tetButton.SetName( "TETButton" );
473 actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
474 actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
475 actor.SetPosition( 0, 0 );
476 actor.SetSize( 400, 800 );
478 tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
479 tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
480 tetButton.SetPosition( 240, 400 );
481 tetButton.SetSize( 100, 100 );
483 actor.Add( tetButton );
484 Stage::GetCurrent().Add( actor );
486 // * Actor's touch event is connected to a callback function
487 // and this callback function consumes the event.
488 actor.TouchedSignal().Connect( &TestCallback );
490 // * Button's pressed signal is connected to a callback function
491 // which also consumes the event.
492 // * Changes the visibility of the button to false.
493 TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY );
494 tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
496 // Initializes TET state.
497 gOnTouchPointInterrupted = false;
498 tetButton.SetVisible( true );
500 Dali::Integration::TouchEvent event;
504 // Test a down point inside the button which is also consumed by the actor, and an up point
505 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
508 application.SendNotification();
509 application.Render();
511 // A down event is sent inside the button's boundary.
513 event = Dali::Integration::TouchEvent();
514 event.AddPoint( pointDownInside );
516 // flush the queue and render once
517 application.SendNotification();
518 application.Render();
519 application.ProcessEvent( event );
521 // More renders are needed in order to allow the node of the actor to become invisible.
522 application.SendNotification();
523 application.Render();
524 application.SendNotification();
525 application.Render();
526 application.SendNotification();
527 application.Render();
529 // An up event is sent outside the button's boundary but inside the actor's one.
531 event = Dali::Integration::TouchEvent();
532 event.AddPoint( pointUpOutside );
534 // flush the queue and render once
535 application.SendNotification();
536 application.Render();
537 application.ProcessEvent( event );
539 DALI_TEST_CHECK( gOnTouchPointInterrupted );
541 // Test a down point inside the button which is also consumed by the actor, and a motion point
542 // consumed only by the actor. gOnTouchPointInterrupted should be true (Button receives an
545 // Initializes TET state.
546 gOnTouchPointInterrupted = false;
547 tetButton.SetVisible( true );
549 application.SendNotification();
550 application.Render();
551 application.SendNotification();
552 application.Render();
553 application.SendNotification();
554 application.Render();
556 // A down event is sent inside the button's boundary.
558 event = Dali::Integration::TouchEvent();
559 event.AddPoint( pointDownInside );
561 // flush the queue and render once
562 application.SendNotification();
563 application.Render();
564 application.ProcessEvent( event );
566 // More renders are needed in order to allow the node of the actor to become invisible.
567 application.SendNotification();
568 application.Render();
569 application.SendNotification();
570 application.Render();
571 application.SendNotification();
572 application.Render();
574 // A motion event is sent outside the button's boundary but inside the actor's one.
576 event = Dali::Integration::TouchEvent();
577 event.AddPoint( pointMotionOut );
579 // flush the queue and render once
580 application.SendNotification();
581 application.Render();
582 application.ProcessEvent( event );
584 DALI_TEST_CHECK( gOnTouchPointInterrupted );
586 // Test a down point inside the button which is also consumed by the actor, and an up point
587 // also inside the button and consumed by the actor. gOnTouchPointInterrupted should be false.
589 // Initializes TET state.
590 gOnTouchPointInterrupted = false;
591 tetButton.SetVisible( true );
593 application.SendNotification();
594 application.Render();
595 application.SendNotification();
596 application.Render();
597 application.SendNotification();
598 application.Render();
600 // A down event is sent inside the button's boundary.
602 event = Dali::Integration::TouchEvent();
603 event.AddPoint( pointDownInside );
605 // flush the queue and render once
606 application.SendNotification();
607 application.Render();
608 application.ProcessEvent( event );
610 tetButton.SetVisible( true );
612 application.SendNotification();
613 application.Render();
614 application.SendNotification();
615 application.Render();
616 application.SendNotification();
617 application.Render();
619 // An up event is sent inside the button's boundary.
621 event = Dali::Integration::TouchEvent();
622 event.AddPoint( pointUpInside );
624 // flush the queue and render once
625 application.SendNotification();
626 application.Render();
627 application.ProcessEvent( event );
629 DALI_TEST_CHECK( !gOnTouchPointInterrupted );
633 int UtcDaliPushButtonProperties(void)
635 ToolkitTestApplication application;
637 PushButton button = PushButton::New();
638 Stage::GetCurrent().Add( button );
640 // PushButton::PROPERTY_AUTO_REPEATING
641 button.SetAutoRepeating( false );
642 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
643 button.SetProperty( PushButton::PROPERTY_AUTO_REPEATING, true );
644 DALI_TEST_CHECK( button.IsAutoRepeating() ) ;
645 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
647 // PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY
648 button.SetInitialAutoRepeatingDelay( 10.0f );
649 DALI_TEST_EQUALS( 10.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
650 button.SetProperty( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, 25.0f );
651 DALI_TEST_EQUALS( 25.0f, button.GetInitialAutoRepeatingDelay(), TEST_LOCATION );
652 DALI_TEST_EQUALS( 25.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
654 // PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY
655 button.SetNextAutoRepeatingDelay( 3.0f );
656 DALI_TEST_EQUALS( 3.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
657 button.SetProperty( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY, 4.0f );
658 DALI_TEST_EQUALS( 4.0f, button.GetNextAutoRepeatingDelay(), TEST_LOCATION );
659 DALI_TEST_EQUALS( 4.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
661 // PushButton::PROPERTY_TOGGLABLE
662 button.SetToggleButton( false );
663 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
664 button.SetProperty( PushButton::PROPERTY_TOGGLABLE, true );
665 DALI_TEST_CHECK( button.IsToggleButton() ) ;
666 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
668 // PushButton::PROPERTY_TOGGLE
669 button.SetToggled( false );
670 DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
671 button.SetProperty( PushButton::PROPERTY_TOGGLE, true );
672 DALI_TEST_CHECK( button.IsToggled() ) ;
673 DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
675 // PushButton::PROPERTY_NORMAL_STATE_ACTOR
677 button.SetButtonImage( Image::New( "IMAGE_PATH_1") );
678 DALI_TEST_EQUALS( "IMAGE_PATH_1", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
681 map.push_back( Property::StringValuePair( "type", "ImageActor" ) );
683 button.SetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR, map );
684 DALI_TEST_EQUALS( "ImageActor", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
687 // PushButton::PROPERTY_PRESSED_IMAGE
689 button.SetPressedImage( Image::New( "IMAGE_PATH_2") );
690 DALI_TEST_EQUALS( "IMAGE_PATH_2", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
693 map.push_back( Property::StringValuePair( "type", "TextActor" ) );
695 button.SetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR, map );
696 DALI_TEST_EQUALS( "TextActor", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
699 // PushButton::PROPERTY_DIMMED_STATE_ACTOR
701 button.SetDimmedImage( Image::New( "IMAGE_PATH_3") );
702 DALI_TEST_EQUALS( "IMAGE_PATH_3", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
705 map.push_back( Property::StringValuePair( "type", "Actor" ) );
707 button.SetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR, map );
708 DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
711 // PushButton::PROPERTY_LABEL_ACTOR
713 button.SetLabelText( "LABEL_TEXT_CUSTOM" );
714 DALI_TEST_EQUALS( "TextView", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
717 map.push_back( Property::StringValuePair( "type", "Actor" ) );
719 button.SetProperty( PushButton::PROPERTY_LABEL_ACTOR, map );
720 DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );