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