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