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