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