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