Fix for TextSelectionToolbar overshootEffectColor styling
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Button.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 #include "dali-toolkit-test-utils/toolkit-timer.h"
25
26 #include <dali.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali/integration-api/events/touch-event-integ.h>
29
30 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
31 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
32 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
33
34 using namespace Dali;
35 using namespace Toolkit;
36
37
38 void utc_dali_toolkit_button_startup(void)
39 {
40   test_return_value = TET_UNDEF;
41 }
42
43 void utc_dali_toolkit_button_cleanup(void)
44 {
45   test_return_value = TET_PASS;
46 }
47
48 namespace
49 {
50 static const char* TEST_IMAGE_ONE = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
51
52 static bool gIsCalledButtonCallback = false;
53
54 const int RENDER_FRAME_INTERVAL = 16;
55
56 static bool ButtonCallback( Button button )
57 {
58   gIsCalledButtonCallback = true;
59   return false;
60 }
61
62 static std::string GetButtonText( Button button )
63 {
64   Property::Value value = button.GetProperty( Toolkit::Button::Property::LABEL );
65
66   Property::Map *labelProperty = value.GetMap();
67
68   std::string textLabel;
69
70   if ( labelProperty )
71   {
72     Property::Value* value = labelProperty->Find( Toolkit::TextVisual::Property::TEXT );
73     value->Get( textLabel );
74   }
75
76   return textLabel;
77 }
78
79 struct CallbackFunctor
80 {
81   CallbackFunctor(bool* callbackFlag)
82   : mCallbackFlag( callbackFlag )
83   {
84   }
85
86   void operator()()
87   {
88     *mCallbackFlag = true;
89   }
90   bool* mCallbackFlag;
91 };
92
93 Dali::Integration::Point GetPointDownInside()
94 {
95   Dali::Integration::Point point;
96   point.SetState( PointState::DOWN );
97   point.SetScreenPosition( Vector2( 240, 400 ) );
98   return point;
99 }
100
101 Dali::Integration::Point GetPointUpInside()
102 {
103   Dali::Integration::Point point;
104   point.SetState( PointState::UP );
105   point.SetScreenPosition( Vector2( 240, 400 ) );
106   return point;
107 }
108
109 Dali::Integration::Point GetPointLeave()
110 {
111   Dali::Integration::Point point;
112   point.SetState( PointState::LEAVE );
113   point.SetScreenPosition( Vector2( 240, 400 ) );
114   return point;
115 }
116
117 Dali::Integration::Point GetPointEnter()
118 {
119   Dali::Integration::Point point;
120   point.SetState( PointState::MOTION );
121   point.SetScreenPosition( Vector2( 240, 400 ) );
122   return point;
123 }
124
125 Dali::Integration::Point GetPointDownOutside()
126 {
127   Dali::Integration::Point point;
128   point.SetState( PointState::DOWN );
129   point.SetScreenPosition( Vector2( 10, 10 ) );
130   return point;
131 }
132
133 Dali::Integration::Point GetPointUpOutside()
134 {
135   Dali::Integration::Point point;
136   point.SetState( PointState::UP );
137   point.SetScreenPosition( Vector2( 10, 10 ) );
138   return point;
139 }
140
141 static float ANIMATION_TIME( 0.5f );
142
143 } // namespace
144
145 int UtcDaliButtonConstructorP(void)
146 {
147   TestApplication application;
148
149   Button button;
150
151   DALI_TEST_CHECK( !button );
152   END_TEST;
153 }
154
155 int UtcDaliButtonCopyConstructorP(void)
156 {
157   TestApplication application;
158
159   // Initialize an object, ref count == 1
160   Button button = PushButton::New();
161
162   Button copy( button );
163   DALI_TEST_CHECK( copy );
164   END_TEST;
165 }
166
167 int UtcDaliButtonAssignmentOperatorP(void)
168 {
169   TestApplication application;
170
171   Button button = PushButton::New();
172
173   Button copy( button );
174   DALI_TEST_CHECK( copy );
175
176   DALI_TEST_CHECK( button == copy );
177   END_TEST;
178 }
179
180 int UtcDaliButtonDownCastP(void)
181 {
182   TestApplication application;
183
184   Button button = PushButton::New();
185
186   BaseHandle object(button);
187
188   Button button2 = Button::DownCast( object );
189   DALI_TEST_CHECK(button2);
190
191   Button button3 = DownCast< Button >(object);
192   DALI_TEST_CHECK(button3);
193   END_TEST;
194 }
195
196 int UtcDaliButtonDownCastN(void)
197 {
198   TestApplication application;
199
200   BaseHandle unInitializedObject;
201
202   Button button1 = Button::DownCast( unInitializedObject );
203   DALI_TEST_CHECK( !button1 );
204
205   Button button2 = DownCast< Button >( unInitializedObject );
206   DALI_TEST_CHECK( !button2 );
207   END_TEST;
208 }
209
210 int UtcDaliButtonSetDisabledP(void)
211 {
212   ToolkitTestApplication application;
213
214   Button button = PushButton::New();
215
216   button.SetDisabled( true );
217
218   DALI_TEST_CHECK( button.IsDisabled() );
219
220   button.SetDisabled( false );
221
222   DALI_TEST_CHECK( !button.IsDisabled() );
223
224   button.SetDisabled( true );
225
226   DALI_TEST_CHECK( button.IsDisabled() );
227
228   button.SetDisabled( false );
229
230   DALI_TEST_CHECK( !button.IsDisabled() );
231   END_TEST;
232 }
233
234 int UtcDaliButtonSetDisabledWithDifferentStates01P(void)
235 {
236   ToolkitTestApplication application;
237
238   tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates01P\n");
239
240   Button button = PushButton::New();
241
242   bool SELECTED = true;
243
244   button.SetProperty( Button::Property::TOGGLABLE, true);
245   button.SetProperty( Button::Property::SELECTED, SELECTED );
246
247   button.SetProperty( Button::Property::DISABLED, true);
248
249   tet_infoline("Set button to SELECTED = false whilst disabled, should not change to false\n");
250   button.SetProperty( Button::Property::SELECTED, !SELECTED );
251
252   bool isSelected = button.GetProperty<bool>( Button::Property::SELECTED ) ;
253
254   DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
255
256   END_TEST;
257 }
258
259 int UtcDaliButtonSetDisabledWithDifferentStates02P(void)
260 {
261   ToolkitTestApplication application;
262
263   tet_infoline("UtcDaliButtonSetDisabledWithDifferentStates02\n");
264
265   Button button = PushButton::New();
266
267   bool SELECTED = true;
268
269   button.SetProperty( Button::Property::TOGGLABLE, true );
270   button.SetProperty( Button::Property::SELECTED, SELECTED );
271   button.SetProperty( Button::Property::DISABLED, true );
272
273   bool isSelected =  button.GetProperty<bool>( Button::Property::SELECTED );
274   DALI_TEST_EQUALS( isSelected, SELECTED , TEST_LOCATION );
275   tet_infoline("Set button to DISABLED = false whilst disabled and then set to unselected\n");
276
277   button.SetProperty( Button::Property::DISABLED, false );
278   button.SetProperty( Button::Property::SELECTED, !SELECTED );
279
280   isSelected = button.GetProperty<bool>( Button::Property::SELECTED );
281   DALI_TEST_EQUALS( isSelected, !SELECTED , TEST_LOCATION );
282
283   END_TEST;
284 }
285
286 int UtcDaliButtonPropertyGetLabelAlignment(void)
287 {
288   ToolkitTestApplication application;
289   tet_infoline(" UtcDaliPushButtonPropertyGetLabelAlignment\n");
290
291   Button button = PushButton::New();
292   button.SetProperty( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT, "END"  );
293   DALI_TEST_EQUALS( button.GetProperty<std::string>( Toolkit::DevelButton::Property::LABEL_RELATIVE_ALIGNMENT ), "END", TEST_LOCATION );
294
295   END_TEST;
296 }
297
298 int UtcDaliButtonIsDisabledP(void)
299 {
300   ToolkitTestApplication application;
301
302   Button button = PushButton::New();
303
304   button.SetDisabled( true );
305
306   DALI_TEST_CHECK( button.IsDisabled() );
307
308   button.SetDisabled( false );
309
310   DALI_TEST_CHECK( !button.IsDisabled() );
311   END_TEST;
312 }
313
314 int UtcDaliButtonSetAutoRepeatingP(void)
315 {
316   ToolkitTestApplication application;
317
318   Button button = PushButton::New();
319
320   button.SetAutoRepeating( true );
321
322   DALI_TEST_CHECK( button.IsAutoRepeating() );
323
324   button.SetAutoRepeating( false );
325
326   DALI_TEST_CHECK( !button.IsAutoRepeating() );
327
328   button.SetAutoRepeating( true );
329
330   DALI_TEST_CHECK( button.IsAutoRepeating() );
331
332   button.SetAutoRepeating( false );
333
334   DALI_TEST_CHECK( !button.IsAutoRepeating() );
335   END_TEST;
336 }
337
338 int UtcDaliButtonIsAutoRepeatingP(void)
339 {
340   ToolkitTestApplication application;
341
342   Button button = PushButton::New();
343
344   button.SetAutoRepeating( true );
345
346   DALI_TEST_CHECK( button.IsAutoRepeating() );
347
348   button.SetAutoRepeating( false );
349
350   DALI_TEST_CHECK( !button.IsAutoRepeating() );
351   END_TEST;
352 }
353
354 int UtcDaliButtonAutoRepeatingP(void)
355 {
356   ToolkitTestApplication application;
357   tet_infoline(" UtcDaliButtonPressedSignalP  Setup Autorepeating and check multiple clicked signals received\n");
358
359   const float AUTO_REPEATING_DELAY = 0.15f;
360
361   Button button = PushButton::New();
362   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
363   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
364   button.SetPosition( 240, 400 );
365   button.SetSize( 100, 100 );
366   Stage::GetCurrent().Add( button );
367
368   application.SendNotification();
369   application.Render();
370
371   button.SetProperty( Toolkit::Button::Property::AUTO_REPEATING, true  );
372   button.SetProperty( Toolkit::Button::Property::INITIAL_AUTO_REPEATING_DELAY, AUTO_REPEATING_DELAY );
373   // connect to its touch signal
374   ConnectionTracker* testTracker = new ConnectionTracker();
375   button.PressedSignal().Connect( &ButtonCallback );
376   button.ClickedSignal().Connect( &ButtonCallback );
377   bool clickedSignal = false;
378   bool pressedSignal = false;
379   button.ConnectSignal( testTracker, "pressed", CallbackFunctor(&pressedSignal) );
380   button.ConnectSignal( testTracker, "clicked", CallbackFunctor(&clickedSignal) );
381
382   Dali::Integration::TouchEvent event;
383
384   // Touch point down and up inside the button.
385
386   gIsCalledButtonCallback = false;
387   event = Dali::Integration::TouchEvent();
388   event.AddPoint( GetPointDownInside() );
389   application.ProcessEvent( event );
390
391   DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
392   DALI_TEST_EQUALS( pressedSignal, true, TEST_LOCATION );
393   tet_infoline("Consume first clicked signal then wait\n");
394
395   gIsCalledButtonCallback = false;
396   Dali::Timer timer = Timer::New( AUTO_REPEATING_DELAY );
397   timer.MockEmitSignal();
398   application.Wait( AUTO_REPEATING_DELAY*2 );
399   DALI_TEST_EQUALS( clickedSignal, true, TEST_LOCATION );
400   tet_infoline("Check gIsCalledButtonCallback was called again after last consumption of it.\n");
401
402   DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
403
404   gIsCalledButtonCallback = false;
405   event = Dali::Integration::TouchEvent();
406   event.AddPoint( GetPointUpInside() );
407   application.ProcessEvent( event );
408
409   DALI_TEST_EQUALS( gIsCalledButtonCallback, true, TEST_LOCATION );
410
411   END_TEST;
412 }
413
414 int UtcDaliButtonSetInitialAutoRepeatingDelayP(void)
415 {
416   ToolkitTestApplication application;
417
418   Button button = PushButton::New();
419
420   button.SetInitialAutoRepeatingDelay( 0.5f );
421
422   DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
423
424   button.SetInitialAutoRepeatingDelay( 0.2f );
425
426   DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
427   END_TEST;
428 }
429
430 int UtcDaliButtonSetNextAutoRepeatingDelayP(void)
431 {
432   ToolkitTestApplication application;
433
434   Button button = PushButton::New();
435
436   button.SetNextAutoRepeatingDelay( 0.5f );
437
438   DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
439
440   button.SetProperty( Button::Property::NEXT_AUTO_REPEATING_DELAY, 0.2f );
441
442   DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
443   END_TEST;
444 }
445
446 int UtcDaliButtonSetTogglableButtonP(void)
447 {
448   ToolkitTestApplication application;
449
450   Button button = PushButton::New();
451
452   button.SetTogglableButton( true );
453
454   DALI_TEST_CHECK( button.IsTogglableButton() );
455
456   button.SetTogglableButton( false );
457
458   DALI_TEST_CHECK( !button.IsTogglableButton() );
459   END_TEST;
460 }
461
462 int UtcDaliButtonSetSelectedP(void)
463 {
464   ToolkitTestApplication application;
465
466   Button button = PushButton::New();
467   button.SetTogglableButton( true );
468
469   button.SetSelected( true );
470
471   DALI_TEST_CHECK( button.IsSelected() );
472
473   button.SetSelected( false );
474
475   DALI_TEST_CHECK( !button.IsSelected() );
476   END_TEST;
477 }
478
479 int UtcDaliButtonSetAnimationTimeP(void)
480 {
481   ToolkitTestApplication application;
482   tet_infoline(" UtcDaliButtonSetAnimationTimeP");
483
484   Button button = PushButton::New();
485
486   button.SetAnimationTime( ANIMATION_TIME );
487
488   DALI_TEST_EQUALS( button.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
489   END_TEST;
490 }
491
492 int UtcDaliButtonSetLabelStringWithPropertyMapP(void)
493 {
494   ToolkitTestApplication application;
495
496   Button button = PushButton::New();
497   button.SetProperty( Toolkit::Button::Property::LABEL,
498                       Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
499                                      .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
500                                      .Add( Toolkit::TextVisual::Property::TEXT, "Button Label")
501                      );
502
503   DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
504   END_TEST;
505 }
506
507 int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void)
508 {
509   ToolkitTestApplication application;
510
511   Button button = PushButton::New();
512
513   tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string");
514
515   Property::Map textVisualMapInitial;
516   textVisualMapInitial["visualType"] = "TEXT";
517   textVisualMapInitial["pointSize"] =  15.0f;
518   textVisualMapInitial["text"] = "button label initial";
519
520   button.SetProperty( Button::Property::LABEL, textVisualMapInitial );
521
522   DALI_TEST_EQUALS( GetButtonText( button ), "button label initial", TEST_LOCATION );
523
524   tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test");
525
526   Property::Map propertyMap;
527   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::DevelVisual::TEXT );
528   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT,  "error if this is the final text" );
529   propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
530
531   button.SetProperty( Button::Property::LABEL, propertyMap );
532
533   DALI_TEST_EQUALS( GetButtonText( button ), "error if this is the final text", TEST_LOCATION );
534
535   tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test");
536
537   Property::Map textVisualMap;
538   textVisualMap["visualType"] = "TEXT";
539   textVisualMap["pointSize"] =  15.0f;
540   textVisualMap["text"] = "Button Label";
541
542   button.SetProperty( Toolkit::Button::Property::LABEL, textVisualMap );
543
544   DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
545   END_TEST;
546 }
547
548 int UtcDaliButtonSetLabelWithStringP(void)
549 {
550   ToolkitTestApplication application;
551
552   Button button = PushButton::New();
553
554   // Set default point size for text visual as style sheet not available.
555   button.SetProperty( Toolkit::Button::Property::LABEL,
556                       Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
557                                      .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
558                                      );
559
560   button.SetProperty( Toolkit::Button::Property::LABEL, "Button Label" );
561
562   DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
563   END_TEST;
564 }
565
566 int UtcDaliButtonSetLabelPropertyP(void)
567 {
568   ToolkitTestApplication application;
569
570   tet_infoline(" UtcDaliButtonSetLabelPropertyP Set text label and then set again with new text");
571
572
573   const std::string TEST_LABEL1 = "test label one";
574   const std::string TEST_LABEL2 = "test label two";
575
576   Button button = PushButton::New();
577
578   button.SetProperty( Toolkit::Button::Property::LABEL,
579                         Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
580                                        .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
581                                        .Add( Toolkit::TextVisual::Property::TEXT, TEST_LABEL1 )
582                      );
583
584   DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL1,  TEST_LOCATION );
585
586   Property::Map propertyMap;
587   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::DevelVisual::TEXT );
588   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT,  TEST_LABEL2 );
589   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
590   propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
591   button.SetProperty( Button::Property::LABEL, propertyMap );
592
593   DALI_TEST_EQUALS( GetButtonText( button ), TEST_LABEL2,  TEST_LOCATION );
594
595   END_TEST;
596 }
597
598 int UtcDaliButtonSetUnselectedImageP(void)
599 {
600   ToolkitTestApplication application;
601   tet_infoline(" UtcDaliButtonSetUnselectedImageP");
602
603   PushButton pushButton = PushButton::New();
604   Stage::GetCurrent().Add( pushButton );
605
606   application.SendNotification();
607   application.Render();
608
609   pushButton.SetUnselectedImage( "Image.jpg" );
610
611   application.SendNotification();
612   application.Render();
613
614   DALI_TEST_CHECK( pushButton );
615
616   END_TEST;
617 }
618
619 int UtcDaliButtonSetSelectedImageP(void)
620 {
621   ToolkitTestApplication application;
622   tet_infoline(" UtcDaliButtonSetButtonImage");
623
624   PushButton pushButton = PushButton::New();
625   Stage::GetCurrent().Add( pushButton );
626
627   application.SendNotification();
628   application.Render();
629
630   pushButton.SetSelectedImage( "Image.jpg" );
631
632   application.SendNotification();
633   application.Render();
634
635   DALI_TEST_CHECK( pushButton );
636
637   END_TEST;
638 }
639
640 int UtcDaliButtonPressedSignalP(void)
641 {
642   ToolkitTestApplication application;
643   tet_infoline(" UtcDaliButtonPressedSignalP");
644
645   Button button = PushButton::New();
646   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
647   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
648   button.SetPosition( 240, 400 );
649   button.SetSize( 100, 100 );
650
651   Stage::GetCurrent().Add( button );
652
653   application.SendNotification();
654   application.Render();
655
656   // connect to its touch signal
657   ConnectionTracker* testTracker = new ConnectionTracker();
658   button.PressedSignal().Connect( &ButtonCallback );
659   button.ReleasedSignal().Connect( &ButtonCallback );
660   bool pressedSignal = false;
661   bool releasedSignal = false;
662   button.ConnectSignal( testTracker, "pressed",   CallbackFunctor(&pressedSignal) );
663   button.ConnectSignal( testTracker, "released",  CallbackFunctor(&releasedSignal) );
664
665   Dali::Integration::TouchEvent event;
666
667   // Test1. Touch point down and up inside the button.
668
669   gIsCalledButtonCallback = false;
670   event = Dali::Integration::TouchEvent();
671   event.AddPoint( GetPointDownInside() );
672   application.ProcessEvent( event );
673
674   DALI_TEST_CHECK( gIsCalledButtonCallback );
675   DALI_TEST_CHECK( pressedSignal );
676
677   gIsCalledButtonCallback = false;
678   event = Dali::Integration::TouchEvent();
679   event.AddPoint( GetPointUpInside() );
680   application.ProcessEvent( event );
681
682   DALI_TEST_CHECK( gIsCalledButtonCallback );
683   DALI_TEST_CHECK( releasedSignal );
684
685   // Test2. Touch point down and up outside the button.
686
687   pressedSignal = false;
688   releasedSignal = false;
689   gIsCalledButtonCallback = false;
690   event = Dali::Integration::TouchEvent();
691   event.AddPoint( GetPointDownOutside() );
692   application.ProcessEvent( event );
693
694   DALI_TEST_CHECK( !gIsCalledButtonCallback );
695   DALI_TEST_CHECK( !pressedSignal );
696
697   gIsCalledButtonCallback = false;
698   event = Dali::Integration::TouchEvent();
699   event.AddPoint( GetPointUpOutside() );
700   application.ProcessEvent( event );
701
702   DALI_TEST_CHECK( !gIsCalledButtonCallback );
703   DALI_TEST_CHECK( !releasedSignal );
704
705   // Test3. Touch point down inside and up outside the button.
706
707   gIsCalledButtonCallback = false;
708   event = Dali::Integration::TouchEvent();
709   event.AddPoint( GetPointDownInside() );
710   application.ProcessEvent( event );
711
712   DALI_TEST_CHECK( gIsCalledButtonCallback );
713
714   gIsCalledButtonCallback = false;
715   event = Dali::Integration::TouchEvent();
716   event.AddPoint( GetPointLeave() );
717   application.ProcessEvent( event );
718
719   event = Dali::Integration::TouchEvent();
720   event.AddPoint( GetPointUpOutside() );
721   application.ProcessEvent( event );
722
723   DALI_TEST_CHECK( gIsCalledButtonCallback );
724
725   // Test4. Touch point down outside and up inside the button.
726
727   gIsCalledButtonCallback = false;
728   event = Dali::Integration::TouchEvent();
729   event.AddPoint( GetPointDownOutside() );
730   application.ProcessEvent( event );
731
732   DALI_TEST_CHECK( !gIsCalledButtonCallback );
733
734   gIsCalledButtonCallback = false;
735   event = Dali::Integration::TouchEvent();
736   event.AddPoint( GetPointEnter() );
737   application.ProcessEvent( event );
738
739   event = Dali::Integration::TouchEvent();
740   event.AddPoint( GetPointUpInside() );
741   application.ProcessEvent( event );
742
743   DALI_TEST_CHECK( !gIsCalledButtonCallback );
744   END_TEST;
745 }
746
747 int UtcDaliButtonClickedSignalP(void)
748 {
749   ToolkitTestApplication application;
750   tet_infoline(" UtcDaliButtonClickedSignalP");
751
752   Button button = PushButton::New();
753   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
754   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
755   button.SetPosition( 240, 400 );
756   button.SetSize( 100, 100 );
757
758   Stage::GetCurrent().Add( button );
759
760   application.SendNotification();
761   application.Render();
762
763   // connect to its touch signal
764   button.ClickedSignal().Connect( &ButtonCallback );
765   bool clickedSignal = false;
766   ConnectionTracker* testTracker = new ConnectionTracker();
767   button.ConnectSignal( testTracker, "clicked",   CallbackFunctor(&clickedSignal) );
768
769   Dali::Integration::TouchEvent event;
770
771   // Test1. Touch point down and up inside the button.
772
773   gIsCalledButtonCallback = false;
774   event = Dali::Integration::TouchEvent();
775   event.AddPoint( GetPointDownInside() );
776   application.ProcessEvent( event );
777
778   event = Dali::Integration::TouchEvent();
779   event.AddPoint( GetPointUpInside() );
780   application.ProcessEvent( event );
781
782   DALI_TEST_CHECK( gIsCalledButtonCallback );
783   DALI_TEST_CHECK( clickedSignal );
784
785   // Test2. Touch point down and up outside the button.
786
787   gIsCalledButtonCallback = false;
788   clickedSignal = false;
789   event = Dali::Integration::TouchEvent();
790   event.AddPoint( GetPointDownOutside() );
791   application.ProcessEvent( event );
792
793   event = Dali::Integration::TouchEvent();
794   event.AddPoint( GetPointUpOutside() );
795   application.ProcessEvent( event );
796
797   DALI_TEST_CHECK( !gIsCalledButtonCallback );
798   DALI_TEST_CHECK( !clickedSignal );
799
800   // Test3. Touch point down inside and up outside the button.
801
802   gIsCalledButtonCallback = false;
803   clickedSignal = false;
804   event = Dali::Integration::TouchEvent();
805   event.AddPoint( GetPointDownInside() );
806   application.ProcessEvent( event );
807
808   event = Dali::Integration::TouchEvent();
809   event.AddPoint( GetPointLeave() );
810   application.ProcessEvent( event );
811
812   event = Dali::Integration::TouchEvent();
813   event.AddPoint( GetPointUpOutside() );
814   application.ProcessEvent( event );
815
816   DALI_TEST_CHECK( !gIsCalledButtonCallback );
817   DALI_TEST_CHECK( !clickedSignal );
818
819   // Test4. Touch point down outside and up inside the button.
820
821   gIsCalledButtonCallback = false;
822   clickedSignal = false;
823   event = Dali::Integration::TouchEvent();
824   event.AddPoint( GetPointDownOutside() );
825   application.ProcessEvent( event );
826
827   event = Dali::Integration::TouchEvent();
828   event.AddPoint( GetPointEnter() );
829   application.ProcessEvent( event );
830
831   event = Dali::Integration::TouchEvent();
832   event.AddPoint( GetPointUpInside() );
833   application.ProcessEvent( event );
834
835   DALI_TEST_CHECK( !gIsCalledButtonCallback );
836   DALI_TEST_CHECK( !clickedSignal );
837   END_TEST;
838 }
839
840 int UtcDaliButtonStateChangedSignalP(void)
841 {
842   ToolkitTestApplication application;
843   tet_infoline(" UtcDaliButtonStateChangedSignalP");
844
845   Button button = PushButton::New();
846   button.SetTogglableButton( true );
847
848   Stage::GetCurrent().Add( button );
849
850   application.SendNotification();
851   application.Render();
852
853   // connect to its signal
854   button.StateChangedSignal().Connect( &ButtonCallback );
855   bool stateChangedSignal = false;
856   ConnectionTracker* testTracker = new ConnectionTracker();
857   button.ConnectSignal( testTracker, "stateChanged",   CallbackFunctor(&stateChangedSignal) );
858
859   gIsCalledButtonCallback = false;
860   button.SetSelected( true );
861
862   DALI_TEST_CHECK( gIsCalledButtonCallback );
863   DALI_TEST_CHECK( stateChangedSignal );
864
865   gIsCalledButtonCallback = false;
866   stateChangedSignal = false;
867
868   button.SetSelected( false );
869
870   DALI_TEST_CHECK( gIsCalledButtonCallback );
871   DALI_TEST_CHECK( stateChangedSignal );
872   END_TEST;
873 }
874
875 int UtcDaliButtonSetProperty(void)
876 {
877   tet_infoline("UtcDaliButtonSetProperty: ");
878   ToolkitTestApplication application;
879
880   PushButton pushButton = PushButton::New();
881
882   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
883   DALI_TEST_CHECK( false == pushButton.IsDisabled() );
884
885   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
886   DALI_TEST_CHECK( true == pushButton.IsDisabled() );
887
888   END_TEST;
889 }
890
891 int UtcDaliButtonSize(void)
892 {
893   ToolkitTestApplication application;
894   tet_infoline(" UtcDaliButtonSize");
895
896   // First an image is set, then SetSize is called.
897   PushButton pushButton = PushButton::New();
898   Stage::GetCurrent().Add( pushButton );
899
900   pushButton.SetBackgroundImage( "Image.jpg" );
901   pushButton.SetSize( 10.f, 10.f );
902
903   application.SendNotification();
904   application.Render();
905
906   Vector3 size = pushButton.GetCurrentSize();
907
908   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
909   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
910   END_TEST;
911 }
912
913 int UtcDaliButtonSetSelectedBackgroundImageP(void)
914 {
915   ToolkitTestApplication application;
916
917   PushButton button = PushButton::New();
918   Stage::GetCurrent().Add( button );
919
920   try
921   {
922     button.SetSelectedBackgroundImage( "TestImage.jpg");
923     DALI_TEST_CHECK( true );
924   }
925   catch(...)
926   {
927     DALI_TEST_CHECK( false );
928   }
929
930   END_TEST;
931 }
932
933 int UtcDaliButtonSetSelectedBackgroundImageN(void)
934 {
935   ToolkitTestApplication application;
936
937   PushButton button;
938
939   try
940   {
941     button.SetSelectedBackgroundImage( "TestImage.jpg");
942     DALI_TEST_CHECK( false );
943   }
944   catch(...)
945   {
946     DALI_TEST_CHECK( true );
947   }
948
949   END_TEST;
950 }
951
952 int UtcDaliButtonSetDisabledImageP(void)
953 {
954   ToolkitTestApplication application;
955
956   PushButton button = PushButton::New();
957   Stage::GetCurrent().Add( button );
958
959   try
960   {
961     button.SetDisabledImage( "TestImage.jpg");
962     DALI_TEST_CHECK( true );
963   }
964   catch(...)
965   {
966     DALI_TEST_CHECK( false );
967   }
968
969   END_TEST;
970 }
971
972 int UtcDaliButtonSetDisabledImageN(void)
973 {
974   ToolkitTestApplication application;
975
976   PushButton button;
977
978   try
979   {
980     button.SetDisabledImage( "TestImage.jpg");
981     DALI_TEST_CHECK( false );
982   }
983   catch(...)
984   {
985     DALI_TEST_CHECK( true );
986   }
987
988   END_TEST;
989 }
990
991 int UtcDaliButtonSetDisabledSelectedImageP(void)
992 {
993   ToolkitTestApplication application;
994
995   PushButton button = PushButton::New();
996   Stage::GetCurrent().Add( button );
997
998   try
999   {
1000     button.SetDisabledSelectedImage( "TestImage.jpg");
1001     DALI_TEST_CHECK( true );
1002   }
1003   catch(...)
1004   {
1005     DALI_TEST_CHECK( false );
1006   }
1007
1008   END_TEST;
1009 }
1010
1011 int UtcDaliButtonSetDisabledSelectedImageN(void)
1012 {
1013   ToolkitTestApplication application;
1014
1015   PushButton button;
1016
1017   try
1018   {
1019     button.SetDisabledSelectedImage( "TestImage.jpg");
1020     DALI_TEST_CHECK( false );
1021   }
1022   catch(...)
1023   {
1024     DALI_TEST_CHECK( true );
1025   }
1026
1027   END_TEST;
1028 }
1029
1030 int UtcDaliButtonSetLabeActorlP(void)
1031 {
1032   ToolkitTestApplication application;
1033
1034   PushButton button = PushButton::New();
1035   Stage::GetCurrent().Add( button );
1036
1037   try
1038   {
1039     button.SetLabel( TextLabel::New("Hello") );
1040     DALI_TEST_CHECK( true );
1041   }
1042   catch(...)
1043   {
1044     DALI_TEST_CHECK( false );
1045   }
1046
1047   END_TEST;
1048 }
1049
1050 int UtcDaliButtonSetLabelN(void)
1051 {
1052   ToolkitTestApplication application;
1053
1054   PushButton button;
1055
1056   try
1057   {
1058     button.SetLabel( TextLabel::New("Hello") );
1059     DALI_TEST_CHECK( false );
1060   }
1061   catch(...)
1062   {
1063     DALI_TEST_CHECK( true );
1064   }
1065
1066   END_TEST;
1067 }
1068
1069 int UtcDaliButtonSetButtonImageP(void)
1070 {
1071   ToolkitTestApplication application;
1072
1073   PushButton button = PushButton::New();
1074   Stage::GetCurrent().Add( button );
1075
1076   try
1077   {
1078     ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1079     button.SetButtonImage( image1 );
1080
1081     Property::Value value = button.GetProperty(Button::Property::UNSELECTED_STATE_IMAGE );
1082     DALI_TEST_CHECK( value.Get<std::string>() == TEST_IMAGE_ONE );
1083   }
1084   catch(...)
1085   {
1086     DALI_TEST_CHECK( false );
1087   }
1088
1089   std::string imageUrl;
1090
1091   Dali::Actor actor = button.GetButtonImage();
1092
1093   Toolkit::ImageView imageView = Toolkit::ImageView ::DownCast( actor );
1094
1095   tet_infoline(" UtcDaliButtonSetButtonImageP Ensure an ImageView is returned\n");
1096   DALI_TEST_CHECK ( imageView )
1097
1098   END_TEST;
1099 }
1100
1101 int UtcDaliButtonSetButtonImageN(void)
1102 {
1103   ToolkitTestApplication application;
1104
1105   PushButton button;
1106
1107   try
1108   {
1109     ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1110     button.SetButtonImage( image1 );
1111
1112     DALI_TEST_CHECK( false );
1113   }
1114   catch(...)
1115   {
1116     DALI_TEST_CHECK( true );
1117   }
1118
1119   END_TEST;
1120 }
1121
1122 int UtcDaliButtonSetSelectedImageWithImageP(void)
1123 {
1124   ToolkitTestApplication application;
1125
1126   PushButton button = PushButton::New();
1127   Stage::GetCurrent().Add( button );
1128   ResourceImage image1 = ResourceImage::New( TEST_IMAGE_ONE );
1129
1130   try
1131   {
1132     button.SetSelectedImage( image1 );
1133     Property::Value value = button.GetProperty( Button::Property::SELECTED_STATE_IMAGE );
1134     DALI_TEST_CHECK( value.Get<std::string>() == TEST_IMAGE_ONE );
1135   }
1136   catch(...)
1137   {
1138     DALI_TEST_CHECK( false );
1139   }
1140
1141   std::string imageUrl;
1142
1143   Dali::Actor actor = button.GetSelectedImage();
1144
1145   Toolkit::ImageView imageView = Toolkit::ImageView::DownCast( actor );
1146
1147   tet_infoline(" UtcDaliButtonSetSelectedImageWithImageP Ensure an ImageView is returned\n");
1148
1149   END_TEST;
1150 }
1151
1152 int UtcDaliButtonSetSelectedImageWithImageN(void)
1153 {
1154   ToolkitTestApplication application;
1155
1156   PushButton button;
1157
1158   try
1159   {
1160     button.SetSelectedImage( CreateBufferImage( 10, 10, Color::WHITE ) );
1161     DALI_TEST_CHECK( false );
1162   }
1163   catch(...)
1164   {
1165     DALI_TEST_CHECK( true );
1166   }
1167
1168   END_TEST;
1169 }
1170
1171 int UtcDaliButtonSetSelectedColorP(void)
1172 {
1173   ToolkitTestApplication application;
1174   tet_infoline(" UtcDaliButtonSetSelectedColorP");
1175
1176   PushButton pushButton = PushButton::New();
1177   Stage::GetCurrent().Add( pushButton );
1178
1179   application.SendNotification();
1180   application.Render();
1181
1182   const Vector4 SET_COLOR = Color::BLUE;
1183
1184   pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1185   pushButton.SetProperty( Button::Property::SELECTED_COLOR, SET_COLOR );
1186
1187   application.SendNotification();
1188   application.Render();
1189
1190   Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1191
1192   DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
1193
1194   END_TEST;
1195 }
1196
1197 int UtcDaliButtonSetUnSelectedColorP(void)
1198 {
1199   ToolkitTestApplication application;
1200   tet_infoline(" UtcDaliButtonSetUnSelectedColorP");
1201
1202   PushButton pushButton = PushButton::New();
1203   Stage::GetCurrent().Add( pushButton );
1204
1205   application.SendNotification();
1206   application.Render();
1207
1208   const Vector4 SET_COLOR = Color::BLUE;
1209
1210   pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1211   pushButton.SetProperty( Button::Property::UNSELECTED_COLOR, SET_COLOR );
1212
1213   application.SendNotification();
1214   application.Render();
1215
1216   Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::UNSELECTED_COLOR );
1217
1218   DALI_TEST_EQUALS( color, SET_COLOR, TEST_LOCATION );
1219
1220   END_TEST;
1221 }
1222
1223 int UtcDaliButtonResetSelectedColorP(void)
1224 {
1225   ToolkitTestApplication application;
1226   tet_infoline(" UtcDaliButtonSetSelectedColorP");
1227
1228   PushButton pushButton = PushButton::New();
1229   Stage::GetCurrent().Add( pushButton );
1230
1231   application.SendNotification();
1232   application.Render();
1233
1234   const Vector4 FIRST_COLOR = Color::BLUE;
1235   const Vector4 SECOND_COLOR = Color::BLUE;
1236
1237   pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
1238   pushButton.SetProperty( Button::Property::SELECTED_COLOR, FIRST_COLOR );
1239
1240   application.SendNotification();
1241   application.Render();
1242
1243   Vector4 color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1244
1245   DALI_TEST_EQUALS( color, FIRST_COLOR, TEST_LOCATION );
1246
1247   pushButton.SetProperty( Button::Property::SELECTED_COLOR, SECOND_COLOR );
1248
1249   application.SendNotification();
1250   application.Render();
1251
1252   color = pushButton.GetProperty<Vector4>( Button::Property::SELECTED_COLOR );
1253
1254   DALI_TEST_EQUALS( color, SECOND_COLOR, TEST_LOCATION );
1255
1256   END_TEST;
1257 }
1258
1259 int UtcDaliButtonSetImagesWithDeprecatedProperties(void)
1260 {
1261   ToolkitTestApplication application;
1262   tet_infoline(" UtcDaliButtonSetImagesWithDeprecatedProperties");
1263
1264   PushButton pushButton = PushButton::New();
1265
1266   Stage::GetCurrent().Add( pushButton );
1267
1268   Property::Map propertyMap;
1269   propertyMap.Insert(Visual::Property::TYPE,  Visual::COLOR);
1270   propertyMap.Insert(ColorVisual::Property::MIX_COLOR, Color::BLUE);
1271
1272   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 0, TEST_LOCATION );
1273
1274   pushButton.SetProperty( Toolkit::Button::Property::UNSELECTED_STATE_IMAGE, propertyMap );
1275   application.SendNotification();
1276   application.Render();
1277   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1278
1279   tet_infoline(" Set state to selected and provide SELECTED visual");
1280   pushButton.SetProperty( Toolkit::Button::Property::SELECTED_STATE_IMAGE, propertyMap );
1281   pushButton.SetProperty( Toolkit::Button::Property::SELECTED, true );
1282   application.SendNotification();
1283   application.Render();
1284   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1285
1286   tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual");
1287   pushButton.SetProperty( Toolkit::Button::Property::SELECTED, false );
1288   pushButton.SetProperty( Toolkit::Button::Property::DISABLED, true );
1289   pushButton.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, propertyMap );
1290   application.SendNotification();
1291   application.Render();
1292   DALI_TEST_EQUALS( pushButton.GetRendererCount(), 1, TEST_LOCATION );
1293
1294 END_TEST;
1295 }
1296
1297 int UtcDaliButtonSetGetDepreciatedPropertiesWithURL(void)
1298 {
1299   ToolkitTestApplication application;
1300   tet_infoline(" UtcDaliButtonSetGetDepreciatedPropertiesWithURL");
1301
1302   PushButton button = PushButton::New();
1303   Stage::GetCurrent().Add( button );
1304
1305   tet_infoline(" Set state to selected, disabled and provide DISABLED_STATE_IMAGE visual");
1306   button.SetProperty( Toolkit::Button::Property::DISABLED, true );
1307   button.SetProperty( Toolkit::Button::Property::DISABLED_STATE_IMAGE, TEST_IMAGE_ONE );
1308
1309   Property::Value value = button.GetProperty(Button::Property::DISABLED_STATE_IMAGE );
1310   DALI_TEST_EQUALS( value.Get<std::string>(),  TEST_IMAGE_ONE, TEST_LOCATION );
1311
1312 END_TEST;
1313 }
1314
1315 int UtcDaliButtonSetLabelTextDeprecatedPropertyP(void)
1316 {
1317   ToolkitTestApplication application;
1318   tet_infoline(" UtcDaliButtonSetLabelTextDeprecatedPropertyP");
1319
1320   const std::string TEST_LABEL1 = "test label one";
1321   const std::string TEST_LABEL2 = "test label two";
1322
1323   Button button = PushButton::New();
1324
1325   button.SetProperty( Toolkit::Button::Property::LABEL,
1326                         Property::Map().Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
1327                                        .Add( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f )
1328                      );
1329
1330   button.SetProperty( Button::Property::LABEL_TEXT, TEST_LABEL1 );
1331
1332   std::string labelText = button.GetProperty<std::string>( Button::Property::LABEL_TEXT );
1333
1334   DALI_TEST_EQUALS( labelText, TEST_LABEL1,  TEST_LOCATION );
1335
1336   Property::Map propertyMap;
1337   propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::DevelVisual::TEXT );
1338   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT,  TEST_LABEL2 );
1339   propertyMap.Insert( Toolkit::TextVisual::Property::TEXT_COLOR, Color::BLUE );
1340   propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
1341   button.SetProperty( Button::Property::LABEL, propertyMap );
1342
1343   labelText = button.GetProperty<std::string>( Button::Property::LABEL_TEXT );
1344
1345   DALI_TEST_EQUALS( labelText, TEST_LABEL2,  TEST_LOCATION );
1346
1347   END_TEST;
1348 }