2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali/integration-api/events/touch-event-integ.h>
30 using namespace Toolkit;
33 void utc_dali_toolkit_button_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_dali_toolkit_button_cleanup(void)
40 test_return_value = TET_PASS;
45 static bool gIsCalledButtonCallback = false;
47 static bool ButtonCallback( Button button )
49 gIsCalledButtonCallback = true;
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 );
60 static float ANIMATION_TIME( 0.5f );
63 int UtcDaliButtonConstructorP(void)
65 TestApplication application;
69 DALI_TEST_CHECK( !button );
73 int UtcDaliButtonCopyConstructorP(void)
75 TestApplication application;
77 // Initialize an object, ref count == 1
78 Button button = PushButton::New();
80 Button copy( button );
81 DALI_TEST_CHECK( copy );
85 int UtcDaliButtonAssignmentOperatorP(void)
87 TestApplication application;
89 Button button = PushButton::New();
91 Button copy( button );
92 DALI_TEST_CHECK( copy );
94 DALI_TEST_CHECK( button == copy );
98 int UtcDaliButtonDownCastP(void)
100 TestApplication application;
102 Button button = PushButton::New();
104 BaseHandle object(button);
106 Button button2 = Button::DownCast( object );
107 DALI_TEST_CHECK(button2);
109 Button button3 = DownCast< Button >(object);
110 DALI_TEST_CHECK(button3);
114 int UtcDaliButtonDownCastN(void)
116 TestApplication application;
118 BaseHandle unInitializedObject;
120 Button button1 = Button::DownCast( unInitializedObject );
121 DALI_TEST_CHECK( !button1 );
123 Button button2 = DownCast< Button >( unInitializedObject );
124 DALI_TEST_CHECK( !button2 );
128 int UtcDaliButtonSetDisabledP(void)
130 ToolkitTestApplication application;
132 Button button = PushButton::New();
134 button.SetDisabled( true );
136 DALI_TEST_CHECK( button.IsDisabled() );
138 button.SetDisabled( false );
140 DALI_TEST_CHECK( !button.IsDisabled() );
142 button.SetDisabled( true );
144 DALI_TEST_CHECK( button.IsDisabled() );
146 button.SetDisabled( false );
148 DALI_TEST_CHECK( !button.IsDisabled() );
152 int UtcDaliButtonIsDisabledP(void)
154 ToolkitTestApplication application;
156 Button button = PushButton::New();
158 button.SetDisabled( true );
160 DALI_TEST_CHECK( button.IsDisabled() );
162 button.SetDisabled( false );
164 DALI_TEST_CHECK( !button.IsDisabled() );
168 int UtcDaliButtonSetAutoRepeatingP(void)
170 ToolkitTestApplication application;
172 Button button = PushButton::New();
174 button.SetAutoRepeating( true );
176 DALI_TEST_CHECK( button.IsAutoRepeating() );
178 button.SetAutoRepeating( false );
180 DALI_TEST_CHECK( !button.IsAutoRepeating() );
182 button.SetAutoRepeating( true );
184 DALI_TEST_CHECK( button.IsAutoRepeating() );
186 button.SetAutoRepeating( false );
188 DALI_TEST_CHECK( !button.IsAutoRepeating() );
192 int UtcDaliButtonIsAutoRepeatingP(void)
194 ToolkitTestApplication application;
196 Button button = PushButton::New();
198 button.SetAutoRepeating( true );
200 DALI_TEST_CHECK( button.IsAutoRepeating() );
202 button.SetAutoRepeating( false );
204 DALI_TEST_CHECK( !button.IsAutoRepeating() );
208 int UtcDaliButtonSetInitialAutoRepeatingDelayP(void)
210 ToolkitTestApplication application;
212 Button button = PushButton::New();
214 button.SetInitialAutoRepeatingDelay( 0.5f );
216 DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
218 button.SetInitialAutoRepeatingDelay( 0.2f );
220 DALI_TEST_EQUALS( button.GetInitialAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
224 int UtcDaliButtonSetNextAutoRepeatingDelayP(void)
226 ToolkitTestApplication application;
228 Button button = PushButton::New();
230 button.SetNextAutoRepeatingDelay( 0.5f );
232 DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.5f, TEST_LOCATION );
234 button.SetNextAutoRepeatingDelay( 0.2f );
236 DALI_TEST_EQUALS( button.GetNextAutoRepeatingDelay(), 0.2f, TEST_LOCATION );
240 int UtcDaliButtonSetTogglableButtonP(void)
242 ToolkitTestApplication application;
244 Button button = PushButton::New();
246 button.SetTogglableButton( true );
248 DALI_TEST_CHECK( button.IsTogglableButton() );
250 button.SetTogglableButton( false );
252 DALI_TEST_CHECK( !button.IsTogglableButton() );
256 int UtcDaliButtonSetSelectedP(void)
258 ToolkitTestApplication application;
260 Button button = PushButton::New();
261 button.SetTogglableButton( true );
263 button.SetSelected( true );
265 DALI_TEST_CHECK( button.IsSelected() );
267 button.SetSelected( false );
269 DALI_TEST_CHECK( !button.IsSelected() );
273 int UtcDaliButtonSetAnimationTimeP(void)
275 ToolkitTestApplication application;
276 tet_infoline(" UtcDaliButtonSetAnimationTimeP");
278 Button button = PushButton::New();
280 button.SetAnimationTime( ANIMATION_TIME );
282 DALI_TEST_EQUALS( button.GetAnimationTime(), ANIMATION_TIME, TEST_LOCATION );
286 int UtcDaliButtonSetLabelStringP(void)
288 ToolkitTestApplication application;
290 Button button = PushButton::New();
292 button.SetLabel( "Button Label" );
294 DALI_TEST_CHECK( button.GetLabel() );
298 int UtcDaliButtonSetLabelActorP(void)
300 ToolkitTestApplication application;
302 Button button = PushButton::New();
304 TextLabel textLabel = TextLabel::New( "Button Label" );
305 button.SetLabel( textLabel );
307 DALI_TEST_CHECK( button.GetLabel() );
311 int UtcDaliButtonPressedSignalP(void)
313 ToolkitTestApplication application;
314 tet_infoline(" UtcDaliButtonPressedSignalP");
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 );
322 Stage::GetCurrent().Add( button );
324 application.SendNotification();
325 application.Render();
327 // connect to its touch signal
328 button.PressedSignal().Connect( &ButtonCallback );
329 button.ReleasedSignal().Connect( &ButtonCallback );
331 Dali::Integration::TouchEvent event;
333 // Test1. Touch point down and up inside the button.
335 gIsCalledButtonCallback = false;
336 event = Dali::Integration::TouchEvent();
337 event.AddPoint( pointDownInside );
338 application.ProcessEvent( event );
340 DALI_TEST_CHECK( gIsCalledButtonCallback );
342 gIsCalledButtonCallback = false;
343 event = Dali::Integration::TouchEvent();
344 event.AddPoint( pointUpInside );
345 application.ProcessEvent( event );
347 DALI_TEST_CHECK( gIsCalledButtonCallback );
349 // Test2. Touch point down and up outside the button.
351 gIsCalledButtonCallback = false;
352 event = Dali::Integration::TouchEvent();
353 event.AddPoint( pointDownOutside );
354 application.ProcessEvent( event );
356 DALI_TEST_CHECK( !gIsCalledButtonCallback );
358 gIsCalledButtonCallback = false;
359 event = Dali::Integration::TouchEvent();
360 event.AddPoint( pointUpOutside );
361 application.ProcessEvent( event );
363 DALI_TEST_CHECK( !gIsCalledButtonCallback );
365 // Test3. Touch point down inside and up outside the button.
367 gIsCalledButtonCallback = false;
368 event = Dali::Integration::TouchEvent();
369 event.AddPoint( pointDownInside );
370 application.ProcessEvent( event );
372 DALI_TEST_CHECK( gIsCalledButtonCallback );
374 gIsCalledButtonCallback = false;
375 event = Dali::Integration::TouchEvent();
376 event.AddPoint( pointLeave );
377 application.ProcessEvent( event );
379 event = Dali::Integration::TouchEvent();
380 event.AddPoint( pointUpOutside );
381 application.ProcessEvent( event );
383 DALI_TEST_CHECK( gIsCalledButtonCallback );
385 // Test4. Touch point down outside and up inside the button.
387 gIsCalledButtonCallback = false;
388 event = Dali::Integration::TouchEvent();
389 event.AddPoint( pointDownOutside );
390 application.ProcessEvent( event );
392 DALI_TEST_CHECK( !gIsCalledButtonCallback );
394 gIsCalledButtonCallback = false;
395 event = Dali::Integration::TouchEvent();
396 event.AddPoint( pointEnter );
397 application.ProcessEvent( event );
399 event = Dali::Integration::TouchEvent();
400 event.AddPoint( pointUpInside );
401 application.ProcessEvent( event );
403 DALI_TEST_CHECK( !gIsCalledButtonCallback );
407 int UtcDaliButtonClickedSignalP(void)
409 ToolkitTestApplication application;
410 tet_infoline(" UtcDaliButtonClickedSignalP");
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 );
418 Stage::GetCurrent().Add( button );
420 application.SendNotification();
421 application.Render();
423 // connect to its touch signal
424 button.ClickedSignal().Connect( &ButtonCallback );
426 Dali::Integration::TouchEvent event;
428 // Test1. Touch point down and up inside the button.
430 gIsCalledButtonCallback = false;
431 event = Dali::Integration::TouchEvent();
432 event.AddPoint( pointDownInside );
433 application.ProcessEvent( event );
435 event = Dali::Integration::TouchEvent();
436 event.AddPoint( pointUpInside );
437 application.ProcessEvent( event );
439 DALI_TEST_CHECK( gIsCalledButtonCallback );
441 // Test2. Touch point down and up outside the button.
443 gIsCalledButtonCallback = false;
444 event = Dali::Integration::TouchEvent();
445 event.AddPoint( pointDownOutside );
446 application.ProcessEvent( event );
448 event = Dali::Integration::TouchEvent();
449 event.AddPoint( pointUpOutside );
450 application.ProcessEvent( event );
452 DALI_TEST_CHECK( !gIsCalledButtonCallback );
454 // Test3. Touch point down inside and up outside the button.
456 gIsCalledButtonCallback = false;
457 event = Dali::Integration::TouchEvent();
458 event.AddPoint( pointDownInside );
459 application.ProcessEvent( event );
461 event = Dali::Integration::TouchEvent();
462 event.AddPoint( pointLeave );
463 application.ProcessEvent( event );
465 event = Dali::Integration::TouchEvent();
466 event.AddPoint( pointUpOutside );
467 application.ProcessEvent( event );
469 DALI_TEST_CHECK( !gIsCalledButtonCallback );
471 // Test4. Touch point down outside and up inside the button.
473 gIsCalledButtonCallback = false;
474 event = Dali::Integration::TouchEvent();
475 event.AddPoint( pointDownOutside );
476 application.ProcessEvent( event );
478 event = Dali::Integration::TouchEvent();
479 event.AddPoint( pointEnter );
480 application.ProcessEvent( event );
482 event = Dali::Integration::TouchEvent();
483 event.AddPoint( pointUpInside );
484 application.ProcessEvent( event );
486 DALI_TEST_CHECK( !gIsCalledButtonCallback );
490 int UtcDaliButtonStateChangedSignalP(void)
492 ToolkitTestApplication application;
493 tet_infoline(" UtcDaliButtonStateChangedSignalP");
495 Button button = PushButton::New();
496 button.SetTogglableButton( true );
498 Stage::GetCurrent().Add( button );
500 application.SendNotification();
501 application.Render();
503 // connect to its signal
504 button.StateChangedSignal().Connect( &ButtonCallback );
506 gIsCalledButtonCallback = false;
507 button.SetSelected( true );
509 DALI_TEST_CHECK( gIsCalledButtonCallback );
511 gIsCalledButtonCallback = false;
512 button.SetSelected( false );
514 DALI_TEST_CHECK( gIsCalledButtonCallback );
518 int UtcDaliButtonSetProperty(void)
520 tet_infoline("UtcDaliButtonSetProperty: ");
521 ToolkitTestApplication application;
523 PushButton pushButton = PushButton::New();
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() );
532 int UtcDaliButtonSize(void)
534 ToolkitTestApplication application;
535 tet_infoline(" UtcDaliButtonSize");
537 ImageActor image01 = ImageActor::New(CreateBufferImage());
538 image01.SetSize( 100, 50 );
540 PushButton pushButton;
544 // Test1 Size is set through Actor API
546 // First an image is set, then SetSize is called.
547 pushButton = PushButton::New();
548 Stage::GetCurrent().Add( pushButton );
550 pushButton.SetBackgroundImage( image01 );
551 pushButton.SetSize( 10.f, 10.f );
553 application.SendNotification();
554 application.Render();
556 size = pushButton.GetCurrentSize();
558 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
559 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );