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