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