Merge "DALi Version 1.2.49" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Button.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 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24 #include "dali-toolkit-test-utils/toolkit-timer.h"
25
26 #include <dali.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali/integration-api/events/touch-event-integ.h>
29
30 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
31 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
33
34 using namespace Dali;
35 using namespace Toolkit;
36
37
38 void utc_dali_toolkit_button_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void utc_dali_toolkit_button_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48 namespace
49 {
50 static bool gIsCalledButtonCallback = false;
51
52 const int RENDER_FRAME_INTERVAL = 16;
53
54 static bool ButtonCallback( Button button )
55 {
56   gIsCalledButtonCallback = true;
57   return false;
58 }
59
60 static std::string GetButtonText( Button button )
61 {
62   Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
63
64   Property::Map *labelProperty = value.GetMap();
65
66   std::string textLabel;
67
68   if ( labelProperty )
69   {
70     Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
71     value->Get( textLabel );
72   }
73
74   return textLabel;
75 }
76
77 struct CallbackFunctor
78 {
79   CallbackFunctor(bool* callbackFlag)
80   : mCallbackFlag( callbackFlag )
81   {
82   }
83
84   void operator()()
85   {
86     *mCallbackFlag = true;
87   }
88   bool* mCallbackFlag;
89 };
90
91 Dali::Integration::Point GetPointDownInside()
92 {
93   Dali::Integration::Point point;
94   point.SetState( PointState::DOWN );
95   point.SetScreenPosition( Vector2( 240, 400 ) );
96   return point;
97 }
98
99 Dali::Integration::Point GetPointUpInside()
100 {
101   Dali::Integration::Point point;
102   point.SetState( PointState::UP );
103   point.SetScreenPosition( Vector2( 240, 400 ) );
104   return point;
105 }
106
107 Dali::Integration::Point GetPointLeave()
108 {
109   Dali::Integration::Point point;
110   point.SetState( PointState::LEAVE );
111   point.SetScreenPosition( Vector2( 240, 400 ) );
112   return point;
113 }
114
115 Dali::Integration::Point GetPointEnter()
116 {
117   Dali::Integration::Point point;
118   point.SetState( PointState::MOTION );
119   point.SetScreenPosition( Vector2( 240, 400 ) );
120   return point;
121 }
122
123 Dali::Integration::Point GetPointDownOutside()
124 {
125   Dali::Integration::Point point;
126   point.SetState( PointState::DOWN );
127   point.SetScreenPosition( Vector2( 10, 10 ) );
128   return point;
129 }
130
131 Dali::Integration::Point GetPointUpOutside()
132 {
133   Dali::Integration::Point point;
134   point.SetState( PointState::UP );
135   point.SetScreenPosition( Vector2( 10, 10 ) );
136   return point;
137 }
138
139 static float ANIMATION_TIME( 0.5f );
140
141 } // namespace
142
143 int UtcDaliButtonConstructorP(void)
144 {
145   TestApplication application;
146
147   Button button;
148
149   DALI_TEST_CHECK( !button );
150   END_TEST;
151 }
152
153 int UtcDaliButtonCopyConstructorP(void)
154 {
155   TestApplication application;
156
157   // Initialize an object, ref count == 1
158   Button button = PushButton::New();
159
160   Button copy( button );
161   DALI_TEST_CHECK( copy );
162   END_TEST;
163 }
164
165 int UtcDaliButtonAssignmentOperatorP(void)
166 {
167   TestApplication application;
168
169   Button button = PushButton::New();
170
171   Button copy( button );
172   DALI_TEST_CHECK( copy );
173
174   DALI_TEST_CHECK( button == copy );
175   END_TEST;
176 }
177
178 int UtcDaliButtonDownCastP(void)
179 {
180   TestApplication application;
181
182   Button button = PushButton::New();
183
184   BaseHandle object(button);
185
186   Button button2 = Button::DownCast( object );
187   DALI_TEST_CHECK(button2);
188
189   Button button3 = DownCast< Button >(object);
190   DALI_TEST_CHECK(button3);
191   END_TEST;
192 }
193
194 int UtcDaliButtonDownCastN(void)
195 {
196   TestApplication application;
197
198   BaseHandle unInitializedObject;
199
200   Button button1 = Button::DownCast( unInitializedObject );
201   DALI_TEST_CHECK( !button1 );
202
203   Button button2 = DownCast< Button >( unInitializedObject );
204   DALI_TEST_CHECK( !button2 );
205   END_TEST;
206 }
207
208 int UtcDaliButtonDisabledPropertyP(void)
209 {
210   ToolkitTestApplication application;
211
212   Button button = PushButton::New();
213
214
215   button.SetProperty( button.GetPropertyIndex("disabled"), true );
216
217   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), true, TEST_LOCATION );
218
219   button.SetProperty( button.GetPropertyIndex("disabled"), false );
220
221   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), false, TEST_LOCATION );
222
223   button.SetProperty( button.GetPropertyIndex("disabled"), true );
224
225   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), true, TEST_LOCATION );
226
227   button.SetProperty( button.GetPropertyIndex("disabled"), false );
228
229   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("disabled")), false, TEST_LOCATION );
230
231   END_TEST;
232 }
233
234 int UtcDaliButtonSetDisabledWithDifferentStates01P(void)
235 {
236   ToolkitTestApplication application;
237
238   tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n");
239
240   Button button = PushButton::New();
241
242   bool SELECTED = true;
243
244   button.SetProperty( Button::Property::TOGGLABLE, true);
245   button.SetProperty( Button::Property::SELECTED, SELECTED );
246
247   button.SetProperty( Button::Property::DISABLED, true);
248
249   tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n");
250   button.SetProperty( Button::Property::SELECTED, !SELECTED );
251
252   bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
253
254   DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
255
256   END_TEST;
257 }
258
259 int UtcDaliButtonSetDisabledWithDifferentStates02P(void)
260 {
261   ToolkitTestApplication application;
262
263   tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n");
264
265   Button button = PushButton::New();
266
267   bool SELECTED = true;
268
269   button.SetProperty( Button::Property::TOGGLABLE, true );
270   button.SetProperty( Button::Property::SELECTED, SELECTED );
271   button.SetProperty( Button::Property::DISABLED, true );
272
273   bool isSelected =  button.GetProperty<bool>( Button::Property::SELECTED );
274   DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
275   tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n");
276
277   button.SetProperty( Button::Property::DISABLED, false );
278   button.SetProperty( Button::Property::SELECTED, !SELECTED );
279
280   isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
281   DALI_TEST_EQUALS( isSelected, !SELECTED , TEST_LOCATION );
282
283   END_TEST;
284 }
285
286 int UtcDaliButtonPropertyGetLabelAlignment(void)
287 {
288   ToolkitTestApplication application;
289   tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
290
291   Button button = PushButton::New();
292   button.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END"  );
293   DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
294
295   END_TEST;
296 }
297
298 int UtcDaliButtonIsDisabledP(void)
299 {
300   ToolkitTestApplication application;
301
302   Button button = PushButton::New();
303
304   button.SetDisabled( true );
305
306   DALI_TEST_CHECK( button.IsDisabled() );
307
308   button.SetDisabled( false );
309
310   DALI_TEST_CHECK( !button.IsDisabled() );
311   END_TEST;
312 }
313
314 int UtcDaliButtonAutoRepeatingPropertyP(void)
315 {
316   ToolkitTestApplication application;
317
318   Button button = PushButton::New();
319
320   button.SetProperty( button.GetPropertyIndex("autoRepeating"), true );
321
322   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
323
324   button.SetProperty( button.GetPropertyIndex("autoRepeating"), false );
325
326   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION );
327
328   button.SetProperty( button.GetPropertyIndex("autoRepeating"), true );
329
330   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION );
331
332   button.SetAutoRepeating( false );
333
334   DALI_TEST_CHECK( !button.IsAutoRepeating() );
335   END_TEST;
336 }
337
338 int UtcDaliButtonIsAutoRepeatingP(void)
339 {
340   ToolkitTestApplication application;
341
342   Button button = PushButton::New();
343
344   button.SetAutoRepeating( true );
345
346   DALI_TEST_CHECK( button.IsAutoRepeating() );
347
348   button.SetAutoRepeating( false );
349
350   DALI_TEST_CHECK( !button.IsAutoRepeating() );
351   END_TEST;
352 }
353
354 int UtcDaliButtonAutoRepeatingP(void)
355 {
356   ToolkitTestApplication application;
357   tet_infoline(" UtcDaliButtonPressedSignalP  Setup Autorepeating and check multiple clicked signals received\n");
358
359   const float AUTO_REPEATING_DELAY = 0.15f;
360
361   Button button = PushButton::New();
362   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
363   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
364   button.SetPosition( 240, 400 );
365   button.SetSize( 100, 100 );
366   Stage::GetCurrent().Add( button );
367
368   application.SendNotification();
369   application.Render();
370
371   button.SetProperty( Toolkit::Button::Property::AUTO_REPEATING, true  );
372   button.SetProperty( Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY );
373   // connect to its touch signal
374   ConnectionTracker* testTracker = new ConnectionTracker();
375   button.PressedSignal().Connect( &ButtonCallback );
376   button.ClickedSignal().Connect( &ButtonCallback );
377   bool clickedSignal = false;
378   bool pressedSignal = false;
379   button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
380   button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
381
382   Dali::Integration::TouchEvent event;
383
384   // Touch point down and up inside the button.
385
386   gIsCalledButtonCallback = false;
387   event = Dali::Integration::TouchEvent();
388   event.AddPoint( GetPointDownInside() );
389   application.ProcessEvent( event );
390
391   DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
392   DALI_TEST_EQUALS( pressedSignal, true, TEST_LOCATION );
393   tet_infoline("Consume first clicked signal then wait\n");
394
395   gIsCalledButtonCallback = false;
396   Dali::Timer timer = Timer::New( AUTO_REPEATING_DELAY );
397   timer.MockEmitSignal();
398   application.Wait( AUTO_REPEATING_DELAY*2 );
399   DALI_TEST_EQUALS( clickedSignal, true, TEST_LOCATION );
400   tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n");
401
402   DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
403
404   gIsCalledButtonCallback = false;
405   event = Dali::Integration::TouchEvent();
406   event.AddPoint( GetPointUpInside() );
407   application.ProcessEvent( event );
408
409   DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
410
411   END_TEST;
412 }
413
414 int UtcDaliButtonInitialAutoRepeatingDelayPropertyP(void)
415 {
416   ToolkitTestApplication application;
417
418   Button button = PushButton::New();
419
420   button.SetProperty( button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.5f );
421
422   DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.5f, TEST_LOCATION );
423
424   button.SetProperty( button.GetPropertyIndex("initialAutoRepeatingDelay"), 0.2f );
425
426   DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("initialAutoRepeatingDelay")), 0.2f, TEST_LOCATION );
427
428   END_TEST;
429 }
430
431 int UtcDaliButtonNextAutoRepeatingDelayPropertyP(void)
432 {
433   ToolkitTestApplication application;
434
435   Button button = PushButton::New();
436
437   button.SetProperty( button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.5f );
438
439   DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.5f, TEST_LOCATION );
440
441   button.SetProperty( button.GetPropertyIndex("nextAutoRepeatingDelay"), 0.2f );
442
443   DALI_TEST_EQUALS( button.GetProperty<float>( button.GetPropertyIndex("nextAutoRepeatingDelay")), 0.2f, TEST_LOCATION );
444   END_TEST;
445 }
446
447 int UtcDaliButtonTogglableButtonPropertyP(void)
448 {
449   ToolkitTestApplication application;
450
451   Button button = PushButton::New();
452
453   button.SetProperty( button.GetPropertyIndex("togglable"), true );
454
455   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("togglable")), true, TEST_LOCATION );
456
457   button.SetProperty( button.GetPropertyIndex("togglable"), false );
458
459   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("togglable")), false, TEST_LOCATION );
460   END_TEST;
461 }
462
463 int UtcDaliButtonSelectedPropertyP(void)
464 {
465   ToolkitTestApplication application;
466
467   Button button = PushButton::New();
468   button.SetProperty( button.GetPropertyIndex("togglable"), true );
469
470   button.SetProperty( button.GetPropertyIndex("selected"), true );
471
472   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("selected")), true, TEST_LOCATION );
473
474   button.SetProperty( button.GetPropertyIndex("selected"), false );
475
476   DALI_TEST_EQUALS( button.GetProperty<bool>( button.GetPropertyIndex("selected")), false, TEST_LOCATION );
477   END_TEST;
478 }
479
480 int UtcDaliButtonSetAnimationTimeP(void)
481 {
482   ToolkitTestApplication application;
483   tet_infoline(" UtcDaliButtonSetAnimationTimeP");
484
485   Button button = PushButton::New();
486
487   button.SetAnimationTime( ANIMATION_TIME );
488
489   DALI_TEST_EQUALS( button.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
490   END_TEST;
491 }
492
493 int UtcDaliButtonSetLabelStringWithPropertyMapP(void)
494 {
495   ToolkitTestApplication application;
496
497   Button button = PushButton::New();
498   button.SetProperty( Toolkit::Button::Property::LABEL,
499                       Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
500                                      .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
501                                      .Add( Toolkit::TextVisual::Property::TEXT, "Button Label")
502                      );
503
504   DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
505   END_TEST;
506 }
507
508 int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void)
509 {
510   ToolkitTestApplication application;
511
512   Button button = PushButton::New();
513
514   tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string");
515
516   Property::Map textVisualMapInitial;
517   textVisualMapInitial["visualType"] = "TEXT";
518   textVisualMapInitial["pointSize"] =  15.0f;
519   textVisualMapInitial["text"] = "button label initial";
520
521   button.SetProperty( Button::Property::LABEL, textVisualMapInitial );
522
523   DALI_TEST_EQUALS( GetButtonText( button ), "button label initial", TEST_LOCATION );
524
525   tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test");
526
527   Property::Map propertyMap;
528   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::DevelVisual::TEXT );
529   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT,  "error if this is the final text" );
530   propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
531
532   button.SetProperty( Button::Property::LABEL, propertyMap );
533
534   DALI_TEST_EQUALS( GetButtonText( button ), "error if this is the final text", TEST_LOCATION );
535
536   tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test");
537
538   Property::Map textVisualMap;
539   textVisualMap["visualType"] = "TEXT";
540   textVisualMap["pointSize"] =  15.0f;
541   textVisualMap["text"] = "Button Label";
542
543   button.SetProperty( Toolkit::Button::Property::LABEL, textVisualMap );
544
545   DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
546   END_TEST;
547 }
548
549 int UtcDaliButtonSetLabelWithStringP(void)
550 {
551   ToolkitTestApplication application;
552
553   Button button = PushButton::New();
554
555   // Set default point size for text visual as style sheet not available.
556   button.SetProperty( Toolkit::Button::Property::LABEL,
557                       Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
558                                      .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
559                                      );
560
561   button.SetProperty( Toolkit::Button::Property::LABEL, "Button Label" );
562
563   DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
564   END_TEST;
565 }
566
567 int UtcDaliButtonSetLabelPropertyP(void)
568 {
569   ToolkitTestApplication application;
570
571   tet_infoline(" UtcDaliButtonSetLabelPropertyP Set text label and then set again with new text");
572
573
574   const std::string TEST_LABEL1 = "test label one";
575   const std::string TEST_LABEL2 = "test label two";
576
577   Button button = PushButton::New();
578
579   button.SetProperty( Toolkit::Button::Property::LABEL,
580                         Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
581                                        .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
582                                        .Add( Toolkit::TextVisual::Property::TEXT, TEST_LABEL1 )
583                      );
584
585   DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL1,  TEST_LOCATION );
586
587   Property::Map propertyMap;
588   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::DevelVisual::TEXT );
589   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT,  TEST_LABEL2 );
590   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
591   propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
592   button.SetProperty( Button::Property::LABEL, propertyMap );
593
594   DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL2,  TEST_LOCATION );
595
596   END_TEST;
597 }
598
599 int UtcDaliButtonPressedSignalP(void)
600 {
601   ToolkitTestApplication application;
602   tet_infoline(" UtcDaliButtonPressedSignalP");
603
604   Button button = PushButton::New();
605   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
606   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
607   button.SetPosition( 240, 400 );
608   button.SetSize( 100, 100 );
609
610   Stage::GetCurrent().Add( button );
611
612   application.SendNotification();
613   application.Render();
614
615   // connect to its touch signal
616   ConnectionTracker* testTracker = new ConnectionTracker();
617   button.PressedSignal().Connect( &ButtonCallback );
618   button.ReleasedSignal().Connect( &ButtonCallback );
619   bool pressedSignal = false;
620   bool releasedSignal = false;
621   button.ConnectSignal( testTracker, "pressed",   CallbackFunctor(&pressedSignal) );
622   button.ConnectSignal( testTracker, "released",  CallbackFunctor(&releasedSignal) );
623
624   Dali::Integration::TouchEvent event;
625
626   // Test1. Touch point down and up inside the button.
627
628   gIsCalledButtonCallback = false;
629   event = Dali::Integration::TouchEvent();
630   event.AddPoint( GetPointDownInside() );
631   application.ProcessEvent( event );
632
633   DALI_TEST_CHECK( gIsCalledButtonCallback );
634   DALI_TEST_CHECK( pressedSignal );
635
636   gIsCalledButtonCallback = false;
637   event = Dali::Integration::TouchEvent();
638   event.AddPoint( GetPointUpInside() );
639   application.ProcessEvent( event );
640
641   DALI_TEST_CHECK( gIsCalledButtonCallback );
642   DALI_TEST_CHECK( releasedSignal );
643
644   // Test2. Touch point down and up outside the button.
645
646   pressedSignal = false;
647   releasedSignal = false;
648   gIsCalledButtonCallback = false;
649   event = Dali::Integration::TouchEvent();
650   event.AddPoint( GetPointDownOutside() );
651   application.ProcessEvent( event );
652
653   DALI_TEST_CHECK( !gIsCalledButtonCallback );
654   DALI_TEST_CHECK( !pressedSignal );
655
656   gIsCalledButtonCallback = false;
657   event = Dali::Integration::TouchEvent();
658   event.AddPoint( GetPointUpOutside() );
659   application.ProcessEvent( event );
660
661   DALI_TEST_CHECK( !gIsCalledButtonCallback );
662   DALI_TEST_CHECK( !releasedSignal );
663
664   // Test3. Touch point down inside and up outside the button.
665
666   gIsCalledButtonCallback = false;
667   event = Dali::Integration::TouchEvent();
668   event.AddPoint( GetPointDownInside() );
669   application.ProcessEvent( event );
670
671   DALI_TEST_CHECK( gIsCalledButtonCallback );
672
673   gIsCalledButtonCallback = false;
674   event = Dali::Integration::TouchEvent();
675   event.AddPoint( GetPointLeave() );
676   application.ProcessEvent( event );
677
678   event = Dali::Integration::TouchEvent();
679   event.AddPoint( GetPointUpOutside() );
680   application.ProcessEvent( event );
681
682   DALI_TEST_CHECK( gIsCalledButtonCallback );
683
684   // Test4. Touch point down outside and up inside the button.
685
686   gIsCalledButtonCallback = false;
687   event = Dali::Integration::TouchEvent();
688   event.AddPoint( GetPointDownOutside() );
689   application.ProcessEvent( event );
690
691   DALI_TEST_CHECK( !gIsCalledButtonCallback );
692
693   gIsCalledButtonCallback = false;
694   event = Dali::Integration::TouchEvent();
695   event.AddPoint( GetPointEnter() );
696   application.ProcessEvent( event );
697
698   event = Dali::Integration::TouchEvent();
699   event.AddPoint( GetPointUpInside() );
700   application.ProcessEvent( event );
701
702   DALI_TEST_CHECK( !gIsCalledButtonCallback );
703   END_TEST;
704 }
705
706 int UtcDaliButtonClickedSignalP(void)
707 {
708   ToolkitTestApplication application;
709   tet_infoline(" UtcDaliButtonClickedSignalP");
710
711   Button button = PushButton::New();
712   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
713   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
714   button.SetPosition( 240, 400 );
715   button.SetSize( 100, 100 );
716
717   Stage::GetCurrent().Add( button );
718
719   application.SendNotification();
720   application.Render();
721
722   // connect to its touch signal
723   button.ClickedSignal().Connect( &ButtonCallback );
724   bool clickedSignal = false;
725   ConnectionTracker* testTracker = new ConnectionTracker();
726   button.ConnectSignal( testTracker, "clicked",   CallbackFunctor(&clickedSignal) );
727
728   Dali::Integration::TouchEvent event;
729
730   // Test1. Touch point down and up inside the button.
731
732   gIsCalledButtonCallback = false;
733   event = Dali::Integration::TouchEvent();
734   event.AddPoint( GetPointDownInside() );
735   application.ProcessEvent( event );
736
737   event = Dali::Integration::TouchEvent();
738   event.AddPoint( GetPointUpInside() );
739   application.ProcessEvent( event );
740
741   DALI_TEST_CHECK( gIsCalledButtonCallback );
742   DALI_TEST_CHECK( clickedSignal );
743
744   // Test2. Touch point down and up outside the button.
745
746   gIsCalledButtonCallback = false;
747   clickedSignal = false;
748   event = Dali::Integration::TouchEvent();
749   event.AddPoint( GetPointDownOutside() );
750   application.ProcessEvent( event );
751
752   event = Dali::Integration::TouchEvent();
753   event.AddPoint( GetPointUpOutside() );
754   application.ProcessEvent( event );
755
756   DALI_TEST_CHECK( !gIsCalledButtonCallback );
757   DALI_TEST_CHECK( !clickedSignal );
758
759   // Test3. Touch point down inside and up outside the button.
760
761   gIsCalledButtonCallback = false;
762   clickedSignal = false;
763   event = Dali::Integration::TouchEvent();
764   event.AddPoint( GetPointDownInside() );
765   application.ProcessEvent( event );
766
767   event = Dali::Integration::TouchEvent();
768   event.AddPoint( GetPointLeave() );
769   application.ProcessEvent( event );
770
771   event = Dali::Integration::TouchEvent();
772   event.AddPoint( GetPointUpOutside() );
773   application.ProcessEvent( event );
774
775   DALI_TEST_CHECK( !gIsCalledButtonCallback );
776   DALI_TEST_CHECK( !clickedSignal );
777
778   // Test4. Touch point down outside and up inside the button.
779
780   gIsCalledButtonCallback = false;
781   clickedSignal = false;
782   event = Dali::Integration::TouchEvent();
783   event.AddPoint( GetPointDownOutside() );
784   application.ProcessEvent( event );
785
786   event = Dali::Integration::TouchEvent();
787   event.AddPoint( GetPointEnter() );
788   application.ProcessEvent( event );
789
790   event = Dali::Integration::TouchEvent();
791   event.AddPoint( GetPointUpInside() );
792   application.ProcessEvent( event );
793
794   DALI_TEST_CHECK( !gIsCalledButtonCallback );
795   DALI_TEST_CHECK( !clickedSignal );
796   END_TEST;
797 }
798
799 int UtcDaliButtonStateChangedSignalP(void)
800 {
801   ToolkitTestApplication application;
802   tet_infoline(" UtcDaliButtonStateChangedSignalP");
803
804   Button button = PushButton::New();
805
806   button.SetProperty( Button::Property::TOGGLABLE, true);
807
808   Stage::GetCurrent().Add( button );
809
810   application.SendNotification();
811   application.Render();
812
813   // connect to its signal
814   button.StateChangedSignal().Connect( &ButtonCallback );
815   bool stateChangedSignal = false;
816   ConnectionTracker* testTracker = new ConnectionTracker();
817   button.ConnectSignal( testTracker, "stateChanged",   CallbackFunctor(&stateChangedSignal) );
818
819   gIsCalledButtonCallback = false;
820   button.SetProperty( Button::Property::SELECTED, true);
821
822   DALI_TEST_CHECK( gIsCalledButtonCallback );
823   DALI_TEST_CHECK( stateChangedSignal );
824
825   gIsCalledButtonCallback = false;
826   stateChangedSignal = false;
827
828   button.SetProperty( Button::Property::SELECTED, false);
829   DALI_TEST_CHECK( gIsCalledButtonCallback );
830   DALI_TEST_CHECK( stateChangedSignal );
831   END_TEST;
832 }
833
834 int UtcDaliButtonSetProperty(void)
835 {
836   tet_infoline("UtcDaliButtonSetProperty: ");
837   ToolkitTestApplication application;
838
839   PushButton pushButton = PushButton::New();
840
841   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
842
843   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( pushButton.GetPropertyIndex("disabled")), false, TEST_LOCATION );
844
845   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
846   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( pushButton.GetPropertyIndex("disabled")), true, TEST_LOCATION );
847
848   END_TEST;
849 }
850
851 // Deprecated API Tests
852
853 int UtcDaliButtonSetDisabledP(void)
854 {
855   ToolkitTestApplication application;
856
857   Button button = PushButton::New();
858
859   button.SetDisabled( true );
860
861   DALI_TEST_CHECK( button.IsDisabled() );
862
863   button.SetDisabled( false );
864
865   DALI_TEST_CHECK( !button.IsDisabled() );
866
867   button.SetDisabled( true );
868
869   DALI_TEST_CHECK( button.IsDisabled() );
870
871   button.SetDisabled( false );
872
873   DALI_TEST_CHECK( !button.IsDisabled() );
874   END_TEST;
875 }
876
877 int UtcDaliButtonSetAutoRepeatingP(void)
878 {
879   ToolkitTestApplication application;
880
881   Button button = PushButton::New();
882
883   button.SetAutoRepeating( true );
884
885   DALI_TEST_CHECK( button.IsAutoRepeating() );
886
887   button.SetAutoRepeating( false );
888
889   DALI_TEST_CHECK( !button.IsAutoRepeating() );
890
891   button.SetAutoRepeating( true );
892
893   DALI_TEST_CHECK( button.IsAutoRepeating() );
894
895   button.SetAutoRepeating( false );
896
897   DALI_TEST_CHECK( !button.IsAutoRepeating() );
898   END_TEST;
899 }
900
901 int UtcDaliButtonSetInitialAutoRepeatingDelayP(void)
902 {
903   ToolkitTestApplication application;
904
905   Button button = PushButton::New();
906
907   button.SetInitialAutoRepeatingDelay( 0.5f );
908
909   DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
910
911   button.SetInitialAutoRepeatingDelay( 0.2f );
912
913   DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
914   END_TEST;
915 }
916
917 int UtcDaliButtonSetNextAutoRepeatingDelayP(void)
918 {
919   ToolkitTestApplication application;
920
921   Button button = PushButton::New();
922
923   button.SetNextAutoRepeatingDelay( 0.5f );
924
925   DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
926
927   button.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 0.2f );
928
929   DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
930   END_TEST;
931 }
932
933 int UtcDaliButtonSetTogglableButtonP(void)
934 {
935   ToolkitTestApplication application;
936
937   Button button = PushButton::New();
938
939   button.SetTogglableButton( true );
940
941   DALI_TEST_CHECK( button.IsTogglableButton() );
942
943   button.SetTogglableButton( false );
944
945   DALI_TEST_CHECK( !button.IsTogglableButton() );
946   END_TEST;
947 }
948
949 int UtcDaliButtonSetSelectedP(void)
950 {
951   ToolkitTestApplication application;
952
953   Button button = PushButton::New();
954   button.SetTogglableButton( true );
955
956   button.SetSelected( true );
957
958   DALI_TEST_CHECK( button.IsSelected() );
959
960   button.SetSelected( false );
961
962   DALI_TEST_CHECK( !button.IsSelected() );
963   END_TEST;
964 }