Added tests for EffectsView
[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
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32
33 void utc_dali_toolkit_button_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_toolkit_button_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 namespace
44 {
45 static bool gIsCalledButtonCallback = false;
46
47 static bool ButtonCallback( Button button )
48 {
49   gIsCalledButtonCallback = true;
50   return false;
51 }
52
53 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
54 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
55 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
56 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
57 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
58 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
59
60 static float ANIMATION_TIME( 0.5f );
61 } // namespace
62
63 int UtcDaliButtonConstructorP(void)
64 {
65   TestApplication application;
66
67   Button button;
68
69   DALI_TEST_CHECK( !button );
70   END_TEST;
71 }
72
73 int UtcDaliButtonCopyConstructorP(void)
74 {
75   TestApplication application;
76
77   // Initialize an object, ref count == 1
78   Button button = PushButton::New();
79
80   Button copy( button );
81   DALI_TEST_CHECK( copy );
82   END_TEST;
83 }
84
85 int UtcDaliButtonAssignmentOperatorP(void)
86 {
87   TestApplication application;
88
89   Button button = PushButton::New();
90
91   Button copy( button );
92   DALI_TEST_CHECK( copy );
93
94   DALI_TEST_CHECK( button == copy );
95   END_TEST;
96 }
97
98 int UtcDaliButtonDownCastP(void)
99 {
100   TestApplication application;
101
102   Button button = PushButton::New();
103
104   BaseHandle object(button);
105
106   Button button2 = Button::DownCast( object );
107   DALI_TEST_CHECK(button2);
108
109   Button button3 = DownCast< Button >(object);
110   DALI_TEST_CHECK(button3);
111   END_TEST;
112 }
113
114 int UtcDaliButtonDownCastN(void)
115 {
116   TestApplication application;
117
118   BaseHandle unInitializedObject;
119
120   Button button1 = Button::DownCast( unInitializedObject );
121   DALI_TEST_CHECK( !button1 );
122
123   Button button2 = DownCast< Button >( unInitializedObject );
124   DALI_TEST_CHECK( !button2 );
125   END_TEST;
126 }
127
128 int UtcDaliButtonSetDisabledP(void)
129 {
130   ToolkitTestApplication application;
131
132   Button button = PushButton::New();
133
134   button.SetDisabled( true );
135
136   DALI_TEST_CHECK( button.IsDisabled() );
137
138   button.SetDisabled( false );
139
140   DALI_TEST_CHECK( !button.IsDisabled() );
141
142   button.SetDisabled( true );
143
144   DALI_TEST_CHECK( button.IsDisabled() );
145
146   button.SetDisabled( false );
147
148   DALI_TEST_CHECK( !button.IsDisabled() );
149   END_TEST;
150 }
151
152 int UtcDaliButtonIsDisabledP(void)
153 {
154   ToolkitTestApplication application;
155
156   Button button = PushButton::New();
157
158   button.SetDisabled( true );
159
160   DALI_TEST_CHECK( button.IsDisabled() );
161
162   button.SetDisabled( false );
163
164   DALI_TEST_CHECK( !button.IsDisabled() );
165   END_TEST;
166 }
167
168 int UtcDaliButtonSetAutoRepeatingP(void)
169 {
170   ToolkitTestApplication application;
171
172   Button button = PushButton::New();
173
174   button.SetAutoRepeating( true );
175
176   DALI_TEST_CHECK( button.IsAutoRepeating() );
177
178   button.SetAutoRepeating( false );
179
180   DALI_TEST_CHECK( !button.IsAutoRepeating() );
181
182   button.SetAutoRepeating( true );
183
184   DALI_TEST_CHECK( button.IsAutoRepeating() );
185
186   button.SetAutoRepeating( false );
187
188   DALI_TEST_CHECK( !button.IsAutoRepeating() );
189   END_TEST;
190 }
191
192 int UtcDaliButtonIsAutoRepeatingP(void)
193 {
194   ToolkitTestApplication application;
195
196   Button button = PushButton::New();
197
198   button.SetAutoRepeating( true );
199
200   DALI_TEST_CHECK( button.IsAutoRepeating() );
201
202   button.SetAutoRepeating( false );
203
204   DALI_TEST_CHECK( !button.IsAutoRepeating() );
205   END_TEST;
206 }
207
208 int UtcDaliButtonSetInitialAutoRepeatingDelayP(void)
209 {
210   ToolkitTestApplication application;
211
212   Button button = PushButton::New();
213
214   button.SetInitialAutoRepeatingDelay( 0.5f );
215
216   DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
217
218   button.SetInitialAutoRepeatingDelay( 0.2f );
219
220   DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
221   END_TEST;
222 }
223
224 int UtcDaliButtonSetNextAutoRepeatingDelayP(void)
225 {
226   ToolkitTestApplication application;
227
228   Button button = PushButton::New();
229
230   button.SetNextAutoRepeatingDelay( 0.5f );
231
232   DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
233
234   button.SetNextAutoRepeatingDelay( 0.2f );
235
236   DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
237   END_TEST;
238 }
239
240 int UtcDaliButtonSetTogglableButtonP(void)
241 {
242   ToolkitTestApplication application;
243
244   Button button = PushButton::New();
245
246   button.SetTogglableButton( true );
247
248   DALI_TEST_CHECK( button.IsTogglableButton() );
249
250   button.SetTogglableButton( false );
251
252   DALI_TEST_CHECK( !button.IsTogglableButton() );
253   END_TEST;
254 }
255
256 int UtcDaliButtonSetSelectedP(void)
257 {
258   ToolkitTestApplication application;
259
260   Button button = PushButton::New();
261   button.SetTogglableButton( true );
262
263   button.SetSelected( true );
264
265   DALI_TEST_CHECK( button.IsSelected() );
266
267   button.SetSelected( false );
268
269   DALI_TEST_CHECK( !button.IsSelected() );
270   END_TEST;
271 }
272
273 int UtcDaliButtonSetAnimationTimeP(void)
274 {
275   ToolkitTestApplication application;
276   tet_infoline(" UtcDaliButtonSetAnimationTimeP");
277
278   Button button = PushButton::New();
279
280   button.SetAnimationTime( ANIMATION_TIME );
281
282   DALI_TEST_EQUALS( button.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
283   END_TEST;
284 }
285
286 int UtcDaliButtonSetLabelStringP(void)
287 {
288   ToolkitTestApplication application;
289
290   Button button = PushButton::New();
291
292   button.SetLabel( "Button Label" );
293
294   DALI_TEST_CHECK( button.GetLabel() );
295   END_TEST;
296 }
297
298 int UtcDaliButtonSetLabelActorP(void)
299 {
300   ToolkitTestApplication application;
301
302   Button button = PushButton::New();
303
304   TextLabel textLabel = TextLabel::New( "Button Label" );
305   button.SetLabel( textLabel );
306
307   DALI_TEST_CHECK( button.GetLabel() );
308   END_TEST;
309 }
310
311 int UtcDaliButtonPressedSignalP(void)
312 {
313   ToolkitTestApplication application;
314   tet_infoline(" UtcDaliButtonPressedSignalP");
315
316   Button button = PushButton::New();
317   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
318   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
319   button.SetPosition( 240, 400 );
320   button.SetSize( 100, 100 );
321
322   Stage::GetCurrent().Add( button );
323
324   application.SendNotification();
325   application.Render();
326
327   // connect to its touch signal
328   button.PressedSignal().Connect( &ButtonCallback );
329   button.ReleasedSignal().Connect( &ButtonCallback );
330
331   Dali::Integration::TouchEvent event;
332
333   // Test1. Touch point down and up inside the button.
334
335   gIsCalledButtonCallback = false;
336   event = Dali::Integration::TouchEvent();
337   event.AddPoint( pointDownInside );
338   application.ProcessEvent( event );
339
340   DALI_TEST_CHECK( gIsCalledButtonCallback );
341
342   gIsCalledButtonCallback = false;
343   event = Dali::Integration::TouchEvent();
344   event.AddPoint( pointUpInside );
345   application.ProcessEvent( event );
346
347   DALI_TEST_CHECK( gIsCalledButtonCallback );
348
349   // Test2. Touch point down and up outside the button.
350
351   gIsCalledButtonCallback = false;
352   event = Dali::Integration::TouchEvent();
353   event.AddPoint( pointDownOutside );
354   application.ProcessEvent( event );
355
356   DALI_TEST_CHECK( !gIsCalledButtonCallback );
357
358   gIsCalledButtonCallback = false;
359   event = Dali::Integration::TouchEvent();
360   event.AddPoint( pointUpOutside );
361   application.ProcessEvent( event );
362
363   DALI_TEST_CHECK( !gIsCalledButtonCallback );
364
365   // Test3. Touch point down inside and up outside the button.
366
367   gIsCalledButtonCallback = false;
368   event = Dali::Integration::TouchEvent();
369   event.AddPoint( pointDownInside );
370   application.ProcessEvent( event );
371
372   DALI_TEST_CHECK( gIsCalledButtonCallback );
373
374   gIsCalledButtonCallback = false;
375   event = Dali::Integration::TouchEvent();
376   event.AddPoint( pointLeave );
377   application.ProcessEvent( event );
378
379   event = Dali::Integration::TouchEvent();
380   event.AddPoint( pointUpOutside );
381   application.ProcessEvent( event );
382
383   DALI_TEST_CHECK( gIsCalledButtonCallback );
384
385   // Test4. Touch point down outside and up inside the button.
386
387   gIsCalledButtonCallback = false;
388   event = Dali::Integration::TouchEvent();
389   event.AddPoint( pointDownOutside );
390   application.ProcessEvent( event );
391
392   DALI_TEST_CHECK( !gIsCalledButtonCallback );
393
394   gIsCalledButtonCallback = false;
395   event = Dali::Integration::TouchEvent();
396   event.AddPoint( pointEnter );
397   application.ProcessEvent( event );
398
399   event = Dali::Integration::TouchEvent();
400   event.AddPoint( pointUpInside );
401   application.ProcessEvent( event );
402
403   DALI_TEST_CHECK( !gIsCalledButtonCallback );
404   END_TEST;
405 }
406
407 int UtcDaliButtonClickedSignalP(void)
408 {
409   ToolkitTestApplication application;
410   tet_infoline(" UtcDaliButtonClickedSignalP");
411
412   Button button = PushButton::New();
413   button.SetAnchorPoint( AnchorPoint::TOP_LEFT );
414   button.SetParentOrigin( ParentOrigin::TOP_LEFT );
415   button.SetPosition( 240, 400 );
416   button.SetSize( 100, 100 );
417
418   Stage::GetCurrent().Add( button );
419
420   application.SendNotification();
421   application.Render();
422
423   // connect to its touch signal
424   button.ClickedSignal().Connect( &ButtonCallback );
425
426   Dali::Integration::TouchEvent event;
427
428   // Test1. Touch point down and up inside the button.
429
430   gIsCalledButtonCallback = false;
431   event = Dali::Integration::TouchEvent();
432   event.AddPoint( pointDownInside );
433   application.ProcessEvent( event );
434
435   event = Dali::Integration::TouchEvent();
436   event.AddPoint( pointUpInside );
437   application.ProcessEvent( event );
438
439   DALI_TEST_CHECK( gIsCalledButtonCallback );
440
441   // Test2. Touch point down and up outside the button.
442
443   gIsCalledButtonCallback = false;
444   event = Dali::Integration::TouchEvent();
445   event.AddPoint( pointDownOutside );
446   application.ProcessEvent( event );
447
448   event = Dali::Integration::TouchEvent();
449   event.AddPoint( pointUpOutside );
450   application.ProcessEvent( event );
451
452   DALI_TEST_CHECK( !gIsCalledButtonCallback );
453
454   // Test3. Touch point down inside and up outside the button.
455
456   gIsCalledButtonCallback = false;
457   event = Dali::Integration::TouchEvent();
458   event.AddPoint( pointDownInside );
459   application.ProcessEvent( event );
460
461   event = Dali::Integration::TouchEvent();
462   event.AddPoint( pointLeave );
463   application.ProcessEvent( event );
464
465   event = Dali::Integration::TouchEvent();
466   event.AddPoint( pointUpOutside );
467   application.ProcessEvent( event );
468
469   DALI_TEST_CHECK( !gIsCalledButtonCallback );
470
471   // Test4. Touch point down outside and up inside the button.
472
473   gIsCalledButtonCallback = false;
474   event = Dali::Integration::TouchEvent();
475   event.AddPoint( pointDownOutside );
476   application.ProcessEvent( event );
477
478   event = Dali::Integration::TouchEvent();
479   event.AddPoint( pointEnter );
480   application.ProcessEvent( event );
481
482   event = Dali::Integration::TouchEvent();
483   event.AddPoint( pointUpInside );
484   application.ProcessEvent( event );
485
486   DALI_TEST_CHECK( !gIsCalledButtonCallback );
487   END_TEST;
488 }
489
490 int UtcDaliButtonStateChangedSignalP(void)
491 {
492   ToolkitTestApplication application;
493   tet_infoline(" UtcDaliButtonStateChangedSignalP");
494
495   Button button = PushButton::New();
496   button.SetTogglableButton( true );
497
498   Stage::GetCurrent().Add( button );
499
500   application.SendNotification();
501   application.Render();
502
503   // connect to its signal
504   button.StateChangedSignal().Connect( &ButtonCallback );
505
506   gIsCalledButtonCallback = false;
507   button.SetSelected( true );
508
509   DALI_TEST_CHECK( gIsCalledButtonCallback );
510
511   gIsCalledButtonCallback = false;
512   button.SetSelected( false );
513
514   DALI_TEST_CHECK( gIsCalledButtonCallback );
515   END_TEST;
516 }
517
518 int UtcDaliButtonSetProperty(void)
519 {
520   tet_infoline("UtcDaliButtonSetProperty: ");
521   ToolkitTestApplication application;
522
523   PushButton pushButton = PushButton::New();
524
525   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), false);
526   DALI_TEST_CHECK( false == pushButton.IsDisabled() );
527   pushButton.SetProperty(pushButton.GetPropertyIndex("disabled"), true);
528   DALI_TEST_CHECK( true == pushButton.IsDisabled() );
529   END_TEST;
530 }
531
532 int UtcDaliButtonSize(void)
533 {
534   ToolkitTestApplication application;
535   tet_infoline(" UtcDaliButtonSize");
536
537   ImageActor image01 = ImageActor::New(CreateBufferImage());
538   image01.SetSize( 100, 50 );
539
540   PushButton pushButton;
541
542   Vector3 size;
543
544   // Test1 Size is set through Actor API
545
546   // First an image is set, then SetSize is called.
547   pushButton = PushButton::New();
548   Stage::GetCurrent().Add( pushButton );
549
550   pushButton.SetBackgroundImage( image01 );
551   pushButton.SetSize( 10.f, 10.f );
552
553   application.SendNotification();
554   application.Render();
555
556   size = pushButton.GetCurrentSize();
557
558   DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
559   DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
560   END_TEST;
561 }