Updating code formatting
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-PushButton.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
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28
29 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
30
31 #include <dali/devel-api/adaptor-framework/image-loading.h>
32
33 using namespace Dali;
34 using namespace Toolkit;
35
36 void utc_dali_toolkit_pushbutton_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void utc_dali_toolkit_pushbutton_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 namespace
47 {
48 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
49
50 static const Vector2 INSIDE_TOUCH_POINT_POSITON                = Vector2(240, 400);
51 static const Vector3 BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS = Vector3(200, 360, 0);
52 static const Size    BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS    = Size(100, 100);
53
54 static bool gPushButtonSelectedState = false;
55 bool        PushButtonSelected(Button button)
56 {
57   gPushButtonSelectedState = button.GetProperty<bool>(button.GetPropertyIndex("selected"));
58   return true;
59 }
60
61 static bool gPushButtonPressed = false;
62
63 static bool PushButtonPressed(Button button)
64 {
65   gPushButtonPressed = true;
66   return true;
67 }
68
69 static bool gPushButtonReleased = false;
70
71 static bool PushButtonReleased(Button button)
72 {
73   gPushButtonReleased = true;
74   return true;
75 }
76
77 static bool gPushButtonClicked = false;
78
79 static bool PushButtonClicked(Button button)
80 {
81   gPushButtonClicked = true;
82   return gPushButtonClicked;
83 }
84
85 Dali::Integration::Point GetPointDownInside()
86 {
87   Dali::Integration::Point point;
88   point.SetState(PointState::DOWN);
89   point.SetScreenPosition(INSIDE_TOUCH_POINT_POSITON);
90   return point;
91 }
92
93 Dali::Integration::Point GetPointUpInside()
94 {
95   Dali::Integration::Point point;
96   point.SetState(PointState::UP);
97   point.SetScreenPosition(INSIDE_TOUCH_POINT_POSITON);
98   return point;
99 }
100
101 Dali::Integration::Point GetPointLeave()
102 {
103   Dali::Integration::Point point;
104   point.SetState(PointState::LEAVE);
105   point.SetScreenPosition(INSIDE_TOUCH_POINT_POSITON);
106   return point;
107 }
108
109 Dali::Integration::Point GetPointEnter()
110 {
111   Dali::Integration::Point point;
112   point.SetState(PointState::MOTION);
113   point.SetScreenPosition(INSIDE_TOUCH_POINT_POSITON);
114   return point;
115 }
116
117 Dali::Integration::Point GetPointDownOutside()
118 {
119   Dali::Integration::Point point;
120   point.SetState(PointState::DOWN);
121   point.SetScreenPosition(Vector2(10, 10));
122   return point;
123 }
124
125 Dali::Integration::Point GetPointUpOutside()
126 {
127   Dali::Integration::Point point;
128   point.SetState(PointState::UP);
129   point.SetScreenPosition(Vector2(10, 10));
130   return point;
131 }
132
133 // Set up the position of the button for the default test events
134 void SetupButtonForTestTouchEvents(ToolkitTestApplication& application, Button& button, bool useDefaultImages)
135 {
136   button.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
137   button.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
138   button.SetProperty(Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS);
139   if(useDefaultImages)
140   {
141     const Vector2            TEST_IMAGE_SIZE = Vector2(BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS);
142     TestPlatformAbstraction& platform        = application.GetPlatform();
143     platform.SetClosestImageSize(TEST_IMAGE_SIZE);
144     button.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE);
145     button.SetProperty(Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE);
146   }
147 }
148
149 static std::string GetButtonText(Button button)
150 {
151   Property::Value value = button.GetProperty(Toolkit::Button::Property::LABEL);
152
153   Property::Map* labelProperty = value.GetMap();
154
155   std::string textLabel;
156
157   if(labelProperty)
158   {
159     Property::Value* value = labelProperty->Find(Toolkit::TextVisual::Property::TEXT);
160     value->Get(textLabel);
161   }
162
163   return textLabel;
164 }
165
166 } //namespace
167
168 int UtcDaliPushButtonConstructorP(void)
169 {
170   ToolkitTestApplication application;
171
172   PushButton button;
173
174   DALI_TEST_CHECK(!button);
175   END_TEST;
176 }
177
178 int UtcDaliPushButtonCopyConstructorP(void)
179 {
180   ToolkitTestApplication application;
181
182   // Initialize an object, ref count == 1
183   PushButton button = PushButton::New();
184
185   PushButton copy(button);
186   DALI_TEST_CHECK(copy);
187   END_TEST;
188 }
189
190 int UtcDaliPushButtonMoveConstructor(void)
191 {
192   ToolkitTestApplication application;
193
194   PushButton button = PushButton::New();
195   DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION);
196   DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
197   button.SetProperty(Button::Property::TOGGLABLE, true);
198   DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
199
200   PushButton moved = std::move(button);
201   DALI_TEST_CHECK(moved);
202   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
203   DALI_TEST_EQUALS(moved.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
204   DALI_TEST_CHECK(!button);
205
206   END_TEST;
207 }
208
209 int UtcDaliPushButtonAssignmentOperatorP(void)
210 {
211   ToolkitTestApplication application;
212
213   PushButton button = PushButton::New();
214
215   PushButton copy(button);
216   DALI_TEST_CHECK(copy);
217
218   DALI_TEST_CHECK(button == copy);
219   END_TEST;
220 }
221
222 int UtcDaliPushButtonMoveAssignment(void)
223 {
224   ToolkitTestApplication application;
225
226   PushButton button = PushButton::New();
227   DALI_TEST_EQUALS(1, button.GetBaseObject().ReferenceCount(), TEST_LOCATION);
228   DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
229   button.SetProperty(Button::Property::TOGGLABLE, true);
230   DALI_TEST_EQUALS(button.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
231
232   PushButton moved;
233   moved = std::move(button);
234   DALI_TEST_CHECK(moved);
235   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
236   DALI_TEST_EQUALS(moved.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
237   DALI_TEST_CHECK(!button);
238
239   END_TEST;
240 }
241
242 int UtcDaliPushButtonNewP(void)
243 {
244   ToolkitTestApplication application;
245
246   PushButton button = PushButton::New();
247
248   DALI_TEST_CHECK(button);
249   END_TEST;
250 }
251
252 int UtcDaliPushButtonDownCastP(void)
253 {
254   ToolkitTestApplication application;
255
256   PushButton button = PushButton::New();
257
258   BaseHandle object(button);
259
260   PushButton button2 = PushButton::DownCast(object);
261   DALI_TEST_CHECK(button2);
262
263   PushButton button3 = DownCast<PushButton>(object);
264   DALI_TEST_CHECK(button3);
265   END_TEST;
266 }
267
268 int UtcDaliPushButtonDownCastN(void)
269 {
270   ToolkitTestApplication application;
271
272   BaseHandle unInitializedObject;
273
274   PushButton button1 = PushButton::DownCast(unInitializedObject);
275   DALI_TEST_CHECK(!button1);
276
277   PushButton button2 = DownCast<PushButton>(unInitializedObject);
278   DALI_TEST_CHECK(!button2);
279   END_TEST;
280 }
281
282 int UtcDaliPushButtonAutoRepeatingProperty(void)
283 {
284   ToolkitTestApplication application;
285   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
286
287   PushButton pushButton = PushButton::New();
288
289   pushButton.SetProperty(pushButton.GetPropertyIndex("autoRepeating"), true);
290   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION);
291
292   pushButton.SetProperty(pushButton.GetPropertyIndex("autoRepeating"), false);
293   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION);
294
295   pushButton.SetProperty(pushButton.GetPropertyIndex("autoRepeating"), true);
296   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION);
297
298   END_TEST;
299 }
300
301 int UtcDaliPushButtonSetAutoRepeating(void)
302 {
303   ToolkitTestApplication application;
304   tet_infoline("UtcDaliPushButtonSetAutoRepeating\n");
305   tet_infoline("Ensure setting AutoRepeating on a SELECTED Toggle button switches off Toggle\n");
306   PushButton pushButton = PushButton::New();
307
308   const bool INITIAL_TOGGLE_VALUE   = true;
309   const bool INITIAL_SELECTED_VALUE = true;
310
311   pushButton.SetProperty(Button::Property::TOGGLABLE, INITIAL_TOGGLE_VALUE);
312   pushButton.SetProperty(Button::Property::SELECTED, INITIAL_SELECTED_VALUE);
313
314   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::TOGGLABLE), INITIAL_TOGGLE_VALUE, TEST_LOCATION);
315   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), INITIAL_SELECTED_VALUE, TEST_LOCATION);
316
317   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
318
319   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::TOGGLABLE), !INITIAL_TOGGLE_VALUE, TEST_LOCATION);
320
321   END_TEST;
322 }
323
324 int UtcDaliPushButtonTogglableProperty(void)
325 {
326   ToolkitTestApplication application;
327   tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
328
329   PushButton pushButton = PushButton::New();
330
331   pushButton.SetProperty(pushButton.GetPropertyIndex("togglable"), true);
332   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION);
333
334   pushButton.SetProperty(pushButton.GetPropertyIndex("togglable"), false);
335   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION);
336
337   pushButton.SetProperty(pushButton.GetPropertyIndex("togglable"), true);
338   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION);
339
340   END_TEST;
341 }
342
343 int UtcDaliPushButtonAutoRepeatingPropertyAndTogglableButton(void)
344 {
345   ToolkitTestApplication application;
346   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
347
348   PushButton pushButton = PushButton::New();
349
350   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
351   pushButton.SetProperty(pushButton.GetPropertyIndex("togglable"), true);
352
353   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), true, TEST_LOCATION);
354   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), false, TEST_LOCATION);
355
356   pushButton.SetProperty(pushButton.GetPropertyIndex("togglable"), true);
357   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
358
359   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("autoRepeating")), true, TEST_LOCATION);
360   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("togglable")), false, TEST_LOCATION);
361   END_TEST;
362 }
363
364 int UtcDaliPushButtonSelectedProperty01(void)
365 {
366   ToolkitTestApplication application;
367   tet_infoline(" UtcDaliPushButtonSetGetSelected01");
368
369   PushButton pushButton = PushButton::New();
370
371   pushButton.SetProperty(pushButton.GetPropertyIndex("togglable"), true);
372
373   pushButton.StateChangedSignal().Connect(&PushButtonSelected);
374
375   gPushButtonSelectedState = false;
376   pushButton.SetProperty(Button::Property::SELECTED, true);
377
378   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), true, TEST_LOCATION);
379   DALI_TEST_CHECK(gPushButtonSelectedState);
380
381   pushButton.SetProperty(Button::Property::SELECTED, false);
382
383   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
384   DALI_TEST_CHECK(!gPushButtonSelectedState);
385
386   pushButton.SetProperty(Button::Property::SELECTED, true);
387
388   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), true, TEST_LOCATION);
389   DALI_TEST_CHECK(gPushButtonSelectedState);
390   END_TEST;
391 }
392
393 int UtcDaliPushButtonSelectedProperty02(void)
394 {
395   ToolkitTestApplication application;
396   tet_infoline(" UtcDaliPushButtonSetGetSelected02");
397
398   PushButton pushButton = PushButton::New();
399
400   pushButton.SetProperty(pushButton.GetPropertyIndex("togglable"), false);
401   pushButton.StateChangedSignal().Connect(&PushButtonSelected);
402
403   gPushButtonSelectedState = false;
404   pushButton.SetProperty(Button::Property::SELECTED, true);
405
406   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
407   DALI_TEST_CHECK(!gPushButtonSelectedState);
408
409   pushButton.SetProperty(Button::Property::SELECTED, false);
410
411   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
412   DALI_TEST_CHECK(!gPushButtonSelectedState);
413
414   pushButton.SetProperty(Button::Property::SELECTED, true);
415
416   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
417   DALI_TEST_CHECK(!gPushButtonSelectedState);
418   END_TEST;
419 }
420
421 int UtcDaliPushButtonAutorepeatingDelayPropertyValues01(void)
422 {
423   ToolkitTestApplication application;
424   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
425
426   PushButton pushButton = PushButton::New();
427
428   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
429
430   pushButton.SetProperty(Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f);
431
432   DALI_TEST_EQUALS(pushButton.GetProperty<float>(pushButton.GetPropertyIndex("initialAutoRepeatingDelay")), 1.f, TEST_LOCATION);
433
434   END_TEST;
435 }
436
437 int UtcDaliPushButtonAutorepeatingDelayPropertyValues02(void)
438 {
439   ToolkitTestApplication application;
440   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
441
442   PushButton pushButton = PushButton::New();
443
444   bool assert1(false);
445   bool assert2(false);
446
447   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
448
449   try
450   {
451     pushButton.SetProperty(Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f);
452   }
453   catch(Dali::DaliException& e)
454   {
455     DALI_TEST_PRINT_ASSERT(e);
456     DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
457     assert1 = true;
458   }
459
460   try
461   {
462     pushButton.SetProperty(Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f);
463   }
464   catch(Dali::DaliException& e)
465   {
466     DALI_TEST_PRINT_ASSERT(e);
467     DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
468     assert2 = true;
469   }
470
471   DALI_TEST_CHECK(assert1 && assert2);
472   END_TEST;
473 }
474
475 int UtcDaliPushButtonLabelProperty(void)
476 {
477   ToolkitTestApplication application;
478   tet_infoline(" UtcDaliPushButtonSetLabelText");
479
480   const std::string STR("Hola!");
481
482   PushButton pushButton = PushButton::New();
483
484   application.SendNotification();
485   application.Render();
486
487   pushButton.SetProperty(Toolkit::Button::Property::LABEL,
488                          Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f));
489
490   pushButton.SetProperty(Toolkit::Button::Property::LABEL, STR);
491
492   DALI_TEST_EQUALS(GetButtonText(pushButton), STR, TEST_LOCATION);
493
494   END_TEST;
495 }
496
497 int UtcDaliPushButtonPressed(void)
498 {
499   ToolkitTestApplication application;
500   tet_infoline(" UtcDaliPushButtonPressed");
501
502   PushButton pushButton = PushButton::New();
503   pushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
504   pushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
505   pushButton.SetProperty(Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS);
506   pushButton.SetProperty(Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS);
507
508   application.GetScene().Add(pushButton);
509
510   application.SendNotification();
511   application.Render();
512
513   gPushButtonPressed = false;
514
515   // connect to its touch signal
516   pushButton.PressedSignal().Connect(&PushButtonPressed);
517
518   Dali::Integration::TouchEvent eventDown;
519   eventDown.AddPoint(GetPointDownInside());
520
521   // flush the queue and render once
522   application.SendNotification();
523   application.Render();
524   application.ProcessEvent(eventDown);
525
526   DALI_TEST_CHECK(gPushButtonPressed);
527   END_TEST;
528 }
529
530 int UtcDaliPushButtonReleased(void)
531 {
532   ToolkitTestApplication application;
533   tet_infoline(" UtcDaliPushButtonReleased");
534
535   PushButton pushButton = PushButton::New();
536   pushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
537   pushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
538   pushButton.SetProperty(Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS);
539   pushButton.SetProperty(Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS);
540
541   application.GetScene().Add(pushButton);
542
543   application.SendNotification();
544   application.Render();
545
546   // connect to its touch signal
547   pushButton.ReleasedSignal().Connect(&PushButtonReleased);
548
549   Dali::Integration::TouchEvent event;
550
551   // Test1. Touch point down and up inside the button.
552
553   gPushButtonReleased = false;
554   event               = Dali::Integration::TouchEvent();
555   event.AddPoint(GetPointDownInside());
556   application.ProcessEvent(event);
557
558   event = Dali::Integration::TouchEvent();
559   event.AddPoint(GetPointUpInside());
560   application.ProcessEvent(event);
561
562   DALI_TEST_CHECK(gPushButtonReleased);
563
564   // Test2. Touch point down and up outside the button.
565
566   gPushButtonReleased = false;
567   event               = Dali::Integration::TouchEvent();
568   event.AddPoint(GetPointDownOutside());
569   application.ProcessEvent(event);
570
571   event = Dali::Integration::TouchEvent();
572   event.AddPoint(GetPointUpOutside());
573   application.ProcessEvent(event);
574
575   DALI_TEST_CHECK(!gPushButtonReleased);
576
577   // Test3. Touch point down inside and up outside the button.
578
579   gPushButtonReleased = false;
580   event               = Dali::Integration::TouchEvent();
581   event.AddPoint(GetPointDownInside());
582   application.ProcessEvent(event);
583
584   event = Dali::Integration::TouchEvent();
585   event.AddPoint(GetPointLeave());
586   application.ProcessEvent(event);
587
588   event = Dali::Integration::TouchEvent();
589   event.AddPoint(GetPointUpOutside());
590   application.ProcessEvent(event);
591
592   DALI_TEST_CHECK(gPushButtonReleased);
593
594   // Test4. Touch point down outside and up inside the button.
595
596   gPushButtonReleased = false;
597   event               = Dali::Integration::TouchEvent();
598   event.AddPoint(GetPointDownOutside());
599   application.ProcessEvent(event);
600
601   event = Dali::Integration::TouchEvent();
602   event.AddPoint(GetPointEnter());
603   application.ProcessEvent(event);
604
605   event = Dali::Integration::TouchEvent();
606   event.AddPoint(GetPointUpInside());
607   application.ProcessEvent(event);
608
609   DALI_TEST_CHECK(!gPushButtonReleased);
610   END_TEST;
611 }
612
613 int UtcDaliPushButtonSelected(void)
614 {
615   ToolkitTestApplication application;
616   tet_infoline(" UtcDaliPushButtonSelected");
617
618   PushButton pushButton = PushButton::New();
619   pushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
620   pushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
621   pushButton.SetProperty(Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS);
622   pushButton.SetProperty(Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS);
623
624   application.GetScene().Add(pushButton);
625
626   application.SendNotification();
627   application.Render();
628
629   // connect to its touch signal
630   pushButton.StateChangedSignal().Connect(&PushButtonSelected);
631
632   Dali::Integration::TouchEvent event;
633
634   // Test1. No togglable button.
635
636   gPushButtonSelectedState = false;
637   event                    = Dali::Integration::TouchEvent();
638   event.AddPoint(GetPointDownInside());
639   application.ProcessEvent(event);
640
641   event = Dali::Integration::TouchEvent();
642   event.AddPoint(GetPointUpInside());
643   application.ProcessEvent(event);
644
645   DALI_TEST_CHECK(!gPushButtonSelectedState);
646
647   // Set togglable property.
648   pushButton.SetProperty(Button::Property::TOGGLABLE, true);
649
650   // Test2. Touch point down and up inside the button twice.
651   gPushButtonSelectedState = false;
652   event                    = Dali::Integration::TouchEvent();
653   event.AddPoint(GetPointDownInside());
654   application.ProcessEvent(event);
655
656   event = Dali::Integration::TouchEvent();
657   event.AddPoint(GetPointUpInside());
658   application.ProcessEvent(event);
659
660   DALI_TEST_CHECK(gPushButtonSelectedState);
661
662   event = Dali::Integration::TouchEvent();
663   event.AddPoint(GetPointDownInside());
664   application.ProcessEvent(event);
665
666   event = Dali::Integration::TouchEvent();
667   event.AddPoint(GetPointUpInside());
668   application.ProcessEvent(event);
669
670   DALI_TEST_CHECK(!gPushButtonSelectedState);
671
672   // Test3. Touch point down and up outside the button.
673
674   gPushButtonSelectedState = false;
675   event                    = Dali::Integration::TouchEvent();
676   event.AddPoint(GetPointDownOutside());
677   application.ProcessEvent(event);
678
679   event = Dali::Integration::TouchEvent();
680   event.AddPoint(GetPointUpOutside());
681   application.ProcessEvent(event);
682
683   DALI_TEST_CHECK(!gPushButtonSelectedState);
684
685   // Test4. Touch point down inside and up outside the button.
686   //        State changes on Button down
687   gPushButtonSelectedState = false;
688   event                    = Dali::Integration::TouchEvent();
689   event.AddPoint(GetPointDownInside());
690   application.ProcessEvent(event);
691
692   event = Dali::Integration::TouchEvent();
693   event.AddPoint(GetPointLeave());
694   application.ProcessEvent(event);
695
696   event = Dali::Integration::TouchEvent();
697   event.AddPoint(GetPointUpOutside());
698   application.ProcessEvent(event);
699
700   DALI_TEST_CHECK(gPushButtonSelectedState);
701
702   // Test5. Touch point down outside and up inside the button.
703   // Start in unselected state
704   pushButton.SetProperty(Button::Property::SELECTED, false);
705
706   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("selected")), false, TEST_LOCATION);
707
708   gPushButtonSelectedState = false;
709   event                    = Dali::Integration::TouchEvent();
710   event.AddPoint(GetPointDownOutside());
711   application.ProcessEvent(event);
712
713   event = Dali::Integration::TouchEvent();
714   event.AddPoint(GetPointEnter());
715   application.ProcessEvent(event);
716
717   event = Dali::Integration::TouchEvent();
718   event.AddPoint(GetPointUpInside());
719   application.ProcessEvent(event);
720
721   DALI_TEST_CHECK(!gPushButtonSelectedState);
722   END_TEST;
723 }
724
725 int UtcDaliPushButtonPropertySetLabelPadding(void)
726 {
727   ToolkitTestApplication application;
728   tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
729
730   PushButton pushButton = PushButton::New();
731   pushButton.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, Vector4(1.0f, 1.0f, 1.0f, 1.0f));
732   DALI_TEST_EQUALS(pushButton.GetProperty<Vector4>(Toolkit::PushButton::Property::LABEL_PADDING), Vector4(1.0f, 1.0f, 1.0f, 1.0f), Math::MACHINE_EPSILON_1000, TEST_LOCATION);
733
734   pushButton.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, Vector4(10.0f, 10.0f, 10.0f, 10.0f));
735   DALI_TEST_EQUALS(pushButton.GetProperty<Vector4>(Toolkit::PushButton::Property::LABEL_PADDING), Vector4(10.0f, 10.0f, 10.0f, 10.0f), Math::MACHINE_EPSILON_1000, TEST_LOCATION);
736
737   END_TEST;
738 }
739
740 int UtcDaliPushButtonPropertySetIconPadding(void)
741 {
742   ToolkitTestApplication application;
743   tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
744
745   PushButton pushButton = PushButton::New();
746   pushButton.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, Vector4(1.0f, 1.0f, 1.0f, 1.0f));
747   DALI_TEST_EQUALS(pushButton.GetProperty<Vector4>(Toolkit::PushButton::Property::ICON_PADDING), Vector4(1.0f, 1.0f, 1.0f, 1.0f), Math::MACHINE_EPSILON_1000, TEST_LOCATION);
748
749   pushButton.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, Vector4(10.0f, 10.0f, 10.0f, 10.0f));
750   DALI_TEST_EQUALS(pushButton.GetProperty<Vector4>(Toolkit::PushButton::Property::ICON_PADDING), Vector4(10.0f, 10.0f, 10.0f, 10.0f), Math::MACHINE_EPSILON_1000, TEST_LOCATION);
751
752   END_TEST;
753 }
754
755 int UtcDaliPushButtonPaddingLayout(void)
756 {
757   ToolkitTestApplication application;
758   tet_infoline(" UtcDaliPushButtonPaddingLayout");
759
760   // This test creates padding for an icon and a label.
761   // The icon and label are each enabled and disabled to confirm the correct padding is used.
762   PushButton pushButton = PushButton::New();
763
764   const Vector4 TEST_ICON_PADDING(20.0f, 20.0f, 20.0f, 20.0f);
765   const Vector4 TEST_LABEL_PADDING(10.0f, 10.0f, 10.0f, 10.0f);
766
767   // Get actual size of test image
768   ImageDimensions testImageSize = Dali::GetClosestImageSize(TEST_IMAGE_ONE);
769   const Vector2   TEST_IMAGE_SIZE(testImageSize.GetWidth(), testImageSize.GetHeight());
770
771   pushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
772   pushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
773   pushButton.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
774   pushButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
775
776   application.GetScene().Add(pushButton);
777
778   application.SendNotification();
779   application.Render();
780
781   // First test the size is zero.
782   // No padding should be added as there is no label or icon.
783   Vector2 size(Vector2::ZERO);
784   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
785   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
786   tet_printf("Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height);
787
788   DALI_TEST_EQUALS(size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
789
790   // Check label only padding
791   pushButton.SetProperty(Toolkit::Button::Property::LABEL, "Label");
792
793   application.SendNotification();
794   application.Render();
795
796   Vector2 sizeWithLabelWithoutPadding(Vector2::ZERO);
797   sizeWithLabelWithoutPadding.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
798   sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
799
800   tet_printf("Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height);
801
802   // Add label padding to label
803   pushButton.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING);
804   application.SendNotification();
805   application.Render();
806
807   Vector2 sizeLabelAndPadding(Vector2::ZERO);
808   sizeLabelAndPadding.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
809   sizeLabelAndPadding.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
810   tet_printf("Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height);
811
812   // If control size has increased beyond size of just label then padding has been applied
813   DALI_TEST_GREATER(sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width + TEST_LABEL_PADDING.x, TEST_LOCATION);
814   DALI_TEST_GREATER(sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height + TEST_LABEL_PADDING.w, TEST_LOCATION);
815
816   // Re-initialise the button so we can setup icon-only padding.
817   pushButton.Unparent();
818   pushButton = PushButton::New();
819
820   pushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
821   pushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
822   pushButton.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
823   pushButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
824
825   application.GetScene().Add(pushButton);
826
827   pushButton.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BEGIN");
828   pushButton.SetProperty(Toolkit::Button::Property::UNSELECTED_VISUAL, TEST_IMAGE_ONE);
829   pushButton.SetProperty(Toolkit::Button::Property::SELECTED_VISUAL, TEST_IMAGE_ONE);
830
831   application.SendNotification();
832   application.Render();
833
834   // Size of button with just icon
835   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
836   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
837   tet_printf("Button RelayoutSize with icon(%f,%f)\n", size.width, size.height);
838
839   pushButton.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING);
840
841   application.SendNotification();
842   application.Render();
843   DALI_TEST_EQUALS(size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
844
845   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
846   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
847   tet_printf("Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height);
848   const Vector2 expectedIconAndPaddingSize(TEST_ICON_PADDING.x + TEST_ICON_PADDING.y + TEST_IMAGE_SIZE.width, TEST_ICON_PADDING.w + TEST_ICON_PADDING.z + TEST_IMAGE_SIZE.height);
849   DALI_TEST_EQUALS(size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
850
851   // Now test padding for both label and icon simultaneously.
852   pushButton.SetProperty(Toolkit::Button::Property::LABEL, "Label");
853
854   application.SendNotification();
855   application.Render();
856
857   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
858   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
859   tet_printf("Button RelayoutSize after label added(%f,%f)\n", size.width, size.height);
860
861   pushButton.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING);
862
863   application.SendNotification();
864   application.Render();
865
866   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
867   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
868   tet_printf("Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height);
869
870   DALI_TEST_EQUALS(size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION);
871   // Test height of control is same as icon and padding, as Text is smaller than icon
872   DALI_TEST_EQUALS(size.height, expectedIconAndPaddingSize.height, TEST_LOCATION);
873
874   END_TEST;
875 }
876
877 int UtcDaliPushButtonAlignmentLayout(void)
878 {
879   ToolkitTestApplication application;
880   tet_infoline(" UtcDaliPushButtonAlignmentLayout");
881
882   /*
883    * This test checks different alignments for the icon against the label.
884    * The icon is then moved around the label in each of it's alignments.
885    * The final relayed out size is checked to confirm the layout has been done correctly.
886    *
887    * There is an Icon which has 0 width and height, but with 75 padding on all sides.
888    *  - Therefore total width and height are both 150.
889    *
890    * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
891    *  - Therefore total width and height are 60+x and 60+y respectively.
892    *    Where x & y are the width and height of the text.
893    *
894    * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
895    * So We use the padding to help us determine the orientation is correct for each alignment.
896    *
897    * |<- 150 ->|         |<-- 60+x -->|
898    *
899    * +---------+   -
900    * |         |   ^     +------------+   -
901    * |         |   |     |            |   ^
902    * |  Icon   |  150    |   Label    |  60+y
903    * |         |   |     |            |   v
904    * |         |   v     +------------+   -
905    * +---------+   -
906    */
907
908   const Vector4 TEST_ICON_PADDING(70.0f, 70.0f, 70.0f, 70.0f);
909   const Vector4 TEST_LABEL_PADDING(30.0f, 30.0f, 30.0f, 30.0f);
910
911   // Get actual size of test image
912   ImageDimensions testImageSize = Dali::GetClosestImageSize(TEST_IMAGE_ONE);
913   const Vector2   TEST_IMAGE_SIZE(testImageSize.GetWidth(), testImageSize.GetHeight());
914
915   PushButton pushButton = PushButton::New();
916
917   pushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
918   pushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
919   pushButton.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
920   pushButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
921
922   application.GetScene().Add(pushButton);
923
924   // Add a label and get size of control
925   pushButton.SetProperty(Toolkit::Button::Property::LABEL, "Label");
926   application.SendNotification();
927   application.Render();
928
929   // First get the size of control with just label
930   Vector2 justLabelSize(Vector2::ZERO);
931   justLabelSize.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
932   justLabelSize.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
933   tet_printf("Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height);
934
935   pushButton.SetProperty(Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING);
936   application.SendNotification();
937   application.Render();
938
939   // Size of Label and Padding
940   Vector2 expectedLabelAndPaddingSize(Vector2::ZERO);
941   expectedLabelAndPaddingSize.width  = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
942   expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
943
944   Vector2 labelAndPaddingSize(Vector2::ZERO);
945   labelAndPaddingSize.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
946   labelAndPaddingSize.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
947
948   DALI_TEST_EQUALS(labelAndPaddingSize, expectedLabelAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
949
950   const Vector2 testImageWithPaddingSize = Vector2((TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y),
951                                                    (TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z));
952
953   // Add Icon and set its alignment
954   pushButton.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BEGIN");
955   pushButton.SetProperty(Toolkit::Button::Property::UNSELECTED_VISUAL, TEST_IMAGE_ONE);
956   pushButton.SetProperty(Toolkit::Button::Property::SELECTED_VISUAL, TEST_IMAGE_ONE);
957   pushButton.SetProperty(Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING);
958
959   application.SendNotification();
960   application.Render();
961
962   Vector2 size(Vector2::ZERO);
963   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
964   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
965
966   /*
967    * Test Icon right alignment.
968    * Height grows to largest of Icon or Label (+ padding).
969    * Normally this will be Icons height, except with very large font sizes.
970    *
971    *  +------------+---------+
972    *  |............+         |
973    *  |            |         |
974    *  |   Label    |  Icon   |
975    *  |            |         |
976    *  |............+         |
977    *  +------------+---------+
978    */
979   DALI_TEST_EQUALS(size.width, (testImageWithPaddingSize.width + labelAndPaddingSize.width), TEST_LOCATION);
980   DALI_TEST_EQUALS(size.height, (std::max(testImageWithPaddingSize.height, labelAndPaddingSize.height)), Math::MACHINE_EPSILON_1000, TEST_LOCATION);
981
982   // Now test left alignment matches right for size.
983   pushButton.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END");
984
985   application.SendNotification();
986   application.Render();
987
988   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
989   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
990
991   /*
992    * Test Icon left alignment.
993    * Height grows to largest of Icon or Label (+ padding).
994    * Normally this will be Icons height, except with very large font sizes.
995    *
996    *  +---------+------------+
997    *  |         +............|
998    *  |         |            |
999    *  |  Icon   |   Label    |
1000    *  |         |            |
1001    *  |         +............|
1002    *  +---------+------------+
1003    */
1004   DALI_TEST_EQUALS(size.width, (testImageWithPaddingSize.width + labelAndPaddingSize.width), TEST_LOCATION);
1005   DALI_TEST_EQUALS(size.height, (std::max(testImageWithPaddingSize.height, labelAndPaddingSize.height)), Math::MACHINE_EPSILON_1000, TEST_LOCATION);
1006
1007   tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
1008   /*
1009    *
1010    *  +---------+
1011    *  |         |
1012    *  |         |
1013    *  |  Icon   |
1014    *  |         |
1015    *  |         |
1016    *  +---------+
1017    *  |         |
1018    *  |  Label  |
1019    *  |         |
1020    *  +---------+
1021    *
1022    */
1023
1024   tet_infoline("SetProperty on LABEL_RELATIVE_ALIGNMENT should relayout the Button");
1025   pushButton.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM");
1026
1027   application.SendNotification();
1028   application.Render();
1029
1030   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
1031   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
1032
1033   tet_printf("Natural width (%f)\n", pushButton.GetNaturalSize().width);
1034   tet_printf("Natural height (%f)\n", pushButton.GetNaturalSize().height);
1035
1036   tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height);
1037   tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height);
1038
1039   DALI_TEST_EQUALS(size.width, (std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width)), TEST_LOCATION);
1040
1041   DALI_TEST_EQUALS(size.height, (testImageWithPaddingSize.height + labelAndPaddingSize.height), TEST_LOCATION);
1042
1043   /*
1044    * Test Icon bottom alignment.
1045    * Width grows to largest of Icon or Label (+ padding).
1046    *
1047    *  +---------+
1048    *  |         |
1049    *  |  Label  |
1050    *  |         |
1051    *  +---------+
1052    *  |         |
1053    *  |         |
1054    *  |  Icon   |
1055    *  |         |
1056    *  |         |
1057    *  +---------+
1058    */
1059   tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1060   pushButton.SetProperty(Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "TOP");
1061
1062   application.SendNotification();
1063   application.Render();
1064
1065   size.width  = pushButton.GetRelayoutSize(Dimension::WIDTH);
1066   size.height = pushButton.GetRelayoutSize(Dimension::HEIGHT);
1067
1068   DALI_TEST_EQUALS(size.width, (std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width)), TEST_LOCATION);
1069   DALI_TEST_EQUALS(size.height, (testImageWithPaddingSize.height + labelAndPaddingSize.height), TEST_LOCATION);
1070
1071   END_TEST;
1072 }
1073
1074 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1075 {
1076   tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1077   ToolkitTestApplication application;
1078
1079   PushButton pushButton = PushButton::New();
1080   pushButton.SetProperty(Actor::Property::SIZE, Vector2(BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS));
1081
1082   application.GetScene().Add(pushButton);
1083
1084   Property::Map propertyMap;
1085   propertyMap.Insert(Visual::Property::TYPE, Visual::COLOR);
1086   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1087
1088   pushButton.SetProperty(Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap);
1089
1090   tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1091
1092   application.SendNotification();
1093   application.Render(0);
1094
1095   unsigned int rendererCount = pushButton.GetRendererCount();
1096   tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount);
1097
1098   DALI_TEST_EQUALS(pushButton.GetRendererCount(), 1, TEST_LOCATION);
1099
1100   tet_printf("Remove button from stage\n");
1101
1102   application.GetScene().Remove(pushButton);
1103
1104   rendererCount = pushButton.GetRendererCount();
1105   tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount);
1106
1107   DALI_TEST_EQUALS(pushButton.GetRendererCount(), 0, TEST_LOCATION);
1108
1109   tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount);
1110
1111   Property::Map propertyMap2;
1112   propertyMap2.Insert(Visual::Property::TYPE, Visual::COLOR);
1113   propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1114   pushButton.SetProperty(Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap2);
1115
1116   tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1117
1118   application.GetScene().Add(pushButton);
1119
1120   tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_VISUAL the renderer count is(%d)\n", pushButton.GetRendererCount());
1121
1122   DALI_TEST_EQUALS(pushButton.GetRendererCount(), 2, TEST_LOCATION);
1123
1124   END_TEST;
1125 }
1126
1127 int UtcDaliPushButtonSetSelectedVisualN(void)
1128 {
1129   tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1130
1131   ToolkitTestApplication application;
1132
1133   PushButton pushButton = PushButton::New();
1134
1135   pushButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1136   pushButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1137   pushButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
1138
1139   application.GetScene().Add(pushButton);
1140   application.SendNotification();
1141   application.Render(0);
1142
1143   unsigned int preRendererCount = pushButton.GetRendererCount();
1144   tet_printf("RendererCount prior to adding visual(%d)\n", preRendererCount);
1145   DALI_TEST_EQUALS(preRendererCount, 0, TEST_LOCATION);
1146
1147   application.GetScene().Remove(pushButton);
1148   application.SendNotification();
1149   application.Render(0);
1150
1151   Property::Map colorMap;
1152   const int     BROKEN_VISUAL_TYPE = 999999999;
1153
1154   colorMap.Insert(Visual::Property::TYPE, BROKEN_VISUAL_TYPE);
1155   colorMap.Insert(BorderVisual::Property::COLOR, Color::BLUE);
1156   colorMap.Insert(BorderVisual::Property::SIZE, 5.f);
1157   pushButton.SetProperty(Toolkit::Button::Property::UNSELECTED_VISUAL, colorMap);
1158
1159   application.GetScene().Add(pushButton);
1160   application.SendNotification();
1161   application.Render(0);
1162
1163   unsigned int postRendererCount = pushButton.GetRendererCount();
1164   tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1165   DALI_TEST_EQUALS(postRendererCount, 0, TEST_LOCATION);
1166
1167   END_TEST;
1168 }
1169
1170 int UtcDaliPushButtonToggleSignalP(void)
1171 {
1172   ToolkitTestApplication application;
1173   tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1174
1175   PushButton button = PushButton::New();
1176   button.SetProperty(Button::Property::TOGGLABLE, true);
1177
1178   SetupButtonForTestTouchEvents(application, button, true);
1179
1180   application.GetScene().Add(button);
1181
1182   application.SendNotification();
1183   application.Render();
1184
1185   // connect to its signal
1186   button.ClickedSignal().Connect(&PushButtonClicked);
1187   gPushButtonClicked = false;
1188
1189   tet_infoline(" Touch down and up within button");
1190   Dali::Integration::TouchEvent event;
1191   event = Dali::Integration::TouchEvent();
1192   event.AddPoint(GetPointDownInside());
1193   application.ProcessEvent(event);
1194
1195   event = Dali::Integration::TouchEvent();
1196   event.AddPoint(GetPointUpInside());
1197   application.ProcessEvent(event);
1198
1199   DALI_TEST_EQUALS(gPushButtonClicked, true, TEST_LOCATION);
1200
1201   END_TEST;
1202 }
1203
1204 // Deprecated API Tests
1205
1206 int UtcDaliPushButtonSetGetAutoRepeating(void)
1207 {
1208   ToolkitTestApplication application;
1209   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
1210
1211   PushButton pushButton = PushButton::New();
1212
1213   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
1214
1215   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::AUTO_REPEATING), true, TEST_LOCATION);
1216
1217   pushButton.SetProperty(Button::Property::AUTO_REPEATING, false);
1218
1219   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::AUTO_REPEATING), false, TEST_LOCATION);
1220
1221   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
1222
1223   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::AUTO_REPEATING), true, TEST_LOCATION);
1224   END_TEST;
1225 }
1226
1227 int UtcDaliPushButtonSetGetTogglableButton(void)
1228 {
1229   ToolkitTestApplication application;
1230   tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
1231
1232   PushButton pushButton = PushButton::New();
1233
1234   pushButton.SetProperty(Button::Property::TOGGLABLE, true);
1235
1236   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
1237
1238   pushButton.SetProperty(Button::Property::TOGGLABLE, false);
1239
1240   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
1241
1242   pushButton.SetProperty(Button::Property::TOGGLABLE, true);
1243
1244   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
1245   END_TEST;
1246 }
1247
1248 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
1249 {
1250   ToolkitTestApplication application;
1251   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
1252
1253   PushButton pushButton = PushButton::New();
1254
1255   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
1256   pushButton.SetProperty(Button::Property::TOGGLABLE, true);
1257
1258   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::TOGGLABLE), true, TEST_LOCATION);
1259   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::AUTO_REPEATING), false, TEST_LOCATION);
1260
1261   pushButton.SetProperty(Button::Property::TOGGLABLE, true);
1262   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
1263
1264   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::AUTO_REPEATING), true, TEST_LOCATION);
1265   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::TOGGLABLE), false, TEST_LOCATION);
1266
1267   END_TEST;
1268 }
1269
1270 int UtcDaliPushButtonSetGetSelected01(void)
1271 {
1272   ToolkitTestApplication application;
1273   tet_infoline(" UtcDaliPushButtonSetGetSelected01");
1274
1275   PushButton pushButton = PushButton::New();
1276
1277   pushButton.SetProperty(Button::Property::TOGGLABLE, true);
1278   pushButton.StateChangedSignal().Connect(&PushButtonSelected);
1279
1280   gPushButtonSelectedState = false;
1281   pushButton.SetProperty(Button::Property::SELECTED, true);
1282
1283   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), true, TEST_LOCATION);
1284   DALI_TEST_CHECK(gPushButtonSelectedState);
1285
1286   pushButton.SetProperty(Button::Property::SELECTED, false);
1287
1288   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
1289   DALI_TEST_CHECK(!gPushButtonSelectedState);
1290
1291   pushButton.SetProperty(Button::Property::SELECTED, true);
1292
1293   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), true, TEST_LOCATION);
1294   DALI_TEST_CHECK(gPushButtonSelectedState);
1295   END_TEST;
1296 }
1297
1298 int UtcDaliPushButtonSetGetSelected02(void)
1299 {
1300   ToolkitTestApplication application;
1301   tet_infoline(" UtcDaliPushButtonSetGetSelected02");
1302
1303   PushButton pushButton = PushButton::New();
1304
1305   tet_infoline(" Set Toggle feature off");
1306   pushButton.SetProperty(Button::Property::TOGGLABLE, false);
1307   pushButton.StateChangedSignal().Connect(&PushButtonSelected);
1308
1309   gPushButtonSelectedState = false;
1310   tet_infoline(" Try to set to selected, expecting failure as not a toggle button");
1311   pushButton.SetProperty(Button::Property::SELECTED, true);
1312
1313   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
1314   DALI_TEST_CHECK(!gPushButtonSelectedState);
1315
1316   pushButton.SetProperty(Button::Property::SELECTED, false);
1317
1318   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
1319   DALI_TEST_CHECK(!gPushButtonSelectedState);
1320
1321   pushButton.SetProperty(Button::Property::SELECTED, true);
1322
1323   DALI_TEST_EQUALS(pushButton.GetProperty<bool>(Button::Property::SELECTED), false, TEST_LOCATION);
1324   DALI_TEST_CHECK(!gPushButtonSelectedState);
1325
1326   END_TEST;
1327 }
1328
1329 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
1330 {
1331   ToolkitTestApplication application;
1332   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
1333
1334   PushButton pushButton = PushButton::New();
1335
1336   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
1337
1338   pushButton.SetProperty(Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f);
1339   DALI_TEST_EQUALS(pushButton.GetProperty<float>(Button::Property::INITIAL_AUTO_REPEATING_DELAY), 1.f, TEST_LOCATION);
1340
1341   pushButton.SetProperty(Button::Property::NEXT_AUTO_REPEATING_DELAY, 1.f);
1342
1343   DALI_TEST_EQUALS(pushButton.GetProperty<float>(Button::Property::NEXT_AUTO_REPEATING_DELAY), 1.f, TEST_LOCATION);
1344   END_TEST;
1345 }
1346
1347 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
1348 {
1349   ToolkitTestApplication application;
1350   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
1351
1352   PushButton pushButton = PushButton::New();
1353
1354   bool assert1(false);
1355   bool assert2(false);
1356
1357   pushButton.SetProperty(Button::Property::AUTO_REPEATING, true);
1358
1359   try
1360   {
1361     pushButton.SetProperty(Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f);
1362   }
1363   catch(Dali::DaliException& e)
1364   {
1365     DALI_TEST_PRINT_ASSERT(e);
1366     DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
1367     assert1 = true;
1368   }
1369
1370   try
1371   {
1372     pushButton.SetProperty(Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f);
1373   }
1374   catch(Dali::DaliException& e)
1375   {
1376     DALI_TEST_PRINT_ASSERT(e);
1377     DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
1378     assert2 = true;
1379   }
1380
1381   DALI_TEST_CHECK(assert1 && assert2);
1382   END_TEST;
1383 }
1384
1385 int UtcDaliPushButtonSetLabelText(void)
1386 {
1387   ToolkitTestApplication application;
1388   tet_infoline(" UtcDaliPushButtonSetLabelText");
1389
1390   const std::string STR("Hola!");
1391
1392   PushButton pushButton = PushButton::New();
1393
1394   pushButton.SetProperty(Toolkit::Button::Property::LABEL,
1395                          Property::Map().Add(Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT).Add(Toolkit::TextVisual::Property::POINT_SIZE, 15.0f));
1396
1397   application.SendNotification();
1398   application.Render();
1399
1400   pushButton.SetProperty(Button::Property::LABEL, STR);
1401
1402   DALI_TEST_EQUALS(GetButtonText(pushButton), STR, TEST_LOCATION);
1403
1404   END_TEST;
1405 }