Text Selection Popup and Radio Button fix and tests uses Button::Properties
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-PushButton.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali.h>
26 #include <dali/integration-api/events/touch-event-integ.h>
27 #include <dali-toolkit/dali-toolkit.h>
28
29 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
30 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
31 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
32
33 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.SetAnchorPoint( AnchorPoint::TOP_LEFT );
137   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
138   button.SetPosition( 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::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, TEST_IMAGE_ONE );
145     button.SetProperty( Toolkit::DevelButton::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::DevelVisual::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.SetAnchorPoint( AnchorPoint::TOP_LEFT );
468   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
469   pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
470   pushButton.SetSize( 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.SetAnchorPoint( AnchorPoint::TOP_LEFT );
501   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
502   pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
503   pushButton.SetSize( 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.SetAnchorPoint( AnchorPoint::TOP_LEFT );
584   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
585   pushButton.SetPosition( BUTTON_POSITON_TO_GET_INSIDE_TOUCH_EVENTS );
586   pushButton.SetSize( 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 UtcDaliPushButtonPropertySetIconAlignment(void)
690 {
691   ToolkitTestApplication application;
692   tet_infoline(" UtcDaliPushButtonPropertySetIconAlignment");
693
694   PushButton pushButton = PushButton::New();
695   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
696   DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "TOP", TEST_LOCATION );
697
698   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
699   DALI_TEST_EQUALS( pushButton.GetProperty<std::string>( Toolkit::PushButton::Property::ICON_ALIGNMENT ), "RIGHT", TEST_LOCATION );
700
701   END_TEST;
702 }
703
704 int UtcDaliPushButtonPropertySetLabelPadding(void)
705 {
706   ToolkitTestApplication application;
707   tet_infoline(" UtcDaliPushButtonPropertySetLabelPadding");
708
709   PushButton pushButton = PushButton::New();
710   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
711   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 );
712
713   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
714   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 );
715
716   END_TEST;
717 }
718
719 int UtcDaliPushButtonPropertySetIconPadding(void)
720 {
721   ToolkitTestApplication application;
722   tet_infoline(" UtcDaliPushButtonPropertySetIconPadding");
723
724   PushButton pushButton = PushButton::New();
725   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) );
726   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 );
727
728   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, Vector4( 10.0f, 10.0f, 10.0f, 10.0f ) );
729   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 );
730
731   END_TEST;
732 }
733
734 int UtcDaliPushButtonPaddingLayout(void)
735 {
736   ToolkitTestApplication application;
737   tet_infoline(" UtcDaliPushButtonPaddingLayout");
738
739   // This test creates padding for an icon and a label.
740   // The icon and label are each enabled and disabled to confirm the correct padding is used.
741   PushButton pushButton = PushButton::New();
742
743   const Vector4 TEST_ICON_PADDING( 20.0f, 20.0f, 20.0f, 20.0f );
744   const Vector4 TEST_LABEL_PADDING( 10.0f, 10.0f, 10.0f ,10.0f );
745   const Vector2 TEST_IMAGE_SIZE = Vector2( 5.0f, 5.0f);
746
747   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
748   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
749   pushButton.SetPosition( 0.0f, 0.0f );
750   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
751
752   Stage::GetCurrent().Add( pushButton );
753
754   application.SendNotification();
755   application.Render();
756
757   // First test the size is zero.
758   // No padding should be added as there is no label or icon.
759   Vector2 size( Vector2::ZERO );
760   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
761   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
762   tet_printf( "Button Natural Size(%f,%f)\n", pushButton.GetNaturalSize().width, pushButton.GetNaturalSize().height );
763
764   DALI_TEST_EQUALS( size, Vector2::ZERO, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
765
766   // Check label only padding
767   pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
768
769   application.SendNotification();
770   application.Render();
771
772   Vector2 sizeWithLabelWithoutPadding( Vector2::ZERO );
773   sizeWithLabelWithoutPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
774   sizeWithLabelWithoutPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
775
776   tet_printf( "Button RelayoutSize label without padding (%f,%f)\n", sizeWithLabelWithoutPadding.width, sizeWithLabelWithoutPadding.height );
777
778   // Add label padding to label
779   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
780   application.SendNotification();
781   application.Render();
782
783   Vector2 sizeLabelAndPadding( Vector2::ZERO );
784   sizeLabelAndPadding.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
785   sizeLabelAndPadding.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
786   tet_printf( "Button RelayoutSize after label padding(%f,%f)\n", sizeLabelAndPadding.width, sizeLabelAndPadding.height );
787
788   // If control size has increased beyond size of just label then padding has been applied
789   DALI_TEST_GREATER( sizeLabelAndPadding.width, sizeWithLabelWithoutPadding.width+TEST_LABEL_PADDING.x, TEST_LOCATION );
790   DALI_TEST_GREATER( sizeLabelAndPadding.height, sizeWithLabelWithoutPadding.height+TEST_LABEL_PADDING.w, TEST_LOCATION );
791
792   // Re-initialise the button so we can setup icon-only padding.
793   pushButton.Unparent();
794   pushButton = PushButton::New();
795
796   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
797   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
798   pushButton.SetPosition( 0.0f, 0.0f );
799   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
800
801   Stage::GetCurrent().Add( pushButton );
802
803   TestPlatformAbstraction& platform = application.GetPlatform();
804   platform.SetClosestImageSize( TEST_IMAGE_SIZE );
805
806   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
807   pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
808   pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
809
810   application.SendNotification();
811   application.Render();
812
813   // Size of button with just icon
814   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
815   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
816   tet_printf( "Button RelayoutSize with icon(%f,%f)\n", size.width, size.height );
817
818   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
819
820   application.SendNotification();
821   application.Render();
822   DALI_TEST_EQUALS( size, TEST_IMAGE_SIZE, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
823
824   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
825   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
826   tet_printf( "Button RelayoutSize after icon padding(%f,%f)\n", size.width, size.height );
827   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 );
828   DALI_TEST_EQUALS( size, expectedIconAndPaddingSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
829
830   // Now test padding for both label and icon simultaneously.
831   pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
832
833   application.SendNotification();
834   application.Render();
835
836   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
837   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
838   tet_printf( "Button RelayoutSize after label added(%f,%f)\n", size.width, size.height );
839
840   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
841
842   application.SendNotification();
843   application.Render();
844
845   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
846   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
847   tet_printf( "Button RelayoutSize after icon and label padding(%f,%f)\n", size.width, size.height );
848
849   DALI_TEST_EQUALS( size.width, sizeLabelAndPadding.width + expectedIconAndPaddingSize.width, TEST_LOCATION );
850   DALI_TEST_GREATER( size.height, expectedIconAndPaddingSize.width, TEST_LOCATION ); // Test height of control is greater than icon and padding. As Text set to larger values.
851
852   END_TEST;
853 }
854
855 int UtcDaliPushButtonAlignmentLayout(void)
856 {
857   ToolkitTestApplication application;
858   tet_infoline(" UtcDaliPushButtonAlignmentLayout");
859
860   /*
861    * This test checks different alignments for the icon against the label.
862    * The icon is then moved around the label in each of it's alignments.
863    * The final relayed out size is checked to confirm the layout has been done correctly.
864    *
865    * There is an Icon which has 0 width and height, but with 75 padding on all sides.
866    *  - Therefore total width and height are both 150.
867    *
868    * There is a Label which has "an unknown" width and height, but with 30 padding on all sides.
869    *  - Therefore total width and height are 60+x and 60+y respectively.
870    *    Where x & y are the width and height of the text.
871    *
872    * The width of the button will always expand to the largest of the icon and label sizes (plus padding).
873    * So We use the padding to help us determine the orientation is correct for each alignment.
874    *
875    * |<- 150 ->|         |<-- 60+x -->|
876    *
877    * +---------+   -
878    * |         |   ^     +------------+   -
879    * |         |   |     |            |   ^
880    * |  Icon   |  150    |   Label    |  60+y
881    * |         |   |     |            |   v
882    * |         |   v     +------------+   -
883    * +---------+   -
884    */
885
886   const Vector4 TEST_ICON_PADDING( 70.0f, 70.0f, 70.0f, 70.0f );
887   const Vector4 TEST_LABEL_PADDING( 30.0f, 30.0f, 30.0f, 30.0f );
888   const Vector2 TEST_IMAGE_SIZE = Vector2( 10.0f, 10.0f);
889
890   PushButton pushButton = PushButton::New();
891
892   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
893   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
894   pushButton.SetPosition( 0.0f, 0.0f );
895   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
896
897   Stage::GetCurrent().Add( pushButton );
898
899   // Add a label and get size of control
900   pushButton.SetProperty( Toolkit::Button::Property::LABEL, "Label" );
901   application.SendNotification();
902   application.Render();
903
904   // First get the size of control with just label
905   Vector2 justLabelSize( Vector2::ZERO );
906   justLabelSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
907   justLabelSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
908   tet_printf( "Button RelayoutSize with just label and no padding(%f,%f)\n", justLabelSize.width, justLabelSize.height );
909
910   pushButton.SetProperty( Toolkit::PushButton::Property::LABEL_PADDING, TEST_LABEL_PADDING );
911   application.SendNotification();
912   application.Render();
913
914   // Size of Label and Padding
915   Vector2 expectedLabelAndPaddingSize( Vector2::ZERO );
916   expectedLabelAndPaddingSize.width = justLabelSize.width + TEST_LABEL_PADDING.x + TEST_LABEL_PADDING.y;
917   expectedLabelAndPaddingSize.height = justLabelSize.height + TEST_LABEL_PADDING.w + TEST_LABEL_PADDING.z;
918
919   Vector2 labelAndPaddingSize( Vector2::ZERO );
920   labelAndPaddingSize.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
921   labelAndPaddingSize.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
922
923   DALI_TEST_EQUALS( labelAndPaddingSize, expectedLabelAndPaddingSize , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
924
925   const Vector2 testImageWithPaddingSize = Vector2 ( ( TEST_IMAGE_SIZE.width + TEST_ICON_PADDING.x + TEST_ICON_PADDING.y ),
926                                                      ( TEST_IMAGE_SIZE.height + TEST_ICON_PADDING.w + TEST_ICON_PADDING.z ) );
927
928   TestPlatformAbstraction& platform = application.GetPlatform();
929   platform.SetClosestImageSize( TEST_IMAGE_SIZE );
930
931   // Add Icon and set its alignment
932   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "RIGHT" );
933   pushButton.SetProperty( Toolkit::PushButton::Property::UNSELECTED_ICON, TEST_IMAGE_ONE );
934   pushButton.SetProperty( Toolkit::PushButton::Property::SELECTED_ICON, TEST_IMAGE_ONE );
935   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_PADDING, TEST_ICON_PADDING );
936
937   application.SendNotification();
938   application.Render();
939
940   Vector2 size( Vector2::ZERO );
941   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
942   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
943
944   /*
945    * Test Icon right alignment.
946    * Height grows to largest of Icon or Label (+ padding).
947    * Normally this will be Icons height, except with very large font sizes.
948    *
949    *  +------------+---------+
950    *  |............+         |
951    *  |            |         |
952    *  |   Label    |  Icon   |
953    *  |            |         |
954    *  |............+         |
955    *  +------------+---------+
956    */
957   DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
958   DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
959
960   // Now test left alignment matches right for size.
961   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "LEFT" );
962
963   application.SendNotification();
964   application.Render();
965
966   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
967   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
968
969   /*
970    * Test Icon left alignment.
971    * Height grows to largest of Icon or Label (+ padding).
972    * Normally this will be Icons height, except with very large font sizes.
973    *
974    *  +---------+------------+
975    *  |         +............|
976    *  |         |            |
977    *  |  Icon   |   Label    |
978    *  |         |            |
979    *  |         +............|
980    *  +---------+------------+
981    */
982   DALI_TEST_EQUALS( size.width, ( testImageWithPaddingSize.width + labelAndPaddingSize.width ) , TEST_LOCATION );
983   DALI_TEST_EQUALS( size.height, ( std::max( testImageWithPaddingSize.height, labelAndPaddingSize.height) ) , Math::MACHINE_EPSILON_1000, TEST_LOCATION );
984
985   tet_infoline(" Test Icon TOP alignment - Width grows to largest of Icon or label (plus padding)");
986   /*
987    *
988    *  +---------+
989    *  |         |
990    *  |         |
991    *  |  Icon   |
992    *  |         |
993    *  |         |
994    *  +---------+
995    *  |         |
996    *  |  Label  |
997    *  |         |
998    *  +---------+
999    *
1000    */
1001
1002   tet_infoline("SetProperty on ICON_ALIGNMENT should relayout the Button");
1003   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "TOP" );
1004
1005   application.SendNotification();
1006   application.Render();
1007
1008   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1009   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1010
1011   tet_printf("Natural width (%f)\n",pushButton.GetNaturalSize().width);
1012   tet_printf("Natural height (%f)\n",pushButton.GetNaturalSize().height);
1013
1014   tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Image and Padding size (%f,%f)\n", testImageWithPaddingSize.width, testImageWithPaddingSize.height );
1015   tet_printf(" UtcDaliPushButtonAlignmentLayout Top layout - Text and Padding size (%f,%f)\n", labelAndPaddingSize.width, labelAndPaddingSize.height );
1016
1017   DALI_TEST_EQUALS( size.width, ( std::max( testImageWithPaddingSize.width, labelAndPaddingSize.width ) ) , TEST_LOCATION );
1018
1019   DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1020
1021   /*
1022    * Test Icon bottom alignment.
1023    * Width grows to largest of Icon or Label (+ padding).
1024    *
1025    *  +---------+
1026    *  |         |
1027    *  |  Label  |
1028    *  |         |
1029    *  +---------+
1030    *  |         |
1031    *  |         |
1032    *  |  Icon   |
1033    *  |         |
1034    *  |         |
1035    *  +---------+
1036    */
1037   tet_infoline(" Test Icon BOTTOM alignment - Width grows to largest of Icon or label (plus padding)");
1038   pushButton.SetProperty( Toolkit::PushButton::Property::ICON_ALIGNMENT, "BOTTOM" );
1039
1040   application.SendNotification();
1041   application.Render();
1042
1043   size.width = pushButton.GetRelayoutSize( Dimension::WIDTH );
1044   size.height = pushButton.GetRelayoutSize( Dimension::HEIGHT );
1045
1046   DALI_TEST_EQUALS( size.width, ( std::max(testImageWithPaddingSize.width, labelAndPaddingSize.width )) , TEST_LOCATION );
1047   DALI_TEST_EQUALS( size.height,( testImageWithPaddingSize.height + labelAndPaddingSize.height ) , TEST_LOCATION );
1048
1049   END_TEST;
1050 }
1051
1052 int UtcDaliPushButtonSetUnSelectedVisual01P(void)
1053 {
1054   tet_infoline(" Test adding a visual for the UNSELECTED_VISUAL property, removing Button from stage and counting renderers\n");
1055   ToolkitTestApplication application;
1056
1057   PushButton pushButton = PushButton::New();
1058   pushButton.SetSize( BUTTON_SIZE_TO_GET_INSIDE_TOUCH_EVENTS );
1059
1060   Stage::GetCurrent().Add( pushButton );
1061
1062   Property::Map propertyMap;
1063   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
1064   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1065
1066   pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, propertyMap );
1067
1068   tet_infoline(" UNSELECTED_VISUAL Added to button\n");
1069
1070   application.SendNotification();
1071   application.Render(0);
1072
1073   unsigned int rendererCount = pushButton.GetRendererCount();
1074   tet_printf("After adding UNSELECTED_BACKGROUND_VISUAL the renderer count is(%d)\n", rendererCount );
1075
1076   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1 , TEST_LOCATION );
1077
1078   tet_printf("Remove button from stage\n" );
1079
1080   Stage::GetCurrent().Remove( pushButton );
1081
1082   rendererCount = pushButton.GetRendererCount();
1083   tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1084
1085   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1086
1087   tet_printf("After removing pushbutton from stage the renderer count is(%d)\n ", rendererCount );
1088
1089   Property::Map propertyMap2;
1090   propertyMap2.Insert(Visual::Property::TYPE,  Visual::COLOR);
1091   propertyMap2.Insert(ColorVisual::Property::MIX_COLOR, Color::RED);
1092   pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, propertyMap2 );
1093
1094   tet_printf("Added UNSELECTED_VISUAL and add button back to Stage\n");
1095
1096   Stage::GetCurrent().Add( pushButton );
1097
1098   tet_printf("With UNSELECTED_BACKGROUND_VISUAL and UNSELECTED_ICON the renderer count is(%d)\n", pushButton.GetRendererCount() );
1099
1100   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 2, TEST_LOCATION );
1101
1102   END_TEST;
1103 }
1104
1105 int UtcDaliPushButtonSetSelectedVisualN(void)
1106 {
1107   tet_infoline(" Test adding a broken visual for the UNSELECTED_VISUAL property");
1108
1109   ToolkitTestApplication application;
1110
1111   PushButton pushButton = PushButton::New();
1112
1113   pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1114   pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
1115   pushButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
1116
1117   Stage::GetCurrent().Add( pushButton );
1118   application.SendNotification();
1119   application.Render(0);
1120
1121   unsigned int preRendererCount = pushButton.GetRendererCount();
1122   tet_printf("RendererCount prior to adding visual(%d)\n",preRendererCount);
1123   DALI_TEST_EQUALS( preRendererCount, 0, TEST_LOCATION );
1124
1125   Stage::GetCurrent().Remove( pushButton );
1126   application.SendNotification();
1127   application.Render(0);
1128
1129   Property::Map colorMap;
1130   const int BROKEN_VISUAL_TYPE = 999999999;
1131
1132   colorMap.Insert(Visual::Property::TYPE,  BROKEN_VISUAL_TYPE);
1133   colorMap.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
1134   colorMap.Insert(BorderVisual::Property::SIZE,  5.f);
1135   pushButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_VISUAL, colorMap );
1136
1137   Stage::GetCurrent().Add( pushButton );
1138   application.SendNotification();
1139   application.Render(0);
1140
1141   unsigned int postRendererCount  = pushButton.GetRendererCount();
1142   tet_printf("RendererCount post broken visual (%d)\n", postRendererCount);
1143   DALI_TEST_EQUALS( postRendererCount, 0, TEST_LOCATION );
1144
1145   END_TEST;
1146 }
1147
1148 int UtcDaliPushButtonSetButtonImageP(void)
1149 {
1150   ToolkitTestApplication application;
1151
1152   PushButton button = PushButton::New();
1153   Stage::GetCurrent().Add( button );
1154
1155   try
1156   {
1157     button.SetButtonImage( ImageView::New() );
1158     DALI_TEST_CHECK( true );
1159   }
1160   catch(...)
1161   {
1162     DALI_TEST_CHECK( false );
1163   }
1164
1165   END_TEST;
1166 }
1167
1168 int UtcDaliPushButtonSetBackgroundImageP(void)
1169 {
1170   ToolkitTestApplication application;
1171
1172   PushButton button = PushButton::New();
1173   Stage::GetCurrent().Add( button );
1174
1175   try
1176   {
1177     button.SetBackgroundImage( ImageView::New() );
1178     DALI_TEST_CHECK( true );
1179   }
1180   catch(...)
1181   {
1182     DALI_TEST_CHECK( false );
1183   }
1184
1185   END_TEST;
1186 }
1187
1188 int UtcDaliPushButtonSetSelectedImageP(void)
1189 {
1190   ToolkitTestApplication application;
1191
1192   PushButton button = PushButton::New();
1193   Stage::GetCurrent().Add( button );
1194
1195   try
1196   {
1197     button.SetSelectedImage( ImageView::New() );
1198     DALI_TEST_CHECK( true );
1199   }
1200   catch(...)
1201   {
1202     DALI_TEST_CHECK( false );
1203   }
1204
1205   END_TEST;
1206 }
1207
1208 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
1209 {
1210   ToolkitTestApplication application;
1211
1212   PushButton button = PushButton::New();
1213   Stage::GetCurrent().Add( button );
1214
1215   try
1216   {
1217     button.SetSelectedBackgroundImage( ImageView::New() );
1218     DALI_TEST_CHECK( true );
1219   }
1220   catch(...)
1221   {
1222     DALI_TEST_CHECK( false );
1223   }
1224
1225   END_TEST;
1226 }
1227
1228 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
1229 {
1230   ToolkitTestApplication application;
1231
1232   PushButton button = PushButton::New();
1233   Stage::GetCurrent().Add( button );
1234
1235   try
1236   {
1237     button.SetDisabledBackgroundImage( ImageView::New() );
1238     DALI_TEST_CHECK( true );
1239   }
1240   catch(...)
1241   {
1242     DALI_TEST_CHECK( false );
1243   }
1244
1245   END_TEST;
1246 }
1247
1248
1249 int UtcDaliPushButtonSetDisabledImageP(void)
1250 {
1251   ToolkitTestApplication application;
1252
1253   PushButton button = PushButton::New();
1254   Stage::GetCurrent().Add( button );
1255
1256   try
1257   {
1258     button.SetDisabledImage( ImageView::New() );
1259     DALI_TEST_CHECK( true );
1260   }
1261   catch(...)
1262   {
1263     DALI_TEST_CHECK( false );
1264   }
1265
1266   END_TEST;
1267 }
1268
1269 int UtcDaliPushButtonSetDisabledSelectedImageP(void)
1270 {
1271   ToolkitTestApplication application;
1272
1273   PushButton button = PushButton::New();
1274   Stage::GetCurrent().Add( button );
1275
1276   try
1277   {
1278     button.SetDisabledSelectedImage( ImageView::New() );
1279     DALI_TEST_CHECK( true );
1280   }
1281   catch(...)
1282   {
1283     DALI_TEST_CHECK( false );
1284   }
1285
1286   END_TEST;
1287 }
1288
1289 int UtcDaliPushButtonToggleSignalP(void)
1290 {
1291   ToolkitTestApplication application;
1292   tet_infoline(" UtcDaliButtonToggleSignalP Ensure Signals emitted");
1293
1294   PushButton button = PushButton::New();
1295   button.SetProperty( Button::Property::TOGGLABLE, true);
1296
1297   SetupButtonForTestTouchEvents( application, button, true );
1298
1299   Stage::GetCurrent().Add( button );
1300
1301   application.SendNotification();
1302   application.Render();
1303
1304   // connect to its signal
1305   button.ClickedSignal().Connect( &PushButtonClicked );
1306   gPushButtonClicked = false;
1307
1308   tet_infoline(" Touch down and up within button");
1309   Dali::Integration::TouchEvent event;
1310   event = Dali::Integration::TouchEvent();
1311   event.AddPoint( GetPointDownInside() );
1312   application.ProcessEvent( event );
1313
1314   event = Dali::Integration::TouchEvent();
1315   event.AddPoint( GetPointUpInside() );
1316   application.ProcessEvent( event );
1317
1318   DALI_TEST_EQUALS( gPushButtonClicked, true, TEST_LOCATION );
1319
1320   END_TEST;
1321 }
1322
1323 // Deprecated API Tests
1324
1325 int UtcDaliPushButtonSetGetAutoRepeating(void)
1326 {
1327   ToolkitTestApplication application;
1328   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
1329
1330   PushButton pushButton = PushButton::New();
1331
1332   pushButton.SetAutoRepeating( true );
1333
1334   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1335
1336   pushButton.SetAutoRepeating( false );
1337
1338   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1339
1340   pushButton.SetAutoRepeating( true );
1341
1342   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1343   END_TEST;
1344 }
1345
1346 int UtcDaliPushButtonSetGetTogglableButton(void)
1347 {
1348   ToolkitTestApplication application;
1349   tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
1350
1351   PushButton pushButton = PushButton::New();
1352
1353   pushButton.SetTogglableButton( true );
1354
1355   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1356
1357   pushButton.SetTogglableButton( false );
1358
1359   DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1360
1361   pushButton.SetTogglableButton( true );
1362
1363   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1364   END_TEST;
1365 }
1366
1367 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
1368 {
1369   ToolkitTestApplication application;
1370   tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
1371
1372   PushButton pushButton = PushButton::New();
1373
1374   pushButton.SetAutoRepeating( true );
1375   pushButton.SetTogglableButton( true );
1376
1377   DALI_TEST_CHECK( pushButton.IsTogglableButton() );
1378   DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
1379
1380   pushButton.SetTogglableButton( true );
1381   pushButton.SetAutoRepeating( true );
1382
1383   DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
1384   DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
1385   END_TEST;
1386 }
1387
1388 int UtcDaliPushButtonSetGetSelected01(void)
1389 {
1390   ToolkitTestApplication application;
1391   tet_infoline(" UtcDaliPushButtonSetGetSelected01");
1392
1393   PushButton pushButton = PushButton::New();
1394
1395   pushButton.SetTogglableButton( true );
1396   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1397
1398   gPushButtonSelectedState = false;
1399   pushButton.SetSelected( true );
1400
1401   DALI_TEST_CHECK( pushButton.IsSelected() );
1402   DALI_TEST_CHECK( gPushButtonSelectedState );
1403
1404   pushButton.SetSelected( false );
1405
1406   DALI_TEST_CHECK( !pushButton.IsSelected() );
1407   DALI_TEST_CHECK( !gPushButtonSelectedState );
1408
1409   pushButton.SetSelected( true );
1410
1411   DALI_TEST_CHECK( pushButton.IsSelected() );
1412   DALI_TEST_CHECK( gPushButtonSelectedState );
1413   END_TEST;
1414 }
1415
1416 int UtcDaliPushButtonSetGetSelected02(void)
1417 {
1418   ToolkitTestApplication application;
1419   tet_infoline(" UtcDaliPushButtonSetGetSelected02");
1420
1421   PushButton pushButton = PushButton::New();
1422
1423   pushButton.SetTogglableButton( false );
1424   pushButton.StateChangedSignal().Connect( &PushButtonSelected );
1425
1426   gPushButtonSelectedState = false;
1427   pushButton.SetSelected( true );
1428
1429   DALI_TEST_CHECK( !pushButton.IsSelected() );
1430   DALI_TEST_CHECK( !gPushButtonSelectedState );
1431
1432   pushButton.SetSelected( false );
1433
1434   DALI_TEST_CHECK( !pushButton.IsSelected() );
1435   DALI_TEST_CHECK( !gPushButtonSelectedState );
1436
1437   pushButton.SetSelected( true );
1438
1439   DALI_TEST_CHECK( !pushButton.IsSelected() );
1440   DALI_TEST_CHECK( !gPushButtonSelectedState );
1441   END_TEST;
1442 }
1443
1444 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
1445 {
1446   ToolkitTestApplication application;
1447   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
1448
1449   PushButton pushButton = PushButton::New();
1450
1451   pushButton.SetAutoRepeating( true );
1452
1453   pushButton.SetInitialAutoRepeatingDelay( 1.f );
1454   DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1455
1456   pushButton.SetNextAutoRepeatingDelay( 1.f );
1457   DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
1458   END_TEST;
1459 }
1460
1461 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
1462 {
1463   ToolkitTestApplication application;
1464   tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
1465
1466   PushButton pushButton = PushButton::New();
1467
1468   bool assert1( false );
1469   bool assert2( false );
1470
1471   pushButton.SetAutoRepeating( true );
1472
1473   try
1474   {
1475     pushButton.SetInitialAutoRepeatingDelay( -1.f );
1476   }
1477   catch( Dali::DaliException& e )
1478   {
1479     DALI_TEST_PRINT_ASSERT( e );
1480     DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
1481     assert1 = true;
1482   }
1483
1484   try
1485   {
1486     pushButton.SetNextAutoRepeatingDelay( -1.f );
1487   }
1488   catch( Dali::DaliException& e )
1489   {
1490     DALI_TEST_PRINT_ASSERT( e );
1491     DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
1492     assert2 = true;
1493   }
1494
1495   DALI_TEST_CHECK( assert1 && assert2 );
1496   END_TEST;
1497 }
1498
1499 int UtcDaliPushButtonSetLabelText(void)
1500 {
1501   ToolkitTestApplication application;
1502   tet_infoline(" UtcDaliPushButtonSetLabelText");
1503
1504   const std::string STR( "Hola!" );
1505
1506   PushButton pushButton = PushButton::New();
1507
1508   pushButton.SetProperty( Toolkit::Button::Property::LABEL,
1509                           Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
1510                                          .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1511                         );
1512
1513   application.SendNotification();
1514   application.Render();
1515
1516   pushButton.SetLabelText( STR );
1517
1518   DALI_TEST_EQUALS( pushButton.GetLabelText(), STR, TEST_LOCATION );
1519
1520   END_TEST;
1521 }