074e0f3b58557d7fae6d2d619c0dcfcefa4a2666
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-PushButton.cpp
1 /*
2  * Copyright (c) 2014 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 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
32
33 #include <dali/devel-api/adaptor-framework/image-loading.h>
34
35 using namespace Dali;
36 using namespace Toolkit;
37
38 void utc_dali_toolkit_pushbutton_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void utc_dali_toolkit_pushbutton_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48 namespace
49 {
50
51 static bool gPushButtonSelectedState = false;
52 bool PushButtonSelected( Button button )
53 {
54   gPushButtonSelectedState = button.IsSelected();
55   return true;
56 }
57
58 static bool gPushButtonPressed = false;
59
60 static bool PushButtonPressed( Button button )
61 {
62   gPushButtonPressed = true;
63   return true;
64 }
65
66 static bool gPushButtonReleased = false;
67
68 static bool PushButtonReleased( Button button )
69 {
70   gPushButtonReleased = true;
71   return true;
72 }
73
74 Dali::Integration::Point GetPointDownInside()
75 {
76   Dali::Integration::Point point;
77   point.SetState( PointState::DOWN );
78   point.SetScreenPosition( Vector2( 240, 400 ) );
79   return point;
80 }
81
82 Dali::Integration::Point GetPointUpInside()
83 {
84   Dali::Integration::Point point;
85   point.SetState( PointState::UP );
86   point.SetScreenPosition( Vector2( 240, 400 ) );
87   return point;
88 }
89
90 Dali::Integration::Point GetPointLeave()
91 {
92   Dali::Integration::Point point;
93   point.SetState( PointState::LEAVE );
94   point.SetScreenPosition( Vector2( 240, 400 ) );
95   return point;
96 }
97
98 Dali::Integration::Point GetPointEnter()
99 {
100   Dali::Integration::Point point;
101   point.SetState( PointState::MOTION );
102   point.SetScreenPosition( Vector2( 240, 400 ) );
103   return point;
104 }
105
106 Dali::Integration::Point GetPointDownOutside()
107 {
108   Dali::Integration::Point point;
109   point.SetState( PointState::DOWN );
110   point.SetScreenPosition( Vector2( 10, 10 ) );
111   return point;
112 }
113
114 Dali::Integration::Point GetPointUpOutside()
115 {
116   Dali::Integration::Point point;
117   point.SetState( PointState::UP );
118   point.SetScreenPosition( Vector2( 10, 10 ) );
119   return point;
120 }
121
122 } //namespace
123
124 int UtcDaliPushButtonConstructorP(void)
125 {
126   TestApplication application;
127
128   PushButton button;
129
130   DALI_TEST_CHECK( !button );
131   END_TEST;
132 }
133
134 int UtcDaliPushButtonCopyConstructorP(void)
135 {
136   TestApplication application;
137
138   // Initialize an object, ref count == 1
139   PushButton button = PushButton::New();
140
141   PushButton copy( button );
142   DALI_TEST_CHECK( copy );
143   END_TEST;
144 }
145
146 int UtcDaliPushButtonAssignmentOperatorP(void)
147 {
148   TestApplication application;
149
150   PushButton button = PushButton::New();
151
152   PushButton copy( button );
153   DALI_TEST_CHECK( copy );
154
155   DALI_TEST_CHECK( button == copy );
156   END_TEST;
157 }
158
159 int UtcDaliPushButtonNewP(void)
160 {
161   TestApplication application;
162
163   PushButton button = PushButton::New();
164
165   DALI_TEST_CHECK( button );
166   END_TEST;
167 }
168
169 int UtcDaliPushButtonDownCastP(void)
170 {
171   TestApplication application;
172
173   PushButton button = PushButton::New();
174
175   BaseHandle object(button);
176
177   PushButton button2 = PushButton::DownCast( object );
178   DALI_TEST_CHECK(button2);
179
180   PushButton button3 = DownCast< PushButton >(object);
181   DALI_TEST_CHECK(button3);
182   END_TEST;
183 }
184
185 int UtcDaliPushButtonDownCastN(void)
186 {
187   TestApplication application;
188
189   BaseHandle unInitializedObject;
190
191   PushButton button1 = PushButton::DownCast( unInitializedObject );
192   DALI_TEST_CHECK( !button1 );
193
194   PushButton button2 = DownCast< PushButton >( unInitializedObject );
195   DALI_TEST_CHECK( !button2 );
196   END_TEST;
197 }
198
199 int UtcDaliPushButtonSetGetAutoRepeating(void)
200 {
201   ToolkitTestApplication application;
202   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
203
204   PushButton pushButton = PushButton::New();
205
206   pushButton.SetAutoRepeating( true );
207
208   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
209
210   pushButton.SetAutoRepeating( false );
211
212   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
213
214   pushButton.SetAutoRepeating( true );
215
216   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
217   END_TEST;
218 }
219
220 int UtcDaliPushButtonSetGetTogglableButton(void)
221 {
222   ToolkitTestApplication application;
223   tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
224
225   PushButton pushButton = PushButton::New();
226
227   pushButton.SetTogglableButton( true );
228
229   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
230
231   pushButton.SetTogglableButton( false );
232
233   DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
234
235   pushButton.SetTogglableButton( true );
236
237   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
238   END_TEST;
239 }
240
241 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
242 {
243   ToolkitTestApplication application;
244   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
245
246   PushButton pushButton = PushButton::New();
247
248   pushButton.SetAutoRepeating( true );
249   pushButton.SetTogglableButton( true );
250
251   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
252   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
253
254   pushButton.SetTogglableButton( true );
255   pushButton.SetAutoRepeating( true );
256
257   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
258   DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
259   END_TEST;
260 }
261
262 int UtcDaliPushButtonSetGetSelected01(void)
263 {
264   ToolkitTestApplication application;
265   tet_infoline(" UtcDaliPushButtonSetGetSelected01");
266
267   PushButton pushButton = PushButton::New();
268
269   pushButton.SetTogglableButton( true );
270   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
271
272   gPushButtonSelectedState = false;
273   pushButton.SetSelected( true );
274
275   DALI_TEST_CHECK( pushButton.IsSelected() );
276   DALI_TEST_CHECK( gPushButtonSelectedState );
277
278   pushButton.SetSelected( false );
279
280   DALI_TEST_CHECK( !pushButton.IsSelected() );
281   DALI_TEST_CHECK( !gPushButtonSelectedState );
282
283   pushButton.SetSelected( true );
284
285   DALI_TEST_CHECK( pushButton.IsSelected() );
286   DALI_TEST_CHECK( gPushButtonSelectedState );
287   END_TEST;
288 }
289
290 int UtcDaliPushButtonSetGetSelected02(void)
291 {
292   ToolkitTestApplication application;
293   tet_infoline(" UtcDaliPushButtonSetGetSelected02");
294
295   PushButton pushButton = PushButton::New();
296
297   pushButton.SetTogglableButton( false );
298   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
299
300   gPushButtonSelectedState = false;
301   pushButton.SetSelected( true );
302
303   DALI_TEST_CHECK( !pushButton.IsSelected() );
304   DALI_TEST_CHECK( !gPushButtonSelectedState );
305
306   pushButton.SetSelected( false );
307
308   DALI_TEST_CHECK( !pushButton.IsSelected() );
309   DALI_TEST_CHECK( !gPushButtonSelectedState );
310
311   pushButton.SetSelected( true );
312
313   DALI_TEST_CHECK( !pushButton.IsSelected() );
314   DALI_TEST_CHECK( !gPushButtonSelectedState );
315   END_TEST;
316 }
317
318 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
319 {
320   ToolkitTestApplication application;
321   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
322
323   PushButton pushButton = PushButton::New();
324
325   pushButton.SetAutoRepeating( true );
326
327   pushButton.SetInitialAutoRepeatingDelay( 1.f );
328   DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
329
330   pushButton.SetNextAutoRepeatingDelay( 1.f );
331   DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
332   END_TEST;
333 }
334
335 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
336 {
337   ToolkitTestApplication application;
338   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
339
340   PushButton pushButton = PushButton::New();
341
342   bool assert1( false );
343   bool assert2( false );
344
345   pushButton.SetAutoRepeating( true );
346
347   try
348   {
349     pushButton.SetInitialAutoRepeatingDelay( -1.f );
350   }
351   catch( Dali::DaliException& e )
352   {
353     DALI_TEST_PRINT_ASSERT( e );
354     DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
355     assert1 = true;
356   }
357
358   try
359   {
360     pushButton.SetNextAutoRepeatingDelay( -1.f );
361   }
362   catch( Dali::DaliException& e )
363   {
364     DALI_TEST_PRINT_ASSERT( e );
365     DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
366     assert2 = true;
367   }
368
369   DALI_TEST_CHECK( assert1 && assert2 );
370   END_TEST;
371 }
372
373 int UtcDaliPushButtonSetLabelText(void)
374 {
375   ToolkitTestApplication application;
376   tet_infoline(" UtcDaliPushButtonSetLabelText");
377
378   const std::string STR( "Hola!" );
379
380   PushButton pushButton = PushButton::New();
381
382   application.SendNotification();
383   application.Render();
384
385   pushButton.SetLabelText( STR );
386
387   DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
388
389   END_TEST;
390 }
391
392 int UtcDaliPushButtonPressed(void)
393 {
394   ToolkitTestApplication application;
395   tet_infoline(" UtcDaliPushButtonPressed");
396
397   PushButton pushButton = PushButton::New();
398   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
399   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
400   pushButton.SetPosition( 240, 400 );
401   pushButton.SetSize( 100, 100 );
402
403   Stage::GetCurrent().Add( pushButton );
404
405   application.SendNotification();
406   application.Render();
407
408   gPushButtonPressed = false;
409
410   // connect to its touch signal
411   pushButton.PressedSignal().Connect( &PushButtonPressed );
412
413   Dali::Integration::TouchEvent eventDown;
414   eventDown.AddPoint( GetPointDownInside() );
415
416   // flush the queue and render once
417   application.SendNotification();
418   application.Render();
419   application.ProcessEvent( eventDown );
420
421   DALI_TEST_CHECK( gPushButtonPressed );
422   END_TEST;
423 }
424
425 int UtcDaliPushButtonReleased(void)
426 {
427   ToolkitTestApplication application;
428   tet_infoline(" UtcDaliPushButtonReleased");
429
430   PushButton pushButton = PushButton::New();
431   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
432   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
433   pushButton.SetPosition( 240, 400 );
434   pushButton.SetSize( 100, 100 );
435
436   Stage::GetCurrent().Add( pushButton );
437
438   application.SendNotification();
439   application.Render();
440
441   // connect to its touch signal
442   pushButton.ReleasedSignal().Connect( &PushButtonReleased );
443
444   Dali::Integration::TouchEvent event;
445
446   // Test1. Touch point down and up inside the button.
447
448   gPushButtonReleased = false;
449   event = Dali::Integration::TouchEvent();
450   event.AddPoint( GetPointDownInside() );
451   application.ProcessEvent( event );
452
453   event = Dali::Integration::TouchEvent();
454   event.AddPoint( GetPointUpInside() );
455   application.ProcessEvent( event );
456
457   DALI_TEST_CHECK( gPushButtonReleased );
458
459   // Test2. Touch point down and up outside the button.
460
461   gPushButtonReleased = false;
462   event = Dali::Integration::TouchEvent();
463   event.AddPoint( GetPointDownOutside() );
464   application.ProcessEvent( event );
465
466   event = Dali::Integration::TouchEvent();
467   event.AddPoint( GetPointUpOutside() );
468   application.ProcessEvent( event );
469
470   DALI_TEST_CHECK( !gPushButtonReleased );
471
472   // Test3. Touch point down inside and up outside the button.
473
474   gPushButtonReleased = false;
475   event = Dali::Integration::TouchEvent();
476   event.AddPoint( GetPointDownInside() );
477   application.ProcessEvent( event );
478
479   event = Dali::Integration::TouchEvent();
480   event.AddPoint( GetPointLeave() );
481   application.ProcessEvent( event );
482
483   event = Dali::Integration::TouchEvent();
484   event.AddPoint( GetPointUpOutside() );
485   application.ProcessEvent( event );
486
487   DALI_TEST_CHECK( gPushButtonReleased );
488
489   // Test4. Touch point down outside and up inside the button.
490
491   gPushButtonReleased = false;
492   event = Dali::Integration::TouchEvent();
493   event.AddPoint( GetPointDownOutside() );
494   application.ProcessEvent( event );
495
496   event = Dali::Integration::TouchEvent();
497   event.AddPoint( GetPointEnter() );
498   application.ProcessEvent( event );
499
500   event = Dali::Integration::TouchEvent();
501   event.AddPoint( GetPointUpInside() );
502   application.ProcessEvent( event );
503
504   DALI_TEST_CHECK( !gPushButtonReleased );
505   END_TEST;
506 }
507
508 int UtcDaliPushButtonSelected(void)
509 {
510   ToolkitTestApplication application;
511   tet_infoline(" UtcDaliPushButtonSelected");
512
513   PushButton pushButton = PushButton::New();
514   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
515   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
516   pushButton.SetPosition( 240, 400 );
517   pushButton.SetSize( 100, 100 );
518
519   Stage::GetCurrent().Add( pushButton );
520
521   application.SendNotification();
522   application.Render();
523
524   // connect to its touch signal
525   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
526
527   Dali::Integration::TouchEvent event;
528
529   // Test1. No togglable button.
530
531   gPushButtonSelectedState = false;
532   event = Dali::Integration::TouchEvent();
533   event.AddPoint( GetPointDownInside() );
534   application.ProcessEvent( event );
535
536   event = Dali::Integration::TouchEvent();
537   event.AddPoint( GetPointUpInside() );
538   application.ProcessEvent( event );
539
540   DALI_TEST_CHECK( !gPushButtonSelectedState );
541
542   // Set togglable property.
543   pushButton.SetTogglableButton( true );
544
545   // Test2. Touch point down and up inside the button twice.
546   gPushButtonSelectedState = false;
547   event = Dali::Integration::TouchEvent();
548   event.AddPoint( GetPointDownInside() );
549   application.ProcessEvent( event );
550
551   event = Dali::Integration::TouchEvent();
552   event.AddPoint( GetPointUpInside() );
553   application.ProcessEvent( event );
554
555   DALI_TEST_CHECK( gPushButtonSelectedState );
556
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( !gPushButtonSelectedState );
566
567   // Test3. Touch point down and up outside the button.
568
569   gPushButtonSelectedState = 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( !gPushButtonSelectedState );
579
580   // Test4. Touch point down inside and up outside the button.
581
582   gPushButtonSelectedState = 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( !gPushButtonSelectedState );
596
597   // Test5. Touch point down outside and up inside the button.
598
599   gPushButtonSelectedState = 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( !gPushButtonSelectedState );
613   END_TEST;
614 }
615
616 int UtcDaliPushButtonPropertySetIconAlignment(void)
617 {
618   ToolkitTestApplication application;
619   tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
620
621   PushButton pushButton = PushButton::New();
622   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
623   DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
624
625   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
626   DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
627
628   END_TEST;
629 }
630
631 int UtcDaliPushButtonPropertySetLabelPadding(void)
632 {
633   ToolkitTestApplication application;
634   tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
635
636   PushButton pushButton = PushButton::New();
637   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
638   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 );
639
640   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
641   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 );
642
643   END_TEST;
644 }
645
646 int UtcDaliPushButtonPropertySetIconPadding(void)
647 {
648   ToolkitTestApplication application;
649   tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
650
651   PushButton pushButton = PushButton::New();
652   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
653   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 );
654
655   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
656   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 );
657
658   END_TEST;
659 }
660
661 int UtcDaliPushButtonPaddingLayout(void)
662 {
663   ToolkitTestApplication application;
664   tet_infoline(" UtcDaliPushButtonPaddingLayout");
665
666   // This test creates padding for an icon and a label.
667   // The icon and label are each enabled and disabled to confirm the correct padding is used.
668   PushButton pushButton = PushButton::New();
669
670
671   const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
672   const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f, 10.0f );
673
674   // Get actual size of test image
675   ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
676   const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
677
678   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
679   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
680   pushButton.SetPosition( 0.0f, 0.0f );
681   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
682
683   Stage::GetCurrent().Add( pushButton );
684
685   application.SendNotification();
686   application.Render();
687
688   // First test the size is zero.
689   // No padding should be added as there is no label or icon.
690   Vector2 size( Vector2::ZERO );
691   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
692   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
693
694   DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
695
696   // Check label only padding.
697   pushButton.SetLabelText( "Label" );
698
699   application.SendNotification();
700   application.Render();
701
702   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
703   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
704
705   // We should not test against the exact label size, we just make sure it is larger than our label padding so we know the padding has been applied.
706   DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION );
707   DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION );
708
709   // Re-initialise the button so we can setup icon-only padding.
710   pushButton.Unparent();
711   pushButton = PushButton::New();
712
713   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
714   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
715
716   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
717   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
718   pushButton.SetPosition( 0.0f, 0.0f );
719   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
720
721   Stage::GetCurrent().Add( pushButton );
722
723
724
725   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
726   pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
727   pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
728
729   application.SendNotification();
730   application.Render();
731
732   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
733   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
734
735
736   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
737
738   application.SendNotification();
739   application.Render();
740   DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
741
742   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
743   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
744   tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
745   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 );
746   DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
747
748   // Now test padding for both label and icon simultaneously.
749   pushButton.SetLabelText( "Label" );
750
751   application.SendNotification();
752   application.Render();
753
754   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
755   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
756
757
758   DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
759   // Test height of control is same as icon and padding, as Text is smaller than icon
760   DALI_TEST_EQUALS( size.height, expectedIconAndPaddingSize.height, TEST_LOCATION );
761
762   END_TEST;
763 }
764
765 int UtcDaliPushButtonAlignmentLayout(void)
766 {
767   ToolkitTestApplication application;
768   tet_infoline(" UtcDaliPushButtonAlignmentLayout");
769
770   /*
771    * This test checks different alignments for the icon against the label.
772    * The icon is then moved around the label in each of it's alignments.
773    * The final relayed out size is checked to confirm the layout has been done correctly.
774    *
775    * There is an Icon which has 0 width and height, but with 75 padding on all sides.
776    *  - Therefore total width and height are both 150.
777    *
778    * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
779    *  - Therefore total width and height are 60+x and 60+y respectively.
780    *    Where x & y are the width and height of the text.
781    *
782    * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
783    * So We use the padding to help us determine the orientation is correct for each alignment.
784    *
785    * |<- 150 ->|         |<-- 60+x -->|
786    *
787    * +---------+   -
788    * |         |   ^     +------------+   -
789    * |         |   |     |            |   ^
790    * |  Icon   |  150    |   Label    |  60+y
791    * |         |   |     |            |   v
792    * |         |   v     +------------+   -
793    * +---------+   -
794    */
795
796
797   const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
798   const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
799
800   // Get actual size of test image
801   ImageDimensions testImageSize = Dali::GetClosestImageSize( TEST_IMAGE_ONE );
802   const Vector2 TEST_IMAGE_SIZE( testImageSize.GetWidth(), testImageSize.GetHeight() );
803
804   PushButton pushButton = PushButton::New();
805
806   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) );
807   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) );
808
809   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
810   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
811   pushButton.SetPosition( 0.0f, 0.0f );
812   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
813
814   Stage::GetCurrent().Add( pushButton );
815
816   const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
817   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
818   pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
819   pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
820
821   application.SendNotification();
822   application.Render();
823
824   // First get the base size (without label).
825   Vector2 baseSize( Vector2::ZERO );
826   baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
827   baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
828
829   DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
830
831
832   DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
833
834   const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
835                                                      ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
836
837   // Add Icon and set its alignment
838   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
839   pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
840   pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
841   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
842
843   application.SendNotification();
844   application.Render();
845
846   Vector2 size( Vector2::ZERO );
847   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
848   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
849
850
851   /*
852    * Test Icon right alignment.
853    * Height grows to largest of Icon or Label (+ padding).
854    * Normally this will be Icons height, except with very large font sizes.
855    *
856    *  +------------+---------+
857    *  |............+         |
858    *  |            |         |
859    *  |   Label    |  Icon   |
860    *  |            |         |
861    *  |............+         |
862    *  +------------+---------+
863    */
864   DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION );
865   DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
866
867   // Now test left alignment matches right for size.
868   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
869
870   application.SendNotification();
871   application.Render();
872
873   Vector2 compareSize( Vector2::ZERO );
874   compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
875   compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
876
877   /*
878    * Test Icon left alignment.
879    * Height grows to largest of Icon or Label (+ padding).
880    * Normally this will be Icons height, except with very large font sizes.
881    *
882    *  +---------+------------+
883    *  |         +............|
884    *  |         |            |
885    *  |  Icon   |   Label    |
886    *  |         |            |
887    *  |         +............|
888    *  +---------+------------+
889    */
890   DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
891
892   // Test top alignment.
893   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
894
895   application.SendNotification();
896   application.Render();
897
898   compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
899   compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
900
901   /*
902    * Test Icon top alignment.
903    * Width grows to largest of Icon or Label (+ padding).
904    *
905    *  +---------+
906    *  |         |
907    *  |         |
908    *  |  Icon   |
909    *  |         |
910    *  |         |
911    *  +---------+
912    *  |         |
913    *  |  Label  |
914    *  |         |
915    *  +---------+
916    *
917    *  Note: We subtract a small number as we want to do a >= test.
918    */
919   DALI_TEST_GREATER( size.width, 150.0f - Math::MACHINE_EPSILON_1000, TEST_LOCATION );
920   DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION );
921
922   // Test bottom alignment.
923   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
924
925   application.SendNotification();
926   application.Render();
927
928   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
929   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
930
931   /*
932    * Test Icon bottom alignment.
933    * Width grows to largest of Icon or Label (+ padding).
934    *
935    *  +---------+
936    *  |         |
937    *  |  Label  |
938    *  |         |
939    *  +---------+
940    *  |         |
941    *  |         |
942    *  |  Icon   |
943    *  |         |
944    *  |         |
945    *  +---------+
946    */
947   DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
948
949   END_TEST;
950 }
951
952 int UtcDaliPushButtonSetButtonImageP(void)
953 {
954   ToolkitTestApplication application;
955
956   PushButton button = PushButton::New();
957   Stage::GetCurrent().Add( button );
958
959   try
960   {
961     button.SetButtonImage( ImageView::New() );
962     DALI_TEST_CHECK( true );
963   }
964   catch(...)
965   {
966     DALI_TEST_CHECK( false );
967   }
968
969   END_TEST;
970 }
971
972 int UtcDaliPushButtonSetButtonImageN(void)
973 {
974   ToolkitTestApplication application;
975
976   PushButton button;
977
978   try
979   {
980     button.SetSelectedImage( ImageView::New() );
981     DALI_TEST_CHECK( false );
982   }
983   catch(...)
984   {
985     DALI_TEST_CHECK( true );
986   }
987
988   END_TEST;
989 }
990
991 int UtcDaliPushButtonSetBackgroundImageP(void)
992 {
993   ToolkitTestApplication application;
994
995   PushButton button = PushButton::New();
996   Stage::GetCurrent().Add( button );
997
998   try
999   {
1000     button.SetBackgroundImage( ImageView::New() );
1001     DALI_TEST_CHECK( true );
1002   }
1003   catch(...)
1004   {
1005     DALI_TEST_CHECK( false );
1006   }
1007
1008   END_TEST;
1009 }
1010
1011 int UtcDaliPushButtonSetBackgroundImageN(void)
1012 {
1013   ToolkitTestApplication application;
1014
1015   PushButton button;
1016
1017   try
1018   {
1019     button.SetBackgroundImage( ImageView::New() );
1020     DALI_TEST_CHECK( false );
1021   }
1022   catch(...)
1023   {
1024     DALI_TEST_CHECK( true );
1025   }
1026
1027   END_TEST;
1028 }
1029
1030 int UtcDaliPushButtonSetSelectedImageP(void)
1031 {
1032   ToolkitTestApplication application;
1033
1034   PushButton button = PushButton::New();
1035   Stage::GetCurrent().Add( button );
1036
1037   try
1038   {
1039     button.SetSelectedImage( ImageView::New() );
1040     DALI_TEST_CHECK( true );
1041   }
1042   catch(...)
1043   {
1044     DALI_TEST_CHECK( false );
1045   }
1046
1047   END_TEST;
1048 }
1049
1050 int UtcDaliPushButtonSetSelectedImageN(void)
1051 {
1052   ToolkitTestApplication application;
1053
1054   PushButton button;
1055
1056   try
1057   {
1058     button.SetSelectedImage( ImageView::New() );
1059     DALI_TEST_CHECK( false );
1060   }
1061   catch(...)
1062   {
1063     DALI_TEST_CHECK( true );
1064   }
1065
1066   END_TEST;
1067 }
1068
1069 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1070 {
1071   ToolkitTestApplication application;
1072
1073   PushButton button = PushButton::New();
1074   Stage::GetCurrent().Add( button );
1075
1076   try
1077   {
1078     button.SetSelectedBackgroundImage( ImageView::New() );
1079     DALI_TEST_CHECK( true );
1080   }
1081   catch(...)
1082   {
1083     DALI_TEST_CHECK( false );
1084   }
1085
1086   END_TEST;
1087 }
1088
1089 int UtcDaliPushButtonSetSelectedBackgroundImageN(void)
1090 {
1091   ToolkitTestApplication application;
1092
1093   PushButton button;
1094
1095   try
1096   {
1097     button.SetSelectedBackgroundImage( ImageView::New() );
1098     DALI_TEST_CHECK( false );
1099   }
1100   catch(...)
1101   {
1102     DALI_TEST_CHECK( true );
1103   }
1104
1105   END_TEST;
1106 }
1107
1108 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1109 {
1110   ToolkitTestApplication application;
1111
1112   PushButton button = PushButton::New();
1113   Stage::GetCurrent().Add( button );
1114
1115   try
1116   {
1117     button.SetDisabledBackgroundImage( ImageView::New() );
1118     DALI_TEST_CHECK( true );
1119   }
1120   catch(...)
1121   {
1122     DALI_TEST_CHECK( false );
1123   }
1124
1125   END_TEST;
1126 }
1127
1128 int UtcDaliPushButtonSetDisabledBackgroundImageN(void)
1129 {
1130   ToolkitTestApplication application;
1131
1132   PushButton button;
1133
1134   try
1135   {
1136     button.SetDisabledBackgroundImage( ImageView::New() );
1137     DALI_TEST_CHECK( false );
1138   }
1139   catch(...)
1140   {
1141     DALI_TEST_CHECK( true );
1142   }
1143
1144   END_TEST;
1145 }
1146
1147 int UtcDaliPushButtonSetDisabledImageP(void)
1148 {
1149   ToolkitTestApplication application;
1150
1151   PushButton button = PushButton::New();
1152   Stage::GetCurrent().Add( button );
1153
1154   try
1155   {
1156     button.SetDisabledImage( ImageView::New() );
1157     DALI_TEST_CHECK( true );
1158   }
1159   catch(...)
1160   {
1161     DALI_TEST_CHECK( false );
1162   }
1163
1164   END_TEST;
1165 }
1166
1167 int UtcDaliPushButtonSetDisabledImageN(void)
1168 {
1169   ToolkitTestApplication application;
1170
1171   PushButton button;
1172
1173   try
1174   {
1175     button.SetDisabledImage( ImageView::New() );
1176     DALI_TEST_CHECK( false );
1177   }
1178   catch(...)
1179   {
1180     DALI_TEST_CHECK( true );
1181   }
1182
1183   END_TEST;
1184 }
1185
1186 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1187 {
1188   ToolkitTestApplication application;
1189
1190   PushButton button = PushButton::New();
1191   Stage::GetCurrent().Add( button );
1192
1193   try
1194   {
1195     button.SetDisabledSelectedImage( ImageView::New() );
1196     DALI_TEST_CHECK( true );
1197   }
1198   catch(...)
1199   {
1200     DALI_TEST_CHECK( false );
1201   }
1202
1203   END_TEST;
1204 }
1205
1206 int UtcDaliPushButtonSetDisabledSelectedImageN(void)
1207 {
1208   ToolkitTestApplication application;
1209
1210   PushButton button;
1211
1212   try
1213   {
1214     button.SetDisabledSelectedImage( ImageView::New() );
1215     DALI_TEST_CHECK( false );
1216   }
1217   catch(...)
1218   {
1219     DALI_TEST_CHECK( true );
1220   }
1221
1222   END_TEST;
1223 }