525a5a14c46f856ddb2d9db5a775959b7017e5b7
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / 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 TEST_FUNCTION( UtcDaliPushButtonProperties, POSITIVE_TC_IDX );
389
390 // Called only once before first test is run.
391 static void Startup()
392 {
393 }
394
395 // Called only once after last test is run
396 static void Cleanup()
397 {
398 }
399
400
401 static void UtcDaliPushButtonSetGetAutoRepeating()
402 {
403   ToolkitTestApplication application;
404   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
405
406   PushButton pushButton = PushButton::New();
407
408   pushButton.SetAutoRepeating( true );
409
410   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
411
412   pushButton.SetAutoRepeating( false );
413
414   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
415
416   pushButton.SetAutoRepeating( true );
417
418   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
419 }
420
421 static void UtcDaliPushButtonSetGetToggleButton()
422 {
423   ToolkitTestApplication application;
424   tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
425
426   PushButton pushButton = PushButton::New();
427
428   pushButton.SetToggleButton( true );
429
430   DALI_TEST_CHECK( pushButton.IsToggleButton() );
431
432   pushButton.SetToggleButton( false );
433
434   DALI_TEST_CHECK( !pushButton.IsToggleButton() );
435
436   pushButton.SetToggleButton( true );
437
438   DALI_TEST_CHECK( pushButton.IsToggleButton() );
439 }
440
441 static void UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton()
442 {
443   ToolkitTestApplication application;
444   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
445
446   PushButton pushButton = PushButton::New();
447
448   pushButton.SetAutoRepeating( true );
449   pushButton.SetToggleButton( true );
450
451   DALI_TEST_CHECK( pushButton.IsToggleButton() );
452   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
453
454   pushButton.SetToggleButton( true );
455   pushButton.SetAutoRepeating( true );
456
457   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
458   DALI_TEST_CHECK( !pushButton.IsToggleButton() );
459 }
460
461 static void UtcDaliPushButtonSetGetToggled01()
462 {
463   ToolkitTestApplication application;
464   tet_infoline(" UtcDaliPushButtonSetGetToggled01");
465
466   PushButton pushButton = PushButton::New();
467
468   pushButton.SetToggleButton( true );
469   pushButton.ToggledSignal().Connect( &PushButtonToggled );
470
471   gPushButtonToggleState = false;
472   pushButton.SetToggled( true );
473
474   DALI_TEST_CHECK( pushButton.IsToggled() );
475   DALI_TEST_CHECK( gPushButtonToggleState );
476
477   pushButton.SetToggled( false );
478
479   DALI_TEST_CHECK( !pushButton.IsToggled() );
480   DALI_TEST_CHECK( !gPushButtonToggleState );
481
482   pushButton.SetToggled( true );
483
484   DALI_TEST_CHECK( pushButton.IsToggled() );
485   DALI_TEST_CHECK( gPushButtonToggleState );
486 }
487
488 static void UtcDaliPushButtonSetGetToggled02()
489 {
490   ToolkitTestApplication application;
491   tet_infoline(" UtcDaliPushButtonSetGetToggled02");
492
493   PushButton pushButton = PushButton::New();
494
495   pushButton.SetToggleButton( false );
496   pushButton.ToggledSignal().Connect( &PushButtonToggled );
497
498   gPushButtonToggleState = false;
499   pushButton.SetToggled( true );
500
501   DALI_TEST_CHECK( !pushButton.IsToggled() );
502   DALI_TEST_CHECK( !gPushButtonToggleState );
503
504   pushButton.SetToggled( false );
505
506   DALI_TEST_CHECK( !pushButton.IsToggled() );
507   DALI_TEST_CHECK( !gPushButtonToggleState );
508
509   pushButton.SetToggled( true );
510
511   DALI_TEST_CHECK( !pushButton.IsToggled() );
512   DALI_TEST_CHECK( !gPushButtonToggleState );
513 }
514
515 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues01()
516 {
517   ToolkitTestApplication application;
518   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
519
520   PushButton pushButton = PushButton::New();
521
522   pushButton.SetAutoRepeating( true );
523
524   pushButton.SetInitialAutoRepeatingDelay( 1.f );
525   DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
526
527   pushButton.SetNextAutoRepeatingDelay( 1.f );
528   DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
529 }
530
531 static void UtcDaliPushButtonSetGetAutorepeatingDelayValues02()
532 {
533   ToolkitTestApplication application;
534   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
535
536   PushButton pushButton = PushButton::New();
537
538   bool assert1( false );
539   bool assert2( false );
540
541   pushButton.SetAutoRepeating( true );
542
543   try
544   {
545     pushButton.SetInitialAutoRepeatingDelay( -1.f );
546   }
547   catch( Dali::DaliException& e )
548   {
549     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
550     DALI_TEST_EQUALS(e.mCondition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
551     assert1 = true;
552   }
553
554   try
555   {
556     pushButton.SetNextAutoRepeatingDelay( -1.f );
557   }
558   catch( Dali::DaliException& e )
559   {
560     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
561     DALI_TEST_EQUALS(e.mCondition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
562     assert2 = true;
563   }
564
565   DALI_TEST_CHECK( assert1 && assert2 );
566 }
567
568 static void UtcDaliPushButtonSetImages()
569 {
570   ToolkitTestApplication application;
571   tet_infoline(" UtcDaliPushButtonSetImages");
572
573   Actor imageActor;
574
575   Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
576   ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
577   imageActor01.SetSize( 20.f, 20.f );
578
579   Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
580   ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
581   imageActor02.SetSize( 40.f, 40.f );
582
583   Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
584   ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
585   imageActor03.SetSize( 60.f, 60.f );
586
587   Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
588   ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
589   imageActor04.SetSize( 80.f, 80.f );
590
591   Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
592   ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
593   imageActor05.SetSize( 100.f, 100.f );
594
595   Vector3 size;
596   PushButton pushButton = PushButton::New();
597
598   application.SendNotification();
599   application.Render();
600
601   // Just check if check box button size changes when a bigger image is set.
602
603   pushButton.SetButtonImage( image01 );
604
605   application.SendNotification();
606   application.Render();
607
608   size = pushButton.GetButtonImage().GetCurrentSize();
609
610   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
611   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
612
613   pushButton.SetButtonImage( imageActor01 );
614
615   application.SendNotification();
616   application.Render();
617
618   size = pushButton.GetButtonImage().GetCurrentSize();
619
620   DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
621   DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
622
623   pushButton.SetBackgroundImage( image02 );
624
625   application.SendNotification();
626   application.Render();
627
628   size = pushButton.GetBackgroundImage().GetCurrentSize();
629
630   DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
631   DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
632
633   pushButton.SetBackgroundImage( imageActor02 );
634
635   application.SendNotification();
636   application.Render();
637
638   size = pushButton.GetBackgroundImage().GetCurrentSize();
639
640   DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
641   DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
642
643   pushButton.SetPressedImage( image03 );
644
645   application.SendNotification();
646   application.Render();
647
648   size = pushButton.GetPressedImage().GetCurrentSize();
649
650   DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
651   DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
652
653   pushButton.SetPressedImage( imageActor03 );
654
655   application.SendNotification();
656   application.Render();
657
658   size = pushButton.GetPressedImage().GetCurrentSize();
659
660   DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
661   DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
662
663   pushButton.SetDimmedBackgroundImage( image04 );
664
665   application.SendNotification();
666   application.Render();
667
668   size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
669
670   DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
671   DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
672
673   pushButton.SetDimmedBackgroundImage( imageActor04 );
674
675   application.SendNotification();
676   application.Render();
677
678   size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
679
680   DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
681   DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
682
683   pushButton.SetDimmedImage( image05 );
684
685   application.SendNotification();
686   application.Render();
687
688   size = pushButton.GetDimmedImage().GetCurrentSize();
689
690   DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
691   DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
692
693   pushButton.SetDimmedImage( imageActor05 );
694
695   application.SendNotification();
696   application.Render();
697
698   size = pushButton.GetDimmedImage().GetCurrentSize();
699
700   DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
701   DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
702 }
703
704 static void UtcDaliPushButtonSetLabelText()
705 {
706   ToolkitTestApplication application;
707   tet_infoline(" UtcDaliPushButtonSetLabelText");
708
709   const std::string STR( "Hola!" );
710
711   PushButton pushButton = PushButton::New();
712
713   application.SendNotification();
714   application.Render();
715
716   TextView textView;
717
718   pushButton.SetLabelText( STR );
719
720   textView = TextView::DownCast( pushButton.GetLabelText() );
721   DALI_TEST_CHECK( STR == textView.GetText() );
722
723   TextView text = TextView::New( STR );
724   pushButton.SetLabelText( text );
725
726   textView = TextView::DownCast( pushButton.GetLabelText() );
727   DALI_TEST_CHECK( STR == textView.GetText() );
728 }
729
730 static void UtcDaliPushButtonPressed()
731 {
732   ToolkitTestApplication application;
733   tet_infoline(" UtcDaliPushButtonPressed");
734
735   PushButton pushButton = PushButton::New();
736   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
737   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
738   pushButton.SetPosition( 240, 400 );
739   pushButton.SetSize( 100, 100 );
740
741   Stage::GetCurrent().Add( pushButton );
742
743   application.SendNotification();
744   application.Render();
745
746   gPushButtonPressed = false;
747
748   // connect to its touch signal
749   pushButton.PressedSignal().Connect( &PushButtonPressed );
750
751   Dali::Integration::TouchEvent eventDown;
752   eventDown.AddPoint( pointDownInside );
753
754   // flush the queue and render once
755   application.SendNotification();
756   application.Render();
757   application.ProcessEvent( eventDown );
758
759   DALI_TEST_CHECK( gPushButtonPressed );
760 }
761
762 static void UtcDaliPushButtonReleased()
763 {
764   ToolkitTestApplication application;
765   tet_infoline(" UtcDaliPushButtonReleased");
766
767   PushButton pushButton = PushButton::New();
768   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
769   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
770   pushButton.SetPosition( 240, 400 );
771   pushButton.SetSize( 100, 100 );
772
773   Stage::GetCurrent().Add( pushButton );
774
775   application.SendNotification();
776   application.Render();
777
778   // connect to its touch signal
779   pushButton.ReleasedSignal().Connect( &PushButtonReleased );
780
781   Dali::Integration::TouchEvent event;
782
783   // Test1. Touch point down and up inside the button.
784
785   gPushButtonReleased = false;
786   event = Dali::Integration::TouchEvent();
787   event.AddPoint( pointDownInside );
788   application.ProcessEvent( event );
789
790   event = Dali::Integration::TouchEvent();
791   event.AddPoint( pointUpInside );
792   application.ProcessEvent( event );
793
794   DALI_TEST_CHECK( gPushButtonReleased );
795
796   // Test2. Touch point down and up outside the button.
797
798   gPushButtonReleased = false;
799   event = Dali::Integration::TouchEvent();
800   event.AddPoint( pointDownOutside );
801   application.ProcessEvent( event );
802
803   event = Dali::Integration::TouchEvent();
804   event.AddPoint( pointUpOutside );
805   application.ProcessEvent( event );
806
807   DALI_TEST_CHECK( !gPushButtonReleased );
808
809   // Test3. Touch point down inside and up outside the button.
810
811   gPushButtonReleased = false;
812   event = Dali::Integration::TouchEvent();
813   event.AddPoint( pointDownInside );
814   application.ProcessEvent( event );
815
816   event = Dali::Integration::TouchEvent();
817   event.AddPoint( pointLeave );
818   application.ProcessEvent( event );
819
820   event = Dali::Integration::TouchEvent();
821   event.AddPoint( pointUpOutside );
822   application.ProcessEvent( event );
823
824   DALI_TEST_CHECK( gPushButtonReleased );
825
826   // Test4. Touch point down outside and up inside the button.
827
828   gPushButtonReleased = false;
829   event = Dali::Integration::TouchEvent();
830   event.AddPoint( pointDownOutside );
831   application.ProcessEvent( event );
832
833   event = Dali::Integration::TouchEvent();
834   event.AddPoint( pointEnter );
835   application.ProcessEvent( event );
836
837   event = Dali::Integration::TouchEvent();
838   event.AddPoint( pointUpInside );
839   application.ProcessEvent( event );
840
841   DALI_TEST_CHECK( !gPushButtonReleased );
842 }
843
844 static void UtcDaliPushButtonToggled()
845 {
846   ToolkitTestApplication application;
847   tet_infoline(" UtcDaliPushButtonToggled");
848
849   PushButton pushButton = PushButton::New();
850   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
851   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
852   pushButton.SetPosition( 240, 400 );
853   pushButton.SetSize( 100, 100 );
854
855   Stage::GetCurrent().Add( pushButton );
856
857   application.SendNotification();
858   application.Render();
859
860   // connect to its touch signal
861   pushButton.ToggledSignal().Connect( &PushButtonToggled );
862
863   Dali::Integration::TouchEvent event;
864
865   // Test1. No toggle button.
866
867   gPushButtonToggleState = false;
868   event = Dali::Integration::TouchEvent();
869   event.AddPoint( pointDownInside );
870   application.ProcessEvent( event );
871
872   event = Dali::Integration::TouchEvent();
873   event.AddPoint( pointUpInside );
874   application.ProcessEvent( event );
875
876   DALI_TEST_CHECK( !gPushButtonToggleState );
877
878   // Set toggle property.
879   pushButton.SetToggleButton( true );
880
881   // Test2. Touch point down and up inside the button twice.
882   gPushButtonToggleState = false;
883   event = Dali::Integration::TouchEvent();
884   event.AddPoint( pointDownInside );
885   application.ProcessEvent( event );
886
887   event = Dali::Integration::TouchEvent();
888   event.AddPoint( pointUpInside );
889   application.ProcessEvent( event );
890
891   DALI_TEST_CHECK( gPushButtonToggleState );
892
893   event = Dali::Integration::TouchEvent();
894   event.AddPoint( pointDownInside );
895   application.ProcessEvent( event );
896
897   event = Dali::Integration::TouchEvent();
898   event.AddPoint( pointUpInside );
899   application.ProcessEvent( event );
900
901   DALI_TEST_CHECK( !gPushButtonToggleState );
902
903   // Test3. Touch point down and up outside the button.
904
905   gPushButtonToggleState = false;
906   event = Dali::Integration::TouchEvent();
907   event.AddPoint( pointDownOutside );
908   application.ProcessEvent( event );
909
910   event = Dali::Integration::TouchEvent();
911   event.AddPoint( pointUpOutside );
912   application.ProcessEvent( event );
913
914   DALI_TEST_CHECK( !gPushButtonToggleState );
915
916   // Test4. Touch point down inside and up outside the button.
917
918   gPushButtonToggleState = false;
919   event = Dali::Integration::TouchEvent();
920   event.AddPoint( pointDownInside );
921   application.ProcessEvent( event );
922
923   event = Dali::Integration::TouchEvent();
924   event.AddPoint( pointLeave );
925   application.ProcessEvent( event );
926
927   event = Dali::Integration::TouchEvent();
928   event.AddPoint( pointUpOutside );
929   application.ProcessEvent( event );
930
931   DALI_TEST_CHECK( !gPushButtonToggleState );
932
933   // Test5. Touch point down outside and up inside the button.
934
935   gPushButtonToggleState = false;
936   event = Dali::Integration::TouchEvent();
937   event.AddPoint( pointDownOutside );
938   application.ProcessEvent( event );
939
940   event = Dali::Integration::TouchEvent();
941   event.AddPoint( pointEnter );
942   application.ProcessEvent( event );
943
944   event = Dali::Integration::TouchEvent();
945   event.AddPoint( pointUpInside );
946   application.ProcessEvent( event );
947
948   DALI_TEST_CHECK( !gPushButtonToggleState );
949 }
950
951 static void UtcDaliPushButtonInterruptEventWhenInsensitive()
952 {
953   ToolkitTestApplication application;
954   tet_infoline(" UtcDaliPushButtonInterruptEventWhenInsensitive");
955
956   // * Creates an actor which contains a button.
957   // * The size of the actor is bigger than the button.
958   // * The button's boundary is contained in the actor's one.
959   Actor actor = Actor::New();
960   TETButton tetButton= Toolkit::TETButton::New();
961
962   actor.SetName( "Actor" );
963   tetButton.SetName( "TETButton" );
964
965   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
966   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
967   actor.SetPosition( 0, 0 );
968   actor.SetSize( 400, 800 );
969
970   tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
971   tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
972   tetButton.SetPosition( 240, 400 );
973   tetButton.SetSize( 100, 100 );
974
975   actor.Add( tetButton );
976   Stage::GetCurrent().Add( actor );
977
978   // * Actor's touch event is connected to a callback function
979   //   and this callback function consumes the event.
980   actor.TouchedSignal().Connect( &TestCallback );
981
982   // * Button's pressed signal is connected to a callback function
983   //   which also consumes the event.
984   // * Changes the sensitiveness of the button to false.
985   TETButtonPressed tetButtonPressed( actor, TETButtonPressed::SENSITIVENESS );
986   tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
987
988   // Initializes TET state.
989   gOnTouchPointInterrupted = false;
990   tetButton.SetSensitive( true );
991
992   Dali::Integration::TouchEvent event;
993
994   // TET starts.
995
996   // Test a down point inside the button which is also consumed by the actor, and an up point
997   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
998   // interrupt event.
999
1000   application.SendNotification();
1001   application.Render();
1002
1003   // A down event is sent inside the button's boundary.
1004
1005   event = Dali::Integration::TouchEvent();
1006   event.AddPoint( pointDownInside );
1007
1008   // flush the queue and render once
1009   application.SendNotification();
1010   application.Render();
1011   application.ProcessEvent( event );
1012
1013   // An up event is sent outside the button's boundary but inside the actor's one.
1014
1015   event = Dali::Integration::TouchEvent();
1016   event.AddPoint( pointUpOutside );
1017
1018   // flush the queue and render once
1019   application.SendNotification();
1020   application.Render();
1021   application.ProcessEvent( event );
1022
1023   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1024
1025   // Test a down point inside the button which is also consumed by the actor, and a motion point
1026   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
1027   // interrupt event.
1028
1029   // Initializes TET state.
1030   gOnTouchPointInterrupted = false;
1031   actor.SetSensitive( true );
1032   tetButton.SetSensitive( true );
1033
1034   application.SendNotification();
1035   application.Render();
1036
1037   // A down event is sent inside the button's boundary.
1038
1039   event = Dali::Integration::TouchEvent();
1040   event.AddPoint( pointDownInside );
1041
1042   // flush the queue and render once
1043   application.SendNotification();
1044   application.Render();
1045   application.ProcessEvent( event );
1046
1047   // A motion event is sent outside the button's boundary but inside the actor's one.
1048
1049   event = Dali::Integration::TouchEvent();
1050   event.AddPoint( pointMotionOut );
1051
1052   // flush the queue and render once
1053   application.SendNotification();
1054   application.Render();
1055   application.ProcessEvent( event );
1056
1057   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1058
1059   // Test a down point inside the button which is also consumed by the actor, and an up point
1060   // also inside the button and consumed by the actor.  gOnTouchPointInterrupted should be false.
1061
1062   // Initializes TET state.
1063   gOnTouchPointInterrupted = false;
1064   actor.SetSensitive( true );
1065   tetButton.SetSensitive( true );
1066
1067   // A down event is sent inside the button's boundary.
1068
1069   event = Dali::Integration::TouchEvent();
1070   event.AddPoint( pointDownInside );
1071
1072   // flush the queue and render once
1073   application.SendNotification();
1074   application.Render();
1075   application.ProcessEvent( event );
1076
1077   actor.SetSensitive( true );
1078   // An up event is sent inside the button's boundary.
1079
1080   event = Dali::Integration::TouchEvent();
1081   event.AddPoint( pointUpInside );
1082
1083   // flush the queue and render once
1084   application.SendNotification();
1085   application.Render();
1086   application.ProcessEvent( event );
1087
1088   DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1089 }
1090
1091 static void UtcDaliPushButtonInterruptEventWhenNonVisible()
1092 {
1093   ToolkitTestApplication application;
1094   tet_infoline(" UtcDaliPushButtonInterruptEventWhenNonVisible");
1095
1096   // Does same test as above but changing the visibility instead the sensitiveness.
1097
1098   // * Creates an actor which contains a button.
1099   // * The size of the actor is bigger than the button.
1100   // * The button's boundary is contained in the actor's one.
1101   Actor actor = Actor::New();
1102   TETButton tetButton = Toolkit::TETButton::New();
1103
1104   actor.SetName( "Actor" );
1105   tetButton.SetName( "TETButton" );
1106
1107   actor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1108   actor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1109   actor.SetPosition( 0, 0 );
1110   actor.SetSize( 400, 800 );
1111
1112   tetButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1113   tetButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1114   tetButton.SetPosition( 240, 400 );
1115   tetButton.SetSize( 100, 100 );
1116
1117   actor.Add( tetButton );
1118   Stage::GetCurrent().Add( actor );
1119
1120   // * Actor's touch event is connected to a callback function
1121   //   and this callback function consumes the event.
1122   actor.TouchedSignal().Connect( &TestCallback );
1123
1124   // * Button's pressed signal is connected to a callback function
1125   //   which also consumes the event.
1126   // * Changes the visibility of the button to false.
1127   TETButtonPressed tetButtonPressed( tetButton, TETButtonPressed::VISIBILITY );
1128   tetButton.PressedSignal().Connect( &tetButtonPressed, &TETButtonPressed::Callback );
1129
1130   // Initializes TET state.
1131   gOnTouchPointInterrupted = false;
1132   tetButton.SetVisible( true );
1133
1134   Dali::Integration::TouchEvent event;
1135
1136   // TET starts.
1137
1138   // Test a down point inside the button which is also consumed by the actor, and an up point
1139   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
1140   // interrupt event.
1141
1142   application.SendNotification();
1143   application.Render();
1144
1145   // A down event is sent inside the button's boundary.
1146
1147   event = Dali::Integration::TouchEvent();
1148   event.AddPoint( pointDownInside );
1149
1150   // flush the queue and render once
1151   application.SendNotification();
1152   application.Render();
1153   application.ProcessEvent( event );
1154
1155   // More renders are needed in order to allow the node of the actor to become invisible.
1156   application.SendNotification();
1157   application.Render();
1158   application.SendNotification();
1159   application.Render();
1160   application.SendNotification();
1161   application.Render();
1162
1163   // An up event is sent outside the button's boundary but inside the actor's one.
1164
1165   event = Dali::Integration::TouchEvent();
1166   event.AddPoint( pointUpOutside );
1167
1168   // flush the queue and render once
1169   application.SendNotification();
1170   application.Render();
1171   application.ProcessEvent( event );
1172
1173   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1174
1175   // Test a down point inside the button which is also consumed by the actor, and a motion point
1176   // consumed only by the actor.  gOnTouchPointInterrupted should be true (Button receives an
1177   // interrupt event.
1178
1179   // Initializes TET state.
1180   gOnTouchPointInterrupted = false;
1181   tetButton.SetVisible( true );
1182
1183   application.SendNotification();
1184   application.Render();
1185   application.SendNotification();
1186   application.Render();
1187   application.SendNotification();
1188   application.Render();
1189
1190   // A down event is sent inside the button's boundary.
1191
1192   event = Dali::Integration::TouchEvent();
1193   event.AddPoint( pointDownInside );
1194
1195   // flush the queue and render once
1196   application.SendNotification();
1197   application.Render();
1198   application.ProcessEvent( event );
1199
1200   // More renders are needed in order to allow the node of the actor to become invisible.
1201   application.SendNotification();
1202   application.Render();
1203   application.SendNotification();
1204   application.Render();
1205   application.SendNotification();
1206   application.Render();
1207
1208   // A motion event is sent outside the button's boundary but inside the actor's one.
1209
1210   event = Dali::Integration::TouchEvent();
1211   event.AddPoint( pointMotionOut );
1212
1213   // flush the queue and render once
1214   application.SendNotification();
1215   application.Render();
1216   application.ProcessEvent( event );
1217
1218   DALI_TEST_CHECK( gOnTouchPointInterrupted );
1219
1220   // Test a down point inside the button which is also consumed by the actor, and an up point
1221   // also inside the button and consumed by the actor.  gOnTouchPointInterrupted should be false.
1222
1223   // Initializes TET state.
1224   gOnTouchPointInterrupted = false;
1225   tetButton.SetVisible( true );
1226
1227   application.SendNotification();
1228   application.Render();
1229   application.SendNotification();
1230   application.Render();
1231   application.SendNotification();
1232   application.Render();
1233
1234   // A down event is sent inside the button's boundary.
1235
1236   event = Dali::Integration::TouchEvent();
1237   event.AddPoint( pointDownInside );
1238
1239   // flush the queue and render once
1240   application.SendNotification();
1241   application.Render();
1242   application.ProcessEvent( event );
1243
1244   tetButton.SetVisible( true );
1245
1246   application.SendNotification();
1247   application.Render();
1248   application.SendNotification();
1249   application.Render();
1250   application.SendNotification();
1251   application.Render();
1252
1253   // An up event is sent inside the button's boundary.
1254
1255   event = Dali::Integration::TouchEvent();
1256   event.AddPoint( pointUpInside );
1257
1258   // flush the queue and render once
1259   application.SendNotification();
1260   application.Render();
1261   application.ProcessEvent( event );
1262
1263   DALI_TEST_CHECK( !gOnTouchPointInterrupted );
1264 }
1265
1266 void UtcDaliPushButtonProperties()
1267 {
1268   ToolkitTestApplication application;
1269
1270   PushButton button = PushButton::New();
1271   Stage::GetCurrent().Add( button );
1272
1273   // PushButton::PROPERTY_AUTO_REPEATING
1274   button.SetAutoRepeating( false );
1275   DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
1276   button.SetProperty( PushButton::PROPERTY_AUTO_REPEATING, true );
1277   DALI_TEST_CHECK( button.IsAutoRepeating() ) ;
1278   DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_AUTO_REPEATING ) );
1279
1280   // PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY
1281   button.SetInitialAutoRepeatingDelay( 10.0f );
1282   DALI_TEST_EQUALS( 10.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1283   button.SetProperty( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY, 25.0f );
1284   DALI_TEST_EQUALS( 25.0f, button.GetInitialAutoRepeatingDelay(), TEST_LOCATION );
1285   DALI_TEST_EQUALS( 25.0f, button.GetProperty< float >( PushButton::PROPERTY_INITIAL_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1286
1287   //  PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY
1288   button.SetNextAutoRepeatingDelay( 3.0f );
1289   DALI_TEST_EQUALS( 3.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1290   button.SetProperty( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY, 4.0f );
1291   DALI_TEST_EQUALS( 4.0f, button.GetNextAutoRepeatingDelay(), TEST_LOCATION );
1292   DALI_TEST_EQUALS( 4.0f, button.GetProperty< float >( PushButton::PROPERTY_NEXT_AUTO_REPEATING_DELAY ), TEST_LOCATION );
1293
1294   //  PushButton::PROPERTY_TOGGLABLE
1295   button.SetToggleButton( false );
1296   DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
1297   button.SetProperty( PushButton::PROPERTY_TOGGLABLE, true );
1298   DALI_TEST_CHECK( button.IsToggleButton() ) ;
1299   DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLABLE ) );
1300
1301   //  PushButton::PROPERTY_TOGGLE
1302   button.SetToggled( false );
1303   DALI_TEST_CHECK( ! button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
1304   button.SetProperty( PushButton::PROPERTY_TOGGLE, true );
1305   DALI_TEST_CHECK( button.IsToggled() ) ;
1306   DALI_TEST_CHECK( button.GetProperty< bool >( PushButton::PROPERTY_TOGGLE ) );
1307
1308   //  PushButton::PROPERTY_NORMAL_STATE_ACTOR
1309   {
1310     button.SetButtonImage( Image::New( "IMAGE_PATH_1") );
1311     DALI_TEST_EQUALS( "IMAGE_PATH_1", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1312
1313     Property::Map map;
1314     map.push_back( Property::StringValuePair( "type", "ImageActor" ) );
1315
1316     button.SetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR, map );
1317     DALI_TEST_EQUALS( "ImageActor", button.GetProperty( PushButton::PROPERTY_NORMAL_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1318   }
1319
1320   //  PushButton::PROPERTY_PRESSED_IMAGE
1321   {
1322     button.SetPressedImage( Image::New( "IMAGE_PATH_2") );
1323     DALI_TEST_EQUALS( "IMAGE_PATH_2", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1324
1325     Property::Map map;
1326     map.push_back( Property::StringValuePair( "type", "TextActor" ) );
1327
1328     button.SetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR, map );
1329     DALI_TEST_EQUALS( "TextActor", button.GetProperty( PushButton::PROPERTY_PRESSED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1330   }
1331
1332   //  PushButton::PROPERTY_DIMMED_STATE_ACTOR
1333   {
1334     button.SetDimmedImage( Image::New( "IMAGE_PATH_3") );
1335     DALI_TEST_EQUALS( "IMAGE_PATH_3", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "image" ).GetValue( "filename" ).Get< std::string >(), TEST_LOCATION );
1336
1337     Property::Map map;
1338     map.push_back( Property::StringValuePair( "type", "Actor" ) );
1339
1340     button.SetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR, map );
1341     DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_DIMMED_STATE_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1342   }
1343
1344   //  PushButton::PROPERTY_LABEL_ACTOR
1345   {
1346     button.SetLabelText( "LABEL_TEXT_CUSTOM" );
1347     DALI_TEST_EQUALS( "TextView", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1348
1349     Property::Map map;
1350     map.push_back( Property::StringValuePair( "type", "Actor" ) );
1351
1352     button.SetProperty( PushButton::PROPERTY_LABEL_ACTOR, map );
1353     DALI_TEST_EQUALS( "Actor", button.GetProperty( PushButton::PROPERTY_LABEL_ACTOR ).GetValue( "type" ).Get< std::string >(), TEST_LOCATION );
1354   }
1355 }