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