support string_view in DALI_TEST_EQUALS
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-PushButton.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
25 #include <dali.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali-toolkit/dali-toolkit.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 )
489                                            .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
490                           );
491
492
493   pushButton.SetProperty( Toolkit::Button::Property::LABEL, STR );
494
495   DALI_TEST_EQUALS( GetButtonText( pushButton ), STR, TEST_LOCATION );
496
497   END_TEST;
498 }
499
500 int UtcDaliPushButtonPressed(void)
501 {
502   ToolkitTestApplication application;
503   tet_infoline(" UtcDaliPushButtonPressed");
504
505   PushButton pushButton = PushButton::New();
506   pushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
507   pushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
508   pushButton.SetProperty( Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
509   pushButton.SetProperty( Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
510
511   application.GetScene().Add( pushButton );
512
513   application.SendNotification();
514   application.Render();
515
516   gPushButtonPressed = false;
517
518   // connect to its touch signal
519   pushButton.PressedSignal().Connect( &PushButtonPressed );
520
521   Dali::Integration::TouchEvent eventDown;
522   eventDown.AddPoint( GetPointDownInside() );
523
524   // flush the queue and render once
525   application.SendNotification();
526   application.Render();
527   application.ProcessEvent( eventDown );
528
529   DALI_TEST_CHECK( gPushButtonPressed );
530   END_TEST;
531 }
532
533 int UtcDaliPushButtonReleased(void)
534 {
535   ToolkitTestApplication application;
536   tet_infoline(" UtcDaliPushButtonReleased");
537
538   PushButton pushButton = PushButton::New();
539   pushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
540   pushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
541   pushButton.SetProperty( Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
542   pushButton.SetProperty( Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
543
544   application.GetScene().Add( pushButton );
545
546   application.SendNotification();
547   application.Render();
548
549   // connect to its touch signal
550   pushButton.ReleasedSignal().Connect( &PushButtonReleased );
551
552   Dali::Integration::TouchEvent event;
553
554   // Test1. Touch point down and up inside the button.
555
556   gPushButtonReleased = false;
557   event = Dali::Integration::TouchEvent();
558   event.AddPoint( GetPointDownInside() );
559   application.ProcessEvent( event );
560
561   event = Dali::Integration::TouchEvent();
562   event.AddPoint( GetPointUpInside() );
563   application.ProcessEvent( event );
564
565   DALI_TEST_CHECK( gPushButtonReleased );
566
567   // Test2. Touch point down and up outside the button.
568
569   gPushButtonReleased = false;
570   event = Dali::Integration::TouchEvent();
571   event.AddPoint( GetPointDownOutside() );
572   application.ProcessEvent( event );
573
574   event = Dali::Integration::TouchEvent();
575   event.AddPoint( GetPointUpOutside() );
576   application.ProcessEvent( event );
577
578   DALI_TEST_CHECK( !gPushButtonReleased );
579
580   // Test3. Touch point down inside and up outside the button.
581
582   gPushButtonReleased = false;
583   event = Dali::Integration::TouchEvent();
584   event.AddPoint( GetPointDownInside() );
585   application.ProcessEvent( event );
586
587   event = Dali::Integration::TouchEvent();
588   event.AddPoint( GetPointLeave() );
589   application.ProcessEvent( event );
590
591   event = Dali::Integration::TouchEvent();
592   event.AddPoint( GetPointUpOutside() );
593   application.ProcessEvent( event );
594
595   DALI_TEST_CHECK( gPushButtonReleased );
596
597   // Test4. Touch point down outside and up inside the button.
598
599   gPushButtonReleased = false;
600   event = Dali::Integration::TouchEvent();
601   event.AddPoint( GetPointDownOutside() );
602   application.ProcessEvent( event );
603
604   event = Dali::Integration::TouchEvent();
605   event.AddPoint( GetPointEnter() );
606   application.ProcessEvent( event );
607
608   event = Dali::Integration::TouchEvent();
609   event.AddPoint( GetPointUpInside() );
610   application.ProcessEvent( event );
611
612   DALI_TEST_CHECK( !gPushButtonReleased );
613   END_TEST;
614 }
615
616 int UtcDaliPushButtonSelected(void)
617 {
618   ToolkitTestApplication application;
619   tet_infoline(" UtcDaliPushButtonSelected");
620
621   PushButton pushButton = PushButton::New();
622   pushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
623   pushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
624   pushButton.SetProperty( Actor::Property::POSITION, BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
625   pushButton.SetProperty( Actor::Property::SIZE, BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
626
627   application.GetScene().Add( pushButton );
628
629   application.SendNotification();
630   application.Render();
631
632   // connect to its touch signal
633   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
634
635   Dali::Integration::TouchEvent event;
636
637   // Test1. No togglable button.
638
639   gPushButtonSelectedState = false;
640   event = Dali::Integration::TouchEvent();
641   event.AddPoint( GetPointDownInside() );
642   application.ProcessEvent( event );
643
644   event = Dali::Integration::TouchEvent();
645   event.AddPoint( GetPointUpInside() );
646   application.ProcessEvent( event );
647
648   DALI_TEST_CHECK( !gPushButtonSelectedState );
649
650   // Set togglable property.
651   pushButton.SetProperty( Button::Property::TOGGLABLE, true );
652
653   // Test2. Touch point down and up inside the button twice.
654   gPushButtonSelectedState = false;
655   event = Dali::Integration::TouchEvent();
656   event.AddPoint( GetPointDownInside() );
657   application.ProcessEvent( event );
658
659   event = Dali::Integration::TouchEvent();
660   event.AddPoint( GetPointUpInside() );
661   application.ProcessEvent( event );
662
663   DALI_TEST_CHECK( gPushButtonSelectedState );
664
665   event = Dali::Integration::TouchEvent();
666   event.AddPoint( GetPointDownInside() );
667   application.ProcessEvent( event );
668
669   event = Dali::Integration::TouchEvent();
670   event.AddPoint( GetPointUpInside() );
671   application.ProcessEvent( event );
672
673   DALI_TEST_CHECK( !gPushButtonSelectedState );
674
675   // Test3. Touch point down and up outside the button.
676
677   gPushButtonSelectedState = false;
678   event = Dali::Integration::TouchEvent();
679   event.AddPoint( GetPointDownOutside() );
680   application.ProcessEvent( event );
681
682   event = Dali::Integration::TouchEvent();
683   event.AddPoint( GetPointUpOutside() );
684   application.ProcessEvent( event );
685
686   DALI_TEST_CHECK( !gPushButtonSelectedState );
687
688   // Test4. Touch point down inside and up outside the button.
689   //        State changes on Button down
690   gPushButtonSelectedState = false;
691   event = Dali::Integration::TouchEvent();
692   event.AddPoint( GetPointDownInside() );
693   application.ProcessEvent( event );
694
695   event = Dali::Integration::TouchEvent();
696   event.AddPoint( GetPointLeave() );
697   application.ProcessEvent( event );
698
699   event = Dali::Integration::TouchEvent();
700   event.AddPoint( GetPointUpOutside() );
701   application.ProcessEvent( event );
702
703   DALI_TEST_CHECK( gPushButtonSelectedState );
704
705   // Test5. Touch point down outside and up inside the button.
706   // Start in unselected state
707   pushButton.SetProperty( Button::Property::SELECTED, false );
708
709   DALI_TEST_EQUALS( pushButton.GetProperty<bool>(pushButton.GetPropertyIndex("selected") ),false , TEST_LOCATION );
710
711   gPushButtonSelectedState = false;
712   event = Dali::Integration::TouchEvent();
713   event.AddPoint( GetPointDownOutside() );
714   application.ProcessEvent( event );
715
716   event = Dali::Integration::TouchEvent();
717   event.AddPoint( GetPointEnter() );
718   application.ProcessEvent( event );
719
720   event = Dali::Integration::TouchEvent();
721   event.AddPoint( GetPointUpInside() );
722   application.ProcessEvent( event );
723
724   DALI_TEST_CHECK( !gPushButtonSelectedState );
725   END_TEST;
726 }
727
728 int UtcDaliPushButtonPropertySetLabelPadding(void)
729 {
730   ToolkitTestApplication application;
731   tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
732
733   PushButton pushButton = PushButton::New();
734   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
735   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 );
736
737   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
738   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 );
739
740   END_TEST;
741 }
742
743 int UtcDaliPushButtonPropertySetIconPadding(void)
744 {
745   ToolkitTestApplication application;
746   tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
747
748   PushButton pushButton = PushButton::New();
749   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
750   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 );
751
752   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
753   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 );
754
755   END_TEST;
756 }
757
758 int UtcDaliPushButtonPaddingLayout(void)
759 {
760   ToolkitTestApplication application;
761   tet_infoline(" UtcDaliPushButtonPaddingLayout");
762
763   // This test creates padding for an icon and a label.
764   // The icon and label are each enabled and disabled to confirm the correct padding is used.
765   PushButton pushButton = PushButton::New();
766
767   const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
768   const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
769
770   // Get actual size of test image
771   ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
772   const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
773
774   pushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
775   pushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
776   pushButton.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
777   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
778
779   application.GetScene().Add( pushButton );
780
781   application.SendNotification();
782   application.Render();
783
784   // First test the size is zero.
785   // No padding should be added as there is no label or icon.
786   Vector2 size( Vector2::ZERO );
787   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
788   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
789   tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
790
791   DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
792
793   // Check label only padding
794   pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
795
796   application.SendNotification();
797   application.Render();
798
799   Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
800   sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
801   sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
802
803   tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
804
805   // Add label padding to label
806   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
807   application.SendNotification();
808   application.Render();
809
810   Vector2 sizeLabelAndPadding( Vector2::ZERO );
811   sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
812   sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
813   tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
814
815   // If control size has increased beyond size of just label then padding has been applied
816   DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
817   DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
818
819   // Re-initialise the button so we can setup icon-only padding.
820   pushButton.Unparent();
821   pushButton = PushButton::New();
822
823   pushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
824   pushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
825   pushButton.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
826   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
827
828   application.GetScene().Add( pushButton );
829
830
831   pushButton.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BEGIN" );
832   pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, TEST_IMAGE_ONE );
833   pushButton.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, TEST_IMAGE_ONE );
834
835   application.SendNotification();
836   application.Render();
837
838   // Size of button with just icon
839   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
840   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
841   tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
842
843   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
844
845   application.SendNotification();
846   application.Render();
847   DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
848
849   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
850   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
851   tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
852   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 );
853   DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
854
855   // Now test padding for both label and icon simultaneously.
856   pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
857
858   application.SendNotification();
859   application.Render();
860
861   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
862   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
863   tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
864
865   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
866
867   application.SendNotification();
868   application.Render();
869
870   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
871   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
872   tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
873
874   DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
875   // Test height of control is same as icon and padding, as Text is smaller than icon
876   DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
877
878   END_TEST;
879 }
880
881 int UtcDaliPushButtonAlignmentLayout(void)
882 {
883   ToolkitTestApplication application;
884   tet_infoline(" UtcDaliPushButtonAlignmentLayout");
885
886   /*
887    * This test checks different alignments for the icon against the label.
888    * The icon is then moved around the label in each of it's alignments.
889    * The final relayed out size is checked to confirm the layout has been done correctly.
890    *
891    * There is an Icon which has 0 width and height, but with 75 padding on all sides.
892    *  - Therefore total width and height are both 150.
893    *
894    * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
895    *  - Therefore total width and height are 60+x and 60+y respectively.
896    *    Where x & y are the width and height of the text.
897    *
898    * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
899    * So We use the padding to help us determine the orientation is correct for each alignment.
900    *
901    * |<- 150 ->|         |<-- 60+x -->|
902    *
903    * +---------+   -
904    * |         |   ^     +------------+   -
905    * |         |   |     |            |   ^
906    * |  Icon   |  150    |   Label    |  60+y
907    * |         |   |     |            |   v
908    * |         |   v     +------------+   -
909    * +---------+   -
910    */
911
912   const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
913   const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
914
915   // Get actual size of test image
916   ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
917   const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
918
919   PushButton pushButton = PushButton::New();
920
921   pushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
922   pushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
923   pushButton.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, 0.0f ));
924   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
925
926   application.GetScene().Add( pushButton );
927
928   // Add a label and get size of control
929   pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
930   application.SendNotification();
931   application.Render();
932
933   // First get the size of control with just label
934   Vector2 justLabelSize( Vector2::ZERO );
935   justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
936   justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
937   tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
938
939   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
940   application.SendNotification();
941   application.Render();
942
943   // Size of Label and Padding
944   Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
945   expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
946   expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
947
948   Vector2 labelAndPaddingSize( Vector2::ZERO );
949   labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
950   labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
951
952   DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
953
954   const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
955                                                      ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
956
957   // Add Icon and set its alignment
958   pushButton.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BEGIN" );
959   pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, TEST_IMAGE_ONE );
960   pushButton.SetProperty( Toolkit::Button::Property::SELECTED_VISUAL, TEST_IMAGE_ONE );
961   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
962
963   application.SendNotification();
964   application.Render();
965
966   Vector2 size( Vector2::ZERO );
967   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
968   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
969
970   /*
971    * Test Icon right alignment.
972    * Height grows to largest of Icon or Label (+ padding).
973    * Normally this will be Icons height, except with very large font sizes.
974    *
975    *  +------------+---------+
976    *  |............+         |
977    *  |            |         |
978    *  |   Label    |  Icon   |
979    *  |            |         |
980    *  |............+         |
981    *  +------------+---------+
982    */
983   DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
984   DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
985
986   // Now test left alignment matches right for size.
987   pushButton.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END" );
988
989   application.SendNotification();
990   application.Render();
991
992   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
993   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
994
995   /*
996    * Test Icon left alignment.
997    * Height grows to largest of Icon or Label (+ padding).
998    * Normally this will be Icons height, except with very large font sizes.
999    *
1000    *  +---------+------------+
1001    *  |         +............|
1002    *  |         |            |
1003    *  |  Icon   |   Label    |
1004    *  |         |            |
1005    *  |         +............|
1006    *  +---------+------------+
1007    */
1008   DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
1009   DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1010
1011   tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
1012   /*
1013    *
1014    *  +---------+
1015    *  |         |
1016    *  |         |
1017    *  |  Icon   |
1018    *  |         |
1019    *  |         |
1020    *  +---------+
1021    *  |         |
1022    *  |  Label  |
1023    *  |         |
1024    *  +---------+
1025    *
1026    */
1027
1028   tet_infoline("SetProperty on LABEL_RELATIVE_ALIGNMENT should relayout the Button");
1029   pushButton.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "BOTTOM" );
1030
1031   application.SendNotification();
1032   application.Render();
1033
1034   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1035   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1036
1037   tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
1038   tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
1039
1040   tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
1041   tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
1042
1043   DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
1044
1045   DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1046
1047   /*
1048    * Test Icon bottom alignment.
1049    * Width grows to largest of Icon or Label (+ padding).
1050    *
1051    *  +---------+
1052    *  |         |
1053    *  |  Label  |
1054    *  |         |
1055    *  +---------+
1056    *  |         |
1057    *  |         |
1058    *  |  Icon   |
1059    *  |         |
1060    *  |         |
1061    *  +---------+
1062    */
1063   tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1064   pushButton.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "TOP" );
1065
1066   application.SendNotification();
1067   application.Render();
1068
1069   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1070   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1071
1072   DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1073   DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1074
1075   END_TEST;
1076 }
1077
1078 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1079 {
1080   tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1081   ToolkitTestApplication application;
1082
1083   PushButton pushButton = PushButton::New();
1084   pushButton.SetProperty( Actor::Property::SIZE, Vector2( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS ) );
1085
1086   application.GetScene().Add( pushButton );
1087
1088   Property::Map propertyMap;
1089   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
1090   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1091
1092   pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1093
1094   tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1095
1096   application.SendNotification();
1097   application.Render(0);
1098
1099   unsigned int rendererCount = pushButton.GetRendererCount();
1100   tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1101
1102   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1103
1104   tet_printf("Remove button from stage\n" );
1105
1106   application.GetScene().Remove( pushButton );
1107
1108   rendererCount = pushButton.GetRendererCount();
1109   tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1110
1111   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1112
1113   tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1114
1115   Property::Map propertyMap2;
1116   propertyMap2.Insert(Visual::Property::TYPE,  Visual::COLOR);
1117   propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1118   pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, propertyMap2 );
1119
1120   tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1121
1122   application.GetScene().Add( pushButton );
1123
1124   tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_VISUAL the renderer count is(%d)\n", pushButton.GetRendererCount() );
1125
1126   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1127
1128   END_TEST;
1129 }
1130
1131 int UtcDaliPushButtonSetSelectedVisualN(void)
1132 {
1133   tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1134
1135   ToolkitTestApplication application;
1136
1137   PushButton pushButton = PushButton::New();
1138
1139   pushButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1140   pushButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1141   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1142
1143   application.GetScene().Add( pushButton );
1144   application.SendNotification();
1145   application.Render(0);
1146
1147   unsigned int preRendererCount = pushButton.GetRendererCount();
1148   tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1149   DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1150
1151   application.GetScene().Remove( pushButton );
1152   application.SendNotification();
1153   application.Render(0);
1154
1155   Property::Map colorMap;
1156   const int BROKEN_VISUAL_TYPE = 999999999;
1157
1158   colorMap.Insert(Visual::Property::TYPE,  BROKEN_VISUAL_TYPE);
1159   colorMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
1160   colorMap.Insert(BorderVisual::Property::SIZE,  5.f);
1161   pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_VISUAL, colorMap );
1162
1163   application.GetScene().Add( pushButton );
1164   application.SendNotification();
1165   application.Render(0);
1166
1167   unsigned int postRendererCount  = pushButton.GetRendererCount();
1168   tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1169   DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1170
1171   END_TEST;
1172 }
1173
1174 int UtcDaliPushButtonToggleSignalP(void)
1175 {
1176   ToolkitTestApplication application;
1177   tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1178
1179   PushButton button = PushButton::New();
1180   button.SetProperty( Button::Property::TOGGLABLE, true);
1181
1182   SetupButtonForTestTouchEvents( application, button, true );
1183
1184   application.GetScene().Add( button );
1185
1186   application.SendNotification();
1187   application.Render();
1188
1189   // connect to its signal
1190   button.ClickedSignal().Connect( &PushButtonClicked );
1191   gPushButtonClicked = false;
1192
1193   tet_infoline(" Touch down and up within button");
1194   Dali::Integration::TouchEvent event;
1195   event = Dali::Integration::TouchEvent();
1196   event.AddPoint( GetPointDownInside() );
1197   application.ProcessEvent( event );
1198
1199   event = Dali::Integration::TouchEvent();
1200   event.AddPoint( GetPointUpInside() );
1201   application.ProcessEvent( event );
1202
1203   DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION );
1204
1205   END_TEST;
1206 }
1207
1208 // Deprecated API Tests
1209
1210 int UtcDaliPushButtonSetGetAutoRepeating(void)
1211 {
1212   ToolkitTestApplication application;
1213   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
1214
1215   PushButton pushButton = PushButton::New();
1216
1217   pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1218
1219   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
1220
1221   pushButton.SetProperty( Button::Property::AUTO_REPEATING, false );
1222
1223   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), false, TEST_LOCATION );
1224
1225   pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1226
1227   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
1228   END_TEST;
1229 }
1230
1231 int UtcDaliPushButtonSetGetTogglableButton(void)
1232 {
1233   ToolkitTestApplication application;
1234   tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
1235
1236   PushButton pushButton = PushButton::New();
1237
1238   pushButton.SetProperty( Button::Property::TOGGLABLE, true );
1239
1240   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), true, TEST_LOCATION );
1241
1242   pushButton.SetProperty( Button::Property::TOGGLABLE, false );
1243
1244   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), false, TEST_LOCATION );
1245
1246   pushButton.SetProperty( Button::Property::TOGGLABLE, true );
1247
1248   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), true, TEST_LOCATION );
1249   END_TEST;
1250 }
1251
1252 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
1253 {
1254   ToolkitTestApplication application;
1255   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
1256
1257   PushButton pushButton = PushButton::New();
1258
1259   pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1260   pushButton.SetProperty( Button::Property::TOGGLABLE, true);
1261
1262   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), true, TEST_LOCATION );
1263   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), false, TEST_LOCATION );
1264
1265   pushButton.SetProperty( Button::Property::TOGGLABLE, true);
1266   pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1267
1268   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::AUTO_REPEATING ), true, TEST_LOCATION );
1269   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::TOGGLABLE ), false, TEST_LOCATION );
1270
1271   END_TEST;
1272 }
1273
1274 int UtcDaliPushButtonSetGetSelected01(void)
1275 {
1276   ToolkitTestApplication application;
1277   tet_infoline(" UtcDaliPushButtonSetGetSelected01");
1278
1279   PushButton pushButton = PushButton::New();
1280
1281   pushButton.SetProperty( Button::Property::TOGGLABLE, true);
1282   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1283
1284   gPushButtonSelectedState = false;
1285   pushButton.SetProperty( Button::Property::SELECTED, true );
1286
1287   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), true, TEST_LOCATION );
1288   DALI_TEST_CHECK( gPushButtonSelectedState );
1289
1290   pushButton.SetProperty( Button::Property::SELECTED, false );
1291
1292   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), false, TEST_LOCATION );
1293   DALI_TEST_CHECK( !gPushButtonSelectedState );
1294
1295   pushButton.SetProperty( Button::Property::SELECTED, true );
1296
1297   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), true, TEST_LOCATION );
1298   DALI_TEST_CHECK( gPushButtonSelectedState );
1299   END_TEST;
1300 }
1301
1302 int UtcDaliPushButtonSetGetSelected02(void)
1303 {
1304   ToolkitTestApplication application;
1305   tet_infoline(" UtcDaliPushButtonSetGetSelected02");
1306
1307   PushButton pushButton = PushButton::New();
1308
1309   tet_infoline(" Set Toggle feature off");
1310   pushButton.SetProperty( Button::Property::TOGGLABLE, false);
1311   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1312
1313   gPushButtonSelectedState = false;
1314   tet_infoline(" Try to set to selected, expecting failure as not a toggle button");
1315   pushButton.SetProperty( Button::Property::SELECTED, true );
1316
1317   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), false, TEST_LOCATION );
1318   DALI_TEST_CHECK( !gPushButtonSelectedState );
1319
1320   pushButton.SetProperty( Button::Property::SELECTED, false );
1321
1322   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED), false, TEST_LOCATION );
1323   DALI_TEST_CHECK( !gPushButtonSelectedState );
1324
1325   pushButton.SetProperty( Button::Property::SELECTED, true );
1326
1327   DALI_TEST_EQUALS( pushButton.GetProperty<bool>( Button::Property::SELECTED ), false, TEST_LOCATION );
1328   DALI_TEST_CHECK( !gPushButtonSelectedState );
1329
1330   END_TEST;
1331 }
1332
1333 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
1334 {
1335   ToolkitTestApplication application;
1336   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
1337
1338   PushButton pushButton = PushButton::New();
1339
1340   pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1341
1342   pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, 1.f);
1343   DALI_TEST_EQUALS( pushButton.GetProperty<float>( Button::Property::INITIAL_AUTO_REPEATING_DELAY ), 1.f, TEST_LOCATION );
1344
1345   pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 1.f);
1346
1347   DALI_TEST_EQUALS( pushButton.GetProperty<float>( Button::Property::NEXT_AUTO_REPEATING_DELAY ), 1.f, TEST_LOCATION );
1348   END_TEST;
1349 }
1350
1351 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
1352 {
1353   ToolkitTestApplication application;
1354   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
1355
1356   PushButton pushButton = PushButton::New();
1357
1358   bool assert1( false );
1359   bool assert2( false );
1360
1361   pushButton.SetProperty( Button::Property::AUTO_REPEATING, true );
1362
1363   try
1364   {
1365     pushButton.SetProperty( Button::Property::INITIAL_AUTO_REPEATING_DELAY, -1.f );
1366   }
1367   catch( Dali::DaliException& e )
1368   {
1369     DALI_TEST_PRINT_ASSERT( e );
1370     DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
1371     assert1 = true;
1372   }
1373
1374   try
1375   {
1376     pushButton.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, -1.f );
1377   }
1378   catch( Dali::DaliException& e )
1379   {
1380     DALI_TEST_PRINT_ASSERT( e );
1381     DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
1382     assert2 = true;
1383   }
1384
1385   DALI_TEST_CHECK( assert1 && assert2 );
1386   END_TEST;
1387 }
1388
1389 int UtcDaliPushButtonSetLabelText(void)
1390 {
1391   ToolkitTestApplication application;
1392   tet_infoline(" UtcDaliPushButtonSetLabelText");
1393
1394   const std::string STR( "Hola!" );
1395
1396   PushButton pushButton = PushButton::New();
1397
1398   pushButton.SetProperty( Toolkit::Button::Property::LABEL,
1399                           Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::TEXT )
1400                                          .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1401                         );
1402
1403   application.SendNotification();
1404   application.Render();
1405
1406   pushButton.SetProperty( Button::Property::LABEL, STR );
1407
1408   DALI_TEST_EQUALS(GetButtonText( pushButton ), STR, TEST_LOCATION);
1409
1410   END_TEST;
1411 }