[SRUK] Initial copy from Tizen 2.2 version
[platform/core/uifw/dali-toolkit.git] / automated-tests / dali-test-suite / buttons / utc-Dali-PushButton.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 #include <iostream>
18
19 #include <stdlib.h>
20 #include <tet_api.h>
21
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>
27
28 #include <dali-toolkit-test-suite-utils.h>
29
30 #include <dali-toolkit/internal/controls/buttons/button-impl.h>
31
32 using namespace Dali;
33 using namespace Toolkit;
34
35 namespace
36 {
37 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
38 {
39   BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
40
41   // Create the image
42   PixelBuffer* pixbuf = imageData.GetBuffer();
43   unsigned int size = width * height;
44
45   for( size_t i = 0; i < size; i++ )
46     {
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;
51     }
52
53   imageData.Update();
54
55   return imageData;
56 }
57
58 static bool gPushButtonToggleState = false;
59 bool PushButtonToggled( Button button, bool toggled )
60 {
61   gPushButtonToggleState = toggled && ( toggled == static_cast<PushButton&>( button ).IsToggled() );
62   return true;
63 }
64
65 static bool gPushButtonPressed = false;
66
67 static bool PushButtonPressed( Button button )
68 {
69   gPushButtonPressed = true;
70   return true;
71 }
72
73 static bool gPushButtonReleased = false;
74
75 static bool PushButtonReleased( Button button )
76 {
77   gPushButtonReleased = true;
78   return true;
79 }
80
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 );
88 } // namespace
89
90 static void Startup();
91 static void Cleanup();
92
93 extern "C" {
94   void (*tet_startup)() = Startup;
95   void (*tet_cleanup)() = Cleanup;
96 }
97
98 //////////////////////////////////////////////////////////
99
100 namespace
101 {
102 static bool gOnTouchPointInterrupted = false;
103 } //namespace
104
105 namespace Dali
106 {
107
108 namespace Toolkit
109 {
110
111 namespace Internal
112 {
113 class TETButton;
114 }
115
116 /**
117  * Creates a Button to test if interrupt events are handled correctly.
118  */
119 class TETButton : public Button
120 {
121 public:
122   // PushButton Pressed
123   typedef SignalV2< bool ( Button ) > PressedSignalV2;
124
125   PressedSignalV2& PressedSignal();
126
127   /**
128    * Default constructor.
129    */
130   TETButton();
131
132   /**
133    * Copy constructor.
134    */
135   TETButton( const Button& button );
136
137   /**
138    * Assignment operator.
139    */
140   TETButton& operator=( const TETButton& button );
141
142   /**
143    * Creates and initializes a new button.
144    */
145   static TETButton New();
146
147   /**
148    * Down cast to TETButton.
149    */
150   static TETButton DownCast( BaseHandle handle );
151
152   /**
153    * Creates a handle using the Toolkit::Internal implementation.
154    * @param[in]  implementation  The Control implementation.
155    */
156   TETButton( Internal::TETButton& implementation );
157
158   /**
159    * Allows the creation of this Control from an Internal::CustomActor pointer.
160    * @param[in]  internal  A pointer to the internal CustomActor.
161    */
162   TETButton( Dali::Internal::CustomActor* internal );
163 };
164
165 namespace Internal
166 {
167
168 /**
169  * Internal implementation
170  */
171 class TETButton : public Button
172 {
173 public:
174   /**
175    * Construct a new Button.
176    */
177   TETButton();
178
179   /**
180    * A reference counted object may only be deleted by calling Unreference()
181    */
182   virtual ~TETButton();
183
184   /**
185    * Creates an internal button.
186    */
187   static Toolkit::TETButton New();
188
189   /**
190    * @return the pressed signal.
191    */
192   Toolkit::TETButton::PressedSignalV2& PressedSignal();
193
194   /**
195    * Callback called when an interrupt events is received.
196    */
197   void OnTouchPointInterrupted();
198
199   /**
200    * Callback received when a down event is received.
201    */
202   void OnButtonDown();
203
204   Toolkit::TETButton::PressedSignalV2 mPressedSignal;   ///< Signal emitted when the button is pressed.
205 };
206
207 } // namespace Internal
208
209 TETButton::TETButton()
210 {
211 }
212
213 TETButton::TETButton( const Button& button )
214 : Button( button )
215 {
216 }
217
218 TETButton& TETButton::operator=( const TETButton& button )
219 {
220   if( &button != this )
221   {
222     Button::operator=( button );
223   }
224   return *this;
225 }
226
227 TETButton TETButton::New()
228 {
229   return Internal::TETButton::New();
230 }
231
232 TETButton TETButton::DownCast( BaseHandle handle )
233 {
234   return Control::DownCast<TETButton, Internal::TETButton>(handle);
235 }
236
237 TETButton::PressedSignalV2& TETButton::PressedSignal()
238 {
239   TETButton button( *this );
240   DALI_ASSERT_ALWAYS( button );
241
242   Dali::RefObject& handle = button.GetImplementation();
243
244   return static_cast<Toolkit::Internal::TETButton&>( handle ).PressedSignal();
245 }
246
247 TETButton::TETButton( Internal::TETButton& implementation )
248 : Button( implementation )
249 {}
250
251 TETButton::TETButton( Dali::Internal::CustomActor* internal )
252 : Button( internal )
253 {
254   VerifyCustomActorPointer<Internal::TETButton>(internal);
255 }
256
257 namespace Internal
258 {
259
260 TETButton::TETButton()
261 : Button(),
262   mPressedSignal()
263 {
264 }
265
266 TETButton::~TETButton()
267 {
268 }
269
270 Toolkit::TETButton TETButton::New()
271 {
272   // Create the implementation, temporarily owned on stack
273   IntrusivePtr< TETButton > internalTETButton = new TETButton();
274
275   // Pass ownership to CustomActor
276   Dali::Toolkit::TETButton tetButton( *internalTETButton );
277
278   // Second-phase init of the implementation
279   // This can only be done after the CustomActor connection has been made...
280   internalTETButton->Initialize();
281
282   return tetButton;
283 }
284
285 Toolkit::TETButton::PressedSignalV2& TETButton::PressedSignal()
286 {
287   return mPressedSignal;
288 }
289
290 void TETButton::OnButtonDown()
291 {
292   Toolkit::TETButton handle( GetOwner() );
293
294   //Emit signal.
295   mPressedSignal.Emit( handle );
296 }
297
298 void TETButton::OnTouchPointInterrupted()
299 {
300   gOnTouchPointInterrupted = true;
301 }
302
303 } // namespace Internal
304
305 } // namespace Toolkit
306
307 } // namespace Dali
308
309 namespace
310 {
311
312 class TETButtonPressed : public Dali::ConnectionTracker
313 {
314 public:
315   enum Test
316   {
317     SENSITIVENESS,
318     VISIBILITY
319   };
320
321   TETButtonPressed( Actor actor, Test test )
322   : mActor( actor ),
323     mTest( test )
324   {
325   }
326
327   bool Callback( Button button )
328   {
329     switch( mTest )
330     {
331       case SENSITIVENESS:
332       {
333         mActor.SetSensitive( false );
334         break;
335       }
336       case VISIBILITY:
337       {
338         std::cout <<"VISIBILITY false" << std::endl;
339         mActor.SetVisible( false );
340         break;
341       }
342       default:
343       {
344         break;
345       }
346     }
347     return true;
348   }
349
350   Actor mActor;
351   Test mTest;
352 };
353
354 static bool TestCallback(Actor actor, const TouchEvent& event)
355 {
356   return true;
357 }
358
359 } // namespace
360
361 //////////////////////////////////////////////////////////
362
363 enum {
364   POSITIVE_TC_IDX = 0x01,
365   NEGATIVE_TC_IDX,
366 };
367
368 #define MAX_NUMBER_OF_TESTS 10000
369 extern "C" {
370   struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
371 }
372
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
389 // Called only once before first test is run.
390 static void Startup()
391 {
392 }
393
394 // Called only once after last test is run
395 static void Cleanup()
396 {
397 }
398
399
400 static void UtcDaliPushButtonSetGetAutoRepeating()
401 {
402   ToolkitTestApplication application;
403   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
404
405   PushButton pushButton = PushButton::New();
406
407   pushButton.SetAutoRepeating( true );
408
409   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
410
411   pushButton.SetAutoRepeating( false );
412
413   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
414
415   pushButton.SetAutoRepeating( true );
416
417   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
418 }
419
420 static void UtcDaliPushButtonSetGetToggleButton()
421 {
422   ToolkitTestApplication application;
423   tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
424
425   PushButton pushButton = PushButton::New();
426
427   pushButton.SetToggleButton( true );
428
429   DALI_TEST_CHECK( pushButton.IsToggleButton() );
430
431   pushButton.SetToggleButton( false );
432
433   DALI_TEST_CHECK( !pushButton.IsToggleButton() );
434
435   pushButton.SetToggleButton( true );
436
437   DALI_TEST_CHECK( pushButton.IsToggleButton() );
438 }
439
440 static void UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton()
441 {
442   ToolkitTestApplication application;
443   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
444
445   PushButton pushButton = PushButton::New();
446
447   pushButton.SetAutoRepeating( true );
448   pushButton.SetToggleButton( true );
449
450   DALI_TEST_CHECK( pushButton.IsToggleButton() );
451   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
452
453   pushButton.SetToggleButton( true );
454   pushButton.SetAutoRepeating( true );
455
456   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
457   DALI_TEST_CHECK( !pushButton.IsToggleButton() );
458 }
459
460 static void UtcDaliPushButtonSetGetToggled01()
461 {
462   ToolkitTestApplication application;
463   tet_infoline(" UtcDaliPushButtonSetGetToggled01");
464
465   PushButton pushButton = PushButton::New();
466
467   pushButton.SetToggleButton( true );
468   pushButton.ToggledSignal().Connect( &PushButtonToggled );
469
470   gPushButtonToggleState = false;
471   pushButton.SetToggled( true );
472
473   DALI_TEST_CHECK( pushButton.IsToggled() );
474   DALI_TEST_CHECK( gPushButtonToggleState );
475
476   pushButton.SetToggled( false );
477
478   DALI_TEST_CHECK( !pushButton.IsToggled() );
479   DALI_TEST_CHECK( !gPushButtonToggleState );
480
481   pushButton.SetToggled( true );
482
483   DALI_TEST_CHECK( pushButton.IsToggled() );
484   DALI_TEST_CHECK( gPushButtonToggleState );
485 }
486
487 static void UtcDaliPushButtonSetGetToggled02()
488 {
489   ToolkitTestApplication application;
490   tet_infoline(" UtcDaliPushButtonSetGetToggled02");
491
492   PushButton pushButton = PushButton::New();
493
494   pushButton.SetToggleButton( false );
495   pushButton.ToggledSignal().Connect( &PushButtonToggled );
496
497   gPushButtonToggleState = false;
498   pushButton.SetToggled( true );
499
500   DALI_TEST_CHECK( !pushButton.IsToggled() );
501   DALI_TEST_CHECK( !gPushButtonToggleState );
502
503   pushButton.SetToggled( false );
504
505   DALI_TEST_CHECK( !pushButton.IsToggled() );
506   DALI_TEST_CHECK( !gPushButtonToggleState );
507
508   pushButton.SetToggled( true );
509
510   DALI_TEST_CHECK( !pushButton.IsToggled() );
511   DALI_TEST_CHECK( !gPushButtonToggleState );
512 }
513
514 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues01()
515 {
516   ToolkitTestApplication application;
517   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
518
519   PushButton pushButton = PushButton::New();
520
521   pushButton.SetAutoRepeating( true );
522
523   pushButton.SetInitialAutoRepeatingDelay( 1.f );
524   DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
525
526   pushButton.SetNextAutoRepeatingDelay( 1.f );
527   DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
528 }
529
530 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues02()
531 {
532   ToolkitTestApplication application;
533   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
534
535   PushButton pushButton = PushButton::New();
536
537   bool assert1( false );
538   bool assert2( false );
539
540   pushButton.SetAutoRepeating( true );
541
542   try
543   {
544     pushButton.SetInitialAutoRepeatingDelay( -1.f );
545   }
546   catch( Dali::DaliException& e )
547   {
548     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
549     DALI_TEST_EQUALS(e.mCondition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
550     assert1 = true;
551   }
552
553   try
554   {
555     pushButton.SetNextAutoRepeatingDelay( -1.f );
556   }
557   catch( Dali::DaliException& e )
558   {
559     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
560     DALI_TEST_EQUALS(e.mCondition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
561     assert2 = true;
562   }
563
564   DALI_TEST_CHECK( assert1 && assert2 );
565 }
566
567 static void UtcDaliPushButtonSetImages()
568 {
569   ToolkitTestApplication application;
570   tet_infoline(" UtcDaliPushButtonSetImages");
571
572   Actor imageActor;
573
574   Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
575   ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
576   imageActor01.SetSize( 20.f, 20.f );
577
578   Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
579   ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
580   imageActor02.SetSize( 40.f, 40.f );
581
582   Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
583   ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
584   imageActor03.SetSize( 60.f, 60.f );
585
586   Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
587   ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
588   imageActor04.SetSize( 80.f, 80.f );
589
590   Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
591   ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
592   imageActor05.SetSize( 100.f, 100.f );
593
594   Vector3 size;
595   PushButton pushButton = PushButton::New();
596
597   application.SendNotification();
598   application.Render();
599
600   // Just check if check box button size changes when a bigger image is set.
601
602   pushButton.SetButtonImage( image01 );
603
604   application.SendNotification();
605   application.Render();
606
607   size = pushButton.GetButtonImage().GetCurrentSize();
608
609   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
610   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
611
612   pushButton.SetButtonImage( imageActor01 );
613
614   application.SendNotification();
615   application.Render();
616
617   size = pushButton.GetButtonImage().GetCurrentSize();
618
619   DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
620   DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
621
622   pushButton.SetBackgroundImage( image02 );
623
624   application.SendNotification();
625   application.Render();
626
627   size = pushButton.GetBackgroundImage().GetCurrentSize();
628
629   DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
630   DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
631
632   pushButton.SetBackgroundImage( imageActor02 );
633
634   application.SendNotification();
635   application.Render();
636
637   size = pushButton.GetBackgroundImage().GetCurrentSize();
638
639   DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
640   DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
641
642   pushButton.SetPressedImage( image03 );
643
644   application.SendNotification();
645   application.Render();
646
647   size = pushButton.GetPressedImage().GetCurrentSize();
648
649   DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
650   DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
651
652   pushButton.SetPressedImage( imageActor03 );
653
654   application.SendNotification();
655   application.Render();
656
657   size = pushButton.GetPressedImage().GetCurrentSize();
658
659   DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
660   DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
661
662   pushButton.SetDimmedBackgroundImage( image04 );
663
664   application.SendNotification();
665   application.Render();
666
667   size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
668
669   DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
670   DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
671
672   pushButton.SetDimmedBackgroundImage( imageActor04 );
673
674   application.SendNotification();
675   application.Render();
676
677   size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
678
679   DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
680   DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
681
682   pushButton.SetDimmedImage( image05 );
683
684   application.SendNotification();
685   application.Render();
686
687   size = pushButton.GetDimmedImage().GetCurrentSize();
688
689   DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
690   DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
691
692   pushButton.SetDimmedImage( imageActor05 );
693
694   application.SendNotification();
695   application.Render();
696
697   size = pushButton.GetDimmedImage().GetCurrentSize();
698
699   DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
700   DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
701 }
702
703 static void UtcDaliPushButtonSetLabelText()
704 {
705   ToolkitTestApplication application;
706   tet_infoline(" UtcDaliPushButtonSetLabelText");
707
708   const std::string STR( "Hola!" );
709
710   PushButton pushButton = PushButton::New();
711
712   application.SendNotification();
713   application.Render();
714
715   TextView textView;
716
717   pushButton.SetLabelText( STR );
718
719   textView = TextView::DownCast( pushButton.GetLabelText() );
720   DALI_TEST_CHECK( STR == textView.GetText() );
721
722   TextView text = TextView::New( STR );
723   pushButton.SetLabelText( text );
724
725   textView = TextView::DownCast( pushButton.GetLabelText() );
726   DALI_TEST_CHECK( STR == textView.GetText() );
727 }
728
729 static void UtcDaliPushButtonPressed()
730 {
731   ToolkitTestApplication application;
732   tet_infoline(" UtcDaliPushButtonPressed");
733
734   PushButton pushButton = PushButton::New();
735   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
736   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
737   pushButton.SetPosition( 240, 400 );
738   pushButton.SetSize( 100, 100 );
739
740   Stage::GetCurrent().Add( pushButton );
741
742   application.SendNotification();
743   application.Render();
744
745   gPushButtonPressed = false;
746
747   // connect to its touch signal
748   pushButton.PressedSignal().Connect( &PushButtonPressed );
749
750   Dali::Integration::TouchEvent eventDown;
751   eventDown.AddPoint( pointDownInside );
752
753   // flush the queue and render once
754   application.SendNotification();
755   application.Render();
756   application.GetCore().SendEvent( eventDown );
757
758   DALI_TEST_CHECK( gPushButtonPressed );
759 }
760
761 static void UtcDaliPushButtonReleased()
762 {
763   ToolkitTestApplication application;
764   tet_infoline(" UtcDaliPushButtonReleased");
765
766   PushButton pushButton = PushButton::New();
767   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
768   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
769   pushButton.SetPosition( 240, 400 );
770   pushButton.SetSize( 100, 100 );
771
772   Stage::GetCurrent().Add( pushButton );
773
774   application.SendNotification();
775   application.Render();
776
777   // connect to its touch signal
778   pushButton.ReleasedSignal().Connect( &PushButtonReleased );
779
780   Dali::Integration::TouchEvent event;
781
782   // Test1. Touch point down and up inside the button.
783
784   gPushButtonReleased = false;
785   event = Dali::Integration::TouchEvent();
786   event.AddPoint( pointDownInside );
787   application.GetCore().SendEvent( event );
788
789   event = Dali::Integration::TouchEvent();
790   event.AddPoint( pointUpInside );
791   application.GetCore().SendEvent( event );
792
793   DALI_TEST_CHECK( gPushButtonReleased );
794
795   // Test2. Touch point down and up outside the button.
796
797   gPushButtonReleased = false;
798   event = Dali::Integration::TouchEvent();
799   event.AddPoint( pointDownOutside );
800   application.GetCore().SendEvent( event );
801
802   event = Dali::Integration::TouchEvent();
803   event.AddPoint( pointUpOutside );
804   application.GetCore().SendEvent( event );
805
806   DALI_TEST_CHECK( !gPushButtonReleased );
807
808   // Test3. Touch point down inside and up outside the button.
809
810   gPushButtonReleased = false;
811   event = Dali::Integration::TouchEvent();
812   event.AddPoint( pointDownInside );
813   application.GetCore().SendEvent( event );
814
815   event = Dali::Integration::TouchEvent();
816   event.AddPoint( pointLeave );
817   application.GetCore().SendEvent( event );
818
819   event = Dali::Integration::TouchEvent();
820   event.AddPoint( pointUpOutside );
821   application.GetCore().SendEvent( event );
822
823   DALI_TEST_CHECK( gPushButtonReleased );
824
825   // Test4. Touch point down outside and up inside the button.
826
827   gPushButtonReleased = false;
828   event = Dali::Integration::TouchEvent();
829   event.AddPoint( pointDownOutside );
830   application.GetCore().SendEvent( event );
831
832   event = Dali::Integration::TouchEvent();
833   event.AddPoint( pointEnter );
834   application.GetCore().SendEvent( event );
835
836   event = Dali::Integration::TouchEvent();
837   event.AddPoint( pointUpInside );
838   application.GetCore().SendEvent( event );
839
840   DALI_TEST_CHECK( !gPushButtonReleased );
841 }
842
843 static void UtcDaliPushButtonToggled()
844 {
845   ToolkitTestApplication application;
846   tet_infoline(" UtcDaliPushButtonToggled");
847
848   PushButton pushButton = PushButton::New();
849   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
850   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
851   pushButton.SetPosition( 240, 400 );
852   pushButton.SetSize( 100, 100 );
853
854   Stage::GetCurrent().Add( pushButton );
855
856   application.SendNotification();
857   application.Render();
858
859   // connect to its touch signal
860   pushButton.ToggledSignal().Connect( &PushButtonToggled );
861
862   Dali::Integration::TouchEvent event;
863
864   // Test1. No toggle button.
865
866   gPushButtonToggleState = false;
867   event = Dali::Integration::TouchEvent();
868   event.AddPoint( pointDownInside );
869   application.GetCore().SendEvent( event );
870
871   event = Dali::Integration::TouchEvent();
872   event.AddPoint( pointUpInside );
873   application.GetCore().SendEvent( event );
874
875   DALI_TEST_CHECK( !gPushButtonToggleState );
876
877   // Set toggle property.
878   pushButton.SetToggleButton( true );
879
880   // Test2. Touch point down and up inside the button twice.
881   gPushButtonToggleState = false;
882   event = Dali::Integration::TouchEvent();
883   event.AddPoint( pointDownInside );
884   application.GetCore().SendEvent( event );
885
886   event = Dali::Integration::TouchEvent();
887   event.AddPoint( pointUpInside );
888   application.GetCore().SendEvent( event );
889
890   DALI_TEST_CHECK( gPushButtonToggleState );
891
892   event = Dali::Integration::TouchEvent();
893   event.AddPoint( pointDownInside );
894   application.GetCore().SendEvent( event );
895
896   event = Dali::Integration::TouchEvent();
897   event.AddPoint( pointUpInside );
898   application.GetCore().SendEvent( event );
899
900   DALI_TEST_CHECK( !gPushButtonToggleState );
901
902   // Test3. Touch point down and up outside the button.
903
904   gPushButtonToggleState = false;
905   event = Dali::Integration::TouchEvent();
906   event.AddPoint( pointDownOutside );
907   application.GetCore().SendEvent( event );
908
909   event = Dali::Integration::TouchEvent();
910   event.AddPoint( pointUpOutside );
911   application.GetCore().SendEvent( event );
912
913   DALI_TEST_CHECK( !gPushButtonToggleState );
914
915   // Test4. Touch point down inside and up outside the button.
916
917   gPushButtonToggleState = false;
918   event = Dali::Integration::TouchEvent();
919   event.AddPoint( pointDownInside );
920   application.GetCore().SendEvent( event );
921
922   event = Dali::Integration::TouchEvent();
923   event.AddPoint( pointLeave );
924   application.GetCore().SendEvent( event );
925
926   event = Dali::Integration::TouchEvent();
927   event.AddPoint( pointUpOutside );
928   application.GetCore().SendEvent( event );
929
930   DALI_TEST_CHECK( !gPushButtonToggleState );
931
932   // Test5. Touch point down outside and up inside the button.
933
934   gPushButtonToggleState = false;
935   event = Dali::Integration::TouchEvent();
936   event.AddPoint( pointDownOutside );
937   application.GetCore().SendEvent( event );
938
939   event = Dali::Integration::TouchEvent();
940   event.AddPoint( pointEnter );
941   application.GetCore().SendEvent( event );
942
943   event = Dali::Integration::TouchEvent();
944   event.AddPoint( pointUpInside );
945   application.GetCore().SendEvent( event );
946
947   DALI_TEST_CHECK( !gPushButtonToggleState );
948 }
949
950 static void UtcDaliPushButtonInterruptEventWhenInsensitive()
951 {
952   ToolkitTestApplication application;
953   tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive");
954
955   // * Creates an actor which contains a button.
956   // * The size of the actor is bigger than the button.
957   // * The button's boundary is contained in the actor's one.
958   Actor actor = Actor::New();
959   TETButton tetButton= Toolkit::TETButton::New();
960
961   actor.SetName( "Actor" );
962   tetButton.SetName( "TETButton" );
963
964   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
965   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
966   actor.SetPosition( 0, 0 );
967   actor.SetSize( 400, 800 );
968
969   tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
970   tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
971   tetButton.SetPosition( 240, 400 );
972   tetButton.SetSize( 100, 100 );
973
974   actor.Add( tetButton );
975   Stage::GetCurrent().Add( actor );
976
977   // * Actor's touch event is connected to a callback function
978   //   and this callback function consumes the event.
979   actor.TouchedSignal().Connect( &TestCallback );
980
981   // * Button's pressed signal is connected to a callback function
982   //   which also consumes the event.
983   // * Changes the sensitiveness of the button to false.
984   TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS );
985   tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
986
987   // Initializes TET state.
988   gOnTouchPointInterrupted = false;
989   tetButton.SetSensitive( true );
990
991   Dali::Integration::TouchEvent event;
992
993   // TET starts.
994
995   // Test a down point inside the button which is also consumed by the actor, and an up point
996   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
997   // interrupt event.
998
999   application.SendNotification();
1000   application.Render();
1001
1002   // A down event is sent inside the button's boundary.
1003
1004   event = Dali::Integration::TouchEvent();
1005   event.AddPoint( pointDownInside );
1006
1007   // flush the queue and render once
1008   application.SendNotification();
1009   application.Render();
1010   application.GetCore().SendEvent( event );
1011
1012   // An up event is sent outside the button's boundary but inside the actor's one.
1013
1014   event = Dali::Integration::TouchEvent();
1015   event.AddPoint( pointUpOutside );
1016
1017   // flush the queue and render once
1018   application.SendNotification();
1019   application.Render();
1020   application.GetCore().SendEvent( event );
1021
1022   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1023
1024   // Test a down point inside the button which is also consumed by the actor, and a motion point
1025   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
1026   // interrupt event.
1027
1028   // Initializes TET state.
1029   gOnTouchPointInterrupted = false;
1030   actor.SetSensitive( true );
1031   tetButton.SetSensitive( true );
1032
1033   application.SendNotification();
1034   application.Render();
1035
1036   // A down event is sent inside the button's boundary.
1037
1038   event = Dali::Integration::TouchEvent();
1039   event.AddPoint( pointDownInside );
1040
1041   // flush the queue and render once
1042   application.SendNotification();
1043   application.Render();
1044   application.GetCore().SendEvent( event );
1045
1046   // A motion event is sent outside the button's boundary but inside the actor's one.
1047
1048   event = Dali::Integration::TouchEvent();
1049   event.AddPoint( pointMotionOut );
1050
1051   // flush the queue and render once
1052   application.SendNotification();
1053   application.Render();
1054   application.GetCore().SendEvent( event );
1055
1056   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1057
1058   // Test a down point inside the button which is also consumed by the actor, and an up point
1059   // also inside the button and consumed by the actor.  gOnTouchPointInterrupted should be false.
1060
1061   // Initializes TET state.
1062   gOnTouchPointInterrupted = false;
1063   actor.SetSensitive( true );
1064   tetButton.SetSensitive( true );
1065
1066   // A down event is sent inside the button's boundary.
1067
1068   event = Dali::Integration::TouchEvent();
1069   event.AddPoint( pointDownInside );
1070
1071   // flush the queue and render once
1072   application.SendNotification();
1073   application.Render();
1074   application.GetCore().SendEvent( event );
1075
1076   actor.SetSensitive( true );
1077   // An up event is sent inside the button's boundary.
1078
1079   event = Dali::Integration::TouchEvent();
1080   event.AddPoint( pointUpInside );
1081
1082   // flush the queue and render once
1083   application.SendNotification();
1084   application.Render();
1085   application.GetCore().SendEvent( event );
1086
1087   DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1088 }
1089
1090 static void UtcDaliPushButtonInterruptEventWhenNonVisible()
1091 {
1092   ToolkitTestApplication application;
1093   tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible");
1094
1095   // Does same test as above but changing the visibility instead the sensitiveness.
1096
1097   // * Creates an actor which contains a button.
1098   // * The size of the actor is bigger than the button.
1099   // * The button's boundary is contained in the actor's one.
1100   Actor actor = Actor::New();
1101   TETButton tetButton = Toolkit::TETButton::New();
1102
1103   actor.SetName( "Actor" );
1104   tetButton.SetName( "TETButton" );
1105
1106   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1107   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1108   actor.SetPosition( 0, 0 );
1109   actor.SetSize( 400, 800 );
1110
1111   tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1112   tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1113   tetButton.SetPosition( 240, 400 );
1114   tetButton.SetSize( 100, 100 );
1115
1116   actor.Add( tetButton );
1117   Stage::GetCurrent().Add( actor );
1118
1119   // * Actor's touch event is connected to a callback function
1120   //   and this callback function consumes the event.
1121   actor.TouchedSignal().Connect( &TestCallback );
1122
1123   // * Button's pressed signal is connected to a callback function
1124   //   which also consumes the event.
1125   // * Changes the visibility of the button to false.
1126   TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY );
1127   tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
1128
1129   // Initializes TET state.
1130   gOnTouchPointInterrupted = false;
1131   tetButton.SetVisible( true );
1132
1133   Dali::Integration::TouchEvent event;
1134
1135   // TET starts.
1136
1137   // Test a down point inside the button which is also consumed by the actor, and an up point
1138   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
1139   // interrupt event.
1140
1141   application.SendNotification();
1142   application.Render();
1143
1144   // A down event is sent inside the button's boundary.
1145
1146   event = Dali::Integration::TouchEvent();
1147   event.AddPoint( pointDownInside );
1148
1149   // flush the queue and render once
1150   application.SendNotification();
1151   application.Render();
1152   application.GetCore().SendEvent( event );
1153
1154   // More renders are needed in order to allow the node of the actor to become invisible.
1155   application.SendNotification();
1156   application.Render();
1157   application.SendNotification();
1158   application.Render();
1159   application.SendNotification();
1160   application.Render();
1161
1162   // An up event is sent outside the button's boundary but inside the actor's one.
1163
1164   event = Dali::Integration::TouchEvent();
1165   event.AddPoint( pointUpOutside );
1166
1167   // flush the queue and render once
1168   application.SendNotification();
1169   application.Render();
1170   application.GetCore().SendEvent( event );
1171
1172   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1173
1174   // Test a down point inside the button which is also consumed by the actor, and a motion point
1175   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
1176   // interrupt event.
1177
1178   // Initializes TET state.
1179   gOnTouchPointInterrupted = false;
1180   tetButton.SetVisible( true );
1181
1182   application.SendNotification();
1183   application.Render();
1184   application.SendNotification();
1185   application.Render();
1186   application.SendNotification();
1187   application.Render();
1188
1189   // A down event is sent inside the button's boundary.
1190
1191   event = Dali::Integration::TouchEvent();
1192   event.AddPoint( pointDownInside );
1193
1194   // flush the queue and render once
1195   application.SendNotification();
1196   application.Render();
1197   application.GetCore().SendEvent( event );
1198
1199   // More renders are needed in order to allow the node of the actor to become invisible.
1200   application.SendNotification();
1201   application.Render();
1202   application.SendNotification();
1203   application.Render();
1204   application.SendNotification();
1205   application.Render();
1206
1207   // A motion event is sent outside the button's boundary but inside the actor's one.
1208
1209   event = Dali::Integration::TouchEvent();
1210   event.AddPoint( pointMotionOut );
1211
1212   // flush the queue and render once
1213   application.SendNotification();
1214   application.Render();
1215   application.GetCore().SendEvent( event );
1216
1217   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1218
1219   // Test a down point inside the button which is also consumed by the actor, and an up point
1220   // also inside the button and consumed by the actor.  gOnTouchPointInterrupted should be false.
1221
1222   // Initializes TET state.
1223   gOnTouchPointInterrupted = false;
1224   tetButton.SetVisible( true );
1225
1226   application.SendNotification();
1227   application.Render();
1228   application.SendNotification();
1229   application.Render();
1230   application.SendNotification();
1231   application.Render();
1232
1233   // A down event is sent inside the button's boundary.
1234
1235   event = Dali::Integration::TouchEvent();
1236   event.AddPoint( pointDownInside );
1237
1238   // flush the queue and render once
1239   application.SendNotification();
1240   application.Render();
1241   application.GetCore().SendEvent( event );
1242
1243   tetButton.SetVisible( true );
1244
1245   application.SendNotification();
1246   application.Render();
1247   application.SendNotification();
1248   application.Render();
1249   application.SendNotification();
1250   application.Render();
1251
1252   // An up event is sent inside the button's boundary.
1253
1254   event = Dali::Integration::TouchEvent();
1255   event.AddPoint( pointUpInside );
1256
1257   // flush the queue and render once
1258   application.SendNotification();
1259   application.Render();
1260   application.GetCore().SendEvent( event );
1261
1262   DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1263 }