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