Merge "Changed ImageView to use a unit square mesh and instead to size the mesh in...
[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 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
69 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
70 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
71 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
72 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
73 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
74 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
75
76 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
77 {
78   BufferImage imageData = BufferImage::New( width, height, Pixel::RGBA8888 );
79
80   // Create the image
81   PixelBuffer* pixbuf = imageData.GetBuffer();
82   unsigned int size = width * height;
83
84   for( size_t i = 0; i < size; i++ )
85     {
86       pixbuf[i*4+0] = 0xFF * color.r;
87       pixbuf[i*4+1] = 0xFF * color.g;
88       pixbuf[i*4+2] = 0xFF * color.b;
89       pixbuf[i*4+3] = 0xFF * color.a;
90     }
91
92   imageData.Update();
93
94   return imageData;
95 }
96
97 } //namespace
98
99 int UtcDaliPushButtonConstructorP(void)
100 {
101   TestApplication application;
102
103   PushButton button;
104
105   DALI_TEST_CHECK( !button );
106   END_TEST;
107 }
108
109 int UtcDaliPushButtonCopyConstructorP(void)
110 {
111   TestApplication application;
112
113   // Initialize an object, ref count == 1
114   PushButton button = PushButton::New();
115
116   PushButton copy( button );
117   DALI_TEST_CHECK( copy );
118   END_TEST;
119 }
120
121 int UtcDaliPushButtonAssignmentOperatorP(void)
122 {
123   TestApplication application;
124
125   PushButton button = PushButton::New();
126
127   PushButton copy( button );
128   DALI_TEST_CHECK( copy );
129
130   DALI_TEST_CHECK( button == copy );
131   END_TEST;
132 }
133
134 int UtcDaliPushButtonNewP(void)
135 {
136   TestApplication application;
137
138   PushButton button = PushButton::New();
139
140   DALI_TEST_CHECK( button );
141   END_TEST;
142 }
143
144 int UtcDaliPushButtonDownCastP(void)
145 {
146   TestApplication application;
147
148   PushButton button = PushButton::New();
149
150   BaseHandle object(button);
151
152   PushButton button2 = PushButton::DownCast( object );
153   DALI_TEST_CHECK(button2);
154
155   PushButton button3 = DownCast< PushButton >(object);
156   DALI_TEST_CHECK(button3);
157   END_TEST;
158 }
159
160 int UtcDaliPushButtonDownCastN(void)
161 {
162   TestApplication application;
163
164   BaseHandle unInitializedObject;
165
166   PushButton button1 = PushButton::DownCast( unInitializedObject );
167   DALI_TEST_CHECK( !button1 );
168
169   PushButton button2 = DownCast< PushButton >( unInitializedObject );
170   DALI_TEST_CHECK( !button2 );
171   END_TEST;
172 }
173
174 int UtcDaliPushButtonSetGetAutoRepeating(void)
175 {
176   ToolkitTestApplication application;
177   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
178
179   PushButton pushButton = PushButton::New();
180
181   pushButton.SetAutoRepeating( true );
182
183   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
184
185   pushButton.SetAutoRepeating( false );
186
187   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
188
189   pushButton.SetAutoRepeating( true );
190
191   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
192   END_TEST;
193 }
194
195 int UtcDaliPushButtonSetGetTogglableButton(void)
196 {
197   ToolkitTestApplication application;
198   tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
199
200   PushButton pushButton = PushButton::New();
201
202   pushButton.SetTogglableButton( true );
203
204   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
205
206   pushButton.SetTogglableButton( false );
207
208   DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
209
210   pushButton.SetTogglableButton( true );
211
212   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
213   END_TEST;
214 }
215
216 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
217 {
218   ToolkitTestApplication application;
219   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
220
221   PushButton pushButton = PushButton::New();
222
223   pushButton.SetAutoRepeating( true );
224   pushButton.SetTogglableButton( true );
225
226   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
227   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
228
229   pushButton.SetTogglableButton( true );
230   pushButton.SetAutoRepeating( true );
231
232   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
233   DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
234   END_TEST;
235 }
236
237 int UtcDaliPushButtonSetGetSelected01(void)
238 {
239   ToolkitTestApplication application;
240   tet_infoline(" UtcDaliPushButtonSetGetSelected01");
241
242   PushButton pushButton = PushButton::New();
243
244   pushButton.SetTogglableButton( true );
245   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
246
247   gPushButtonSelectedState = false;
248   pushButton.SetSelected( true );
249
250   DALI_TEST_CHECK( pushButton.IsSelected() );
251   DALI_TEST_CHECK( gPushButtonSelectedState );
252
253   pushButton.SetSelected( false );
254
255   DALI_TEST_CHECK( !pushButton.IsSelected() );
256   DALI_TEST_CHECK( !gPushButtonSelectedState );
257
258   pushButton.SetSelected( true );
259
260   DALI_TEST_CHECK( pushButton.IsSelected() );
261   DALI_TEST_CHECK( gPushButtonSelectedState );
262   END_TEST;
263 }
264
265 int UtcDaliPushButtonSetGetSelected02(void)
266 {
267   ToolkitTestApplication application;
268   tet_infoline(" UtcDaliPushButtonSetGetSelected02");
269
270   PushButton pushButton = PushButton::New();
271
272   pushButton.SetTogglableButton( false );
273   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
274
275   gPushButtonSelectedState = false;
276   pushButton.SetSelected( true );
277
278   DALI_TEST_CHECK( !pushButton.IsSelected() );
279   DALI_TEST_CHECK( !gPushButtonSelectedState );
280
281   pushButton.SetSelected( false );
282
283   DALI_TEST_CHECK( !pushButton.IsSelected() );
284   DALI_TEST_CHECK( !gPushButtonSelectedState );
285
286   pushButton.SetSelected( true );
287
288   DALI_TEST_CHECK( !pushButton.IsSelected() );
289   DALI_TEST_CHECK( !gPushButtonSelectedState );
290   END_TEST;
291 }
292
293 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
294 {
295   ToolkitTestApplication application;
296   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
297
298   PushButton pushButton = PushButton::New();
299
300   pushButton.SetAutoRepeating( true );
301
302   pushButton.SetInitialAutoRepeatingDelay( 1.f );
303   DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
304
305   pushButton.SetNextAutoRepeatingDelay( 1.f );
306   DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
307   END_TEST;
308 }
309
310 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
311 {
312   ToolkitTestApplication application;
313   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
314
315   PushButton pushButton = PushButton::New();
316
317   bool assert1( false );
318   bool assert2( false );
319
320   pushButton.SetAutoRepeating( true );
321
322   try
323   {
324     pushButton.SetInitialAutoRepeatingDelay( -1.f );
325   }
326   catch( Dali::DaliException& e )
327   {
328     DALI_TEST_PRINT_ASSERT( e );
329     DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
330     assert1 = true;
331   }
332
333   try
334   {
335     pushButton.SetNextAutoRepeatingDelay( -1.f );
336   }
337   catch( Dali::DaliException& e )
338   {
339     DALI_TEST_PRINT_ASSERT( e );
340     DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
341     assert2 = true;
342   }
343
344   DALI_TEST_CHECK( assert1 && assert2 );
345   END_TEST;
346 }
347
348 int UtcDaliPushButtonSetLabelText(void)
349 {
350   ToolkitTestApplication application;
351   tet_infoline(" UtcDaliPushButtonSetLabelText");
352
353   const std::string STR( "Hola!" );
354
355   PushButton pushButton = PushButton::New();
356
357   application.SendNotification();
358   application.Render();
359
360   pushButton.SetLabelText( STR );
361
362   DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
363
364   END_TEST;
365 }
366
367 int UtcDaliPushButtonPressed(void)
368 {
369   ToolkitTestApplication application;
370   tet_infoline(" UtcDaliPushButtonPressed");
371
372   PushButton pushButton = PushButton::New();
373   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
374   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
375   pushButton.SetPosition( 240, 400 );
376   pushButton.SetSize( 100, 100 );
377
378   Stage::GetCurrent().Add( pushButton );
379
380   application.SendNotification();
381   application.Render();
382
383   gPushButtonPressed = false;
384
385   // connect to its touch signal
386   pushButton.PressedSignal().Connect( &PushButtonPressed );
387
388   Dali::Integration::TouchEvent eventDown;
389   eventDown.AddPoint( pointDownInside );
390
391   // flush the queue and render once
392   application.SendNotification();
393   application.Render();
394   application.ProcessEvent( eventDown );
395
396   DALI_TEST_CHECK( gPushButtonPressed );
397   END_TEST;
398 }
399
400 int UtcDaliPushButtonReleased(void)
401 {
402   ToolkitTestApplication application;
403   tet_infoline(" UtcDaliPushButtonReleased");
404
405   PushButton pushButton = PushButton::New();
406   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
407   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
408   pushButton.SetPosition( 240, 400 );
409   pushButton.SetSize( 100, 100 );
410
411   Stage::GetCurrent().Add( pushButton );
412
413   application.SendNotification();
414   application.Render();
415
416   // connect to its touch signal
417   pushButton.ReleasedSignal().Connect( &PushButtonReleased );
418
419   Dali::Integration::TouchEvent event;
420
421   // Test1. Touch point down and up inside the button.
422
423   gPushButtonReleased = false;
424   event = Dali::Integration::TouchEvent();
425   event.AddPoint( pointDownInside );
426   application.ProcessEvent( event );
427
428   event = Dali::Integration::TouchEvent();
429   event.AddPoint( pointUpInside );
430   application.ProcessEvent( event );
431
432   DALI_TEST_CHECK( gPushButtonReleased );
433
434   // Test2. Touch point down and up outside the button.
435
436   gPushButtonReleased = false;
437   event = Dali::Integration::TouchEvent();
438   event.AddPoint( pointDownOutside );
439   application.ProcessEvent( event );
440
441   event = Dali::Integration::TouchEvent();
442   event.AddPoint( pointUpOutside );
443   application.ProcessEvent( event );
444
445   DALI_TEST_CHECK( !gPushButtonReleased );
446
447   // Test3. Touch point down inside and up outside the button.
448
449   gPushButtonReleased = false;
450   event = Dali::Integration::TouchEvent();
451   event.AddPoint( pointDownInside );
452   application.ProcessEvent( event );
453
454   event = Dali::Integration::TouchEvent();
455   event.AddPoint( pointLeave );
456   application.ProcessEvent( event );
457
458   event = Dali::Integration::TouchEvent();
459   event.AddPoint( pointUpOutside );
460   application.ProcessEvent( event );
461
462   DALI_TEST_CHECK( gPushButtonReleased );
463
464   // Test4. Touch point down outside and up inside the button.
465
466   gPushButtonReleased = false;
467   event = Dali::Integration::TouchEvent();
468   event.AddPoint( pointDownOutside );
469   application.ProcessEvent( event );
470
471   event = Dali::Integration::TouchEvent();
472   event.AddPoint( pointEnter );
473   application.ProcessEvent( event );
474
475   event = Dali::Integration::TouchEvent();
476   event.AddPoint( pointUpInside );
477   application.ProcessEvent( event );
478
479   DALI_TEST_CHECK( !gPushButtonReleased );
480   END_TEST;
481 }
482
483 int UtcDaliPushButtonSelected(void)
484 {
485   ToolkitTestApplication application;
486   tet_infoline(" UtcDaliPushButtonSelected");
487
488   PushButton pushButton = PushButton::New();
489   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
490   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
491   pushButton.SetPosition( 240, 400 );
492   pushButton.SetSize( 100, 100 );
493
494   Stage::GetCurrent().Add( pushButton );
495
496   application.SendNotification();
497   application.Render();
498
499   // connect to its touch signal
500   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
501
502   Dali::Integration::TouchEvent event;
503
504   // Test1. No togglable button.
505
506   gPushButtonSelectedState = false;
507   event = Dali::Integration::TouchEvent();
508   event.AddPoint( pointDownInside );
509   application.ProcessEvent( event );
510
511   event = Dali::Integration::TouchEvent();
512   event.AddPoint( pointUpInside );
513   application.ProcessEvent( event );
514
515   DALI_TEST_CHECK( !gPushButtonSelectedState );
516
517   // Set togglable property.
518   pushButton.SetTogglableButton( true );
519
520   // Test2. Touch point down and up inside the button twice.
521   gPushButtonSelectedState = false;
522   event = Dali::Integration::TouchEvent();
523   event.AddPoint( pointDownInside );
524   application.ProcessEvent( event );
525
526   event = Dali::Integration::TouchEvent();
527   event.AddPoint( pointUpInside );
528   application.ProcessEvent( event );
529
530   DALI_TEST_CHECK( gPushButtonSelectedState );
531
532   event = Dali::Integration::TouchEvent();
533   event.AddPoint( pointDownInside );
534   application.ProcessEvent( event );
535
536   event = Dali::Integration::TouchEvent();
537   event.AddPoint( pointUpInside );
538   application.ProcessEvent( event );
539
540   DALI_TEST_CHECK( !gPushButtonSelectedState );
541
542   // Test3. Touch point down and up outside the button.
543
544   gPushButtonSelectedState = false;
545   event = Dali::Integration::TouchEvent();
546   event.AddPoint( pointDownOutside );
547   application.ProcessEvent( event );
548
549   event = Dali::Integration::TouchEvent();
550   event.AddPoint( pointUpOutside );
551   application.ProcessEvent( event );
552
553   DALI_TEST_CHECK( !gPushButtonSelectedState );
554
555   // Test4. Touch point down inside and up outside the button.
556
557   gPushButtonSelectedState = false;
558   event = Dali::Integration::TouchEvent();
559   event.AddPoint( pointDownInside );
560   application.ProcessEvent( event );
561
562   event = Dali::Integration::TouchEvent();
563   event.AddPoint( pointLeave );
564   application.ProcessEvent( event );
565
566   event = Dali::Integration::TouchEvent();
567   event.AddPoint( pointUpOutside );
568   application.ProcessEvent( event );
569
570   DALI_TEST_CHECK( !gPushButtonSelectedState );
571
572   // Test5. Touch point down outside and up inside the button.
573
574   gPushButtonSelectedState = false;
575   event = Dali::Integration::TouchEvent();
576   event.AddPoint( pointDownOutside );
577   application.ProcessEvent( event );
578
579   event = Dali::Integration::TouchEvent();
580   event.AddPoint( pointEnter );
581   application.ProcessEvent( event );
582
583   event = Dali::Integration::TouchEvent();
584   event.AddPoint( pointUpInside );
585   application.ProcessEvent( event );
586
587   DALI_TEST_CHECK( !gPushButtonSelectedState );
588   END_TEST;
589 }
590
591 int UtcDaliPushButtonPropertySetIconAlignment(void)
592 {
593   ToolkitTestApplication application;
594   tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
595
596   PushButton pushButton = PushButton::New();
597   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
598   DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
599
600   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
601   DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
602
603   END_TEST;
604 }
605
606 int UtcDaliPushButtonPropertySetLabelPadding(void)
607 {
608   ToolkitTestApplication application;
609   tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
610
611   PushButton pushButton = PushButton::New();
612   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
613   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 );
614
615   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
616   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 );
617
618   END_TEST;
619 }
620
621 int UtcDaliPushButtonPropertySetIconPadding(void)
622 {
623   ToolkitTestApplication application;
624   tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
625
626   PushButton pushButton = PushButton::New();
627   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
628   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 );
629
630   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
631   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 );
632
633   END_TEST;
634 }
635
636 int UtcDaliPushButtonPaddingLayout(void)
637 {
638   ToolkitTestApplication application;
639   tet_infoline(" UtcDaliPushButtonPaddingLayout");
640
641   // This test creates padding for an icon and a label.
642   // The icon and label are each enabled and disabled to confirm the correct padding is used.
643   PushButton pushButton = PushButton::New();
644
645   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
646   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
647
648   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
649   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
650   pushButton.SetPosition( 0.0f, 0.0f );
651   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
652
653   Stage::GetCurrent().Add( pushButton );
654
655   application.SendNotification();
656   application.Render();
657
658   // First test the size is zero.
659   // No padding should be added as there is no label or icon.
660   Vector2 size( Vector2::ZERO );
661   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
662   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
663
664   DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
665
666   // Check label only padding.
667   pushButton.SetLabelText( "Label" );
668
669   application.SendNotification();
670   application.Render();
671
672   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
673   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
674
675   // 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.
676   DALI_TEST_GREATER( size.width, 20.0f, TEST_LOCATION );
677   DALI_TEST_GREATER( size.height, 20.0f, TEST_LOCATION );
678
679   // Re-initialise the button so we can setup icon-only padding.
680   pushButton.Unparent();
681   pushButton = PushButton::New();
682
683   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
684   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 20.0f, 20.0f, 20.0f, 20.0f ) );
685
686   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
687   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
688   pushButton.SetPosition( 0.0f, 0.0f );
689   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
690
691   Stage::GetCurrent().Add( pushButton );
692
693   const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
694   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
695   pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
696   pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
697
698   application.SendNotification();
699   application.Render();
700
701   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
702   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
703
704   DALI_TEST_EQUALS( size, Vector2( 40.0f, 40.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
705
706   // Now test padding for both label and icon simultaneously.
707   pushButton.SetLabelText( "Label" );
708
709   application.SendNotification();
710   application.Render();
711
712   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
713   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
714
715   // 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.
716   // Note we only test the width as we are horizontally aligned and the label my be less high than the icon.
717   // Full directional alignment tests are done in UtcDaliPushButtonAlignmentLayout.
718   DALI_TEST_GREATER( size.width, 60.0f, TEST_LOCATION );
719
720   END_TEST;
721 }
722
723 int UtcDaliPushButtonAlignmentLayout(void)
724 {
725   ToolkitTestApplication application;
726   tet_infoline(" UtcDaliPushButtonAlignmentLayout");
727
728   // This test checks different alignments for the icon against the label.
729   // The icon is then moved around the label in each of it's alignments.
730   // The final relayed out size is checked to confirm the layout has been done correctly.
731   PushButton pushButton = PushButton::New();
732
733   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 30.0f, 30.0f, 30.0f, 30.0f ) );
734   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 75.0f, 75.0f, 75.0f, 75.0f ) );
735
736   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
737   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
738   pushButton.SetPosition( 0.0f, 0.0f );
739   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
740
741   Stage::GetCurrent().Add( pushButton );
742
743   const char* INVALID_IMAGE_FILE_NAME = "invalid-image.jpg";
744   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
745   pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, INVALID_IMAGE_FILE_NAME );
746   pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, INVALID_IMAGE_FILE_NAME );
747
748   application.SendNotification();
749   application.Render();
750
751   // First get the base size (without label).
752   Vector2 baseSize( Vector2::ZERO );
753   baseSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
754   baseSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
755
756   DALI_TEST_EQUALS( baseSize, Vector2( 150.0f, 150.0f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
757
758   // Add a label to cause size to be modified in the direction of alignment.
759   pushButton.SetLabelText( "Label" );
760
761   application.SendNotification();
762   application.Render();
763
764   Vector2 size( Vector2::ZERO );
765   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
766   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
767
768   DALI_TEST_GREATER( size.width, 150.0f + 60.0f, TEST_LOCATION );
769   DALI_TEST_EQUALS( size.height, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
770
771   // Now test left alignment matches right for size.
772   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
773
774   application.SendNotification();
775   application.Render();
776
777   Vector2 compareSize( Vector2::ZERO );
778   compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
779   compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
780
781   DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
782
783   // Test top alignment.
784   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
785
786   application.SendNotification();
787   application.Render();
788
789   compareSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
790   compareSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
791
792   DALI_TEST_EQUALS( compareSize.width, 150.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
793   DALI_TEST_GREATER( compareSize.height, 150.0f + 60.0f, TEST_LOCATION );
794
795   // Test bottom alignment.
796   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
797
798   application.SendNotification();
799   application.Render();
800
801   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
802   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
803
804   DALI_TEST_EQUALS( size, compareSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
805
806   END_TEST;
807 }