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/integration-api/events/touch-event-integ.h>
27 #include <dali-toolkit/dali-toolkit.h>
30 using namespace Toolkit;
32 void utc_dali_toolkit_pushbutton_startup(void)
34 test_return_value = TET_UNDEF;
37 void utc_dali_toolkit_pushbutton_cleanup(void)
39 test_return_value = TET_PASS;
45 static bool gPushButtonSelectedState = false;
46 bool PushButtonSelected( Button button )
48 gPushButtonSelectedState = button.IsSelected();
52 static bool gPushButtonPressed = false;
54 static bool PushButtonPressed( Button button )
56 gPushButtonPressed = true;
60 static bool gPushButtonReleased = false;
62 static bool PushButtonReleased( Button button )
64 gPushButtonReleased = true;
68 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
69 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
70 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
71 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
72 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
73 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
74 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
76 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
78 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
81 PixelBuffer* pixbuf = imageData.GetBuffer();
82 unsigned int size = width * height;
84 for( size_t i = 0; i < size; i++ )
86 pixbuf[i*4+0] = 0xFF * color.r;
87 pixbuf[i*4+1] = 0xFF * color.g;
88 pixbuf[i*4+2] = 0xFF * color.b;
89 pixbuf[i*4+3] = 0xFF * color.a;
100 int UtcDaliPushButtonSetGetAutoRepeating(void)
102 ToolkitTestApplication application;
103 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
105 PushButton pushButton = PushButton::New();
107 pushButton.SetAutoRepeating( true );
109 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
111 pushButton.SetAutoRepeating( false );
113 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
115 pushButton.SetAutoRepeating( true );
117 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
121 int UtcDaliPushButtonSetGetTogglableButton(void)
123 ToolkitTestApplication application;
124 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
126 PushButton pushButton = PushButton::New();
128 pushButton.SetTogglableButton( true );
130 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
132 pushButton.SetTogglableButton( false );
134 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
136 pushButton.SetTogglableButton( true );
138 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
142 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
144 ToolkitTestApplication application;
145 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
147 PushButton pushButton = PushButton::New();
149 pushButton.SetAutoRepeating( true );
150 pushButton.SetTogglableButton( true );
152 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
153 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
155 pushButton.SetTogglableButton( true );
156 pushButton.SetAutoRepeating( true );
158 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
159 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
163 int UtcDaliPushButtonSetGetSelected01(void)
165 ToolkitTestApplication application;
166 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
168 PushButton pushButton = PushButton::New();
170 pushButton.SetTogglableButton( true );
171 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
173 gPushButtonSelectedState = false;
174 pushButton.SetSelected( true );
176 DALI_TEST_CHECK( pushButton.IsSelected() );
177 DALI_TEST_CHECK( gPushButtonSelectedState );
179 pushButton.SetSelected( false );
181 DALI_TEST_CHECK( !pushButton.IsSelected() );
182 DALI_TEST_CHECK( !gPushButtonSelectedState );
184 pushButton.SetSelected( true );
186 DALI_TEST_CHECK( pushButton.IsSelected() );
187 DALI_TEST_CHECK( gPushButtonSelectedState );
191 int UtcDaliPushButtonSetGetSelected02(void)
193 ToolkitTestApplication application;
194 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
196 PushButton pushButton = PushButton::New();
198 pushButton.SetTogglableButton( false );
199 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
201 gPushButtonSelectedState = false;
202 pushButton.SetSelected( true );
204 DALI_TEST_CHECK( !pushButton.IsSelected() );
205 DALI_TEST_CHECK( !gPushButtonSelectedState );
207 pushButton.SetSelected( false );
209 DALI_TEST_CHECK( !pushButton.IsSelected() );
210 DALI_TEST_CHECK( !gPushButtonSelectedState );
212 pushButton.SetSelected( true );
214 DALI_TEST_CHECK( !pushButton.IsSelected() );
215 DALI_TEST_CHECK( !gPushButtonSelectedState );
219 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
221 ToolkitTestApplication application;
222 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
224 PushButton pushButton = PushButton::New();
226 pushButton.SetAutoRepeating( true );
228 pushButton.SetInitialAutoRepeatingDelay( 1.f );
229 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
231 pushButton.SetNextAutoRepeatingDelay( 1.f );
232 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
236 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
238 ToolkitTestApplication application;
239 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
241 PushButton pushButton = PushButton::New();
243 bool assert1( false );
244 bool assert2( false );
246 pushButton.SetAutoRepeating( true );
250 pushButton.SetInitialAutoRepeatingDelay( -1.f );
252 catch( Dali::DaliException& e )
254 DALI_TEST_PRINT_ASSERT( e );
255 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
261 pushButton.SetNextAutoRepeatingDelay( -1.f );
263 catch( Dali::DaliException& e )
265 DALI_TEST_PRINT_ASSERT( e );
266 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
270 DALI_TEST_CHECK( assert1 && assert2 );
274 int UtcDaliPushButtonSetImages(void)
276 ToolkitTestApplication application;
277 tet_infoline(" UtcDaliPushButtonSetImages");
281 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
282 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
283 imageActor01.SetSize( 20.f, 20.f );
285 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
286 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
287 imageActor02.SetSize( 40.f, 40.f );
289 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
290 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
291 imageActor03.SetSize( 60.f, 60.f );
293 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
294 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
295 imageActor04.SetSize( 80.f, 80.f );
297 Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
298 ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
299 imageActor05.SetSize( 100.f, 100.f );
302 PushButton pushButton = PushButton::New();
304 application.SendNotification();
305 application.Render();
307 // Just check if check box button size changes when a bigger image is set.
309 pushButton.SetButtonImage( image01 );
311 application.SendNotification();
312 application.Render();
314 size = pushButton.GetButtonImage().GetCurrentSize();
316 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
317 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
319 pushButton.SetButtonImage( imageActor01 );
321 application.SendNotification();
322 application.Render();
324 size = pushButton.GetButtonImage().GetCurrentSize();
326 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
327 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
329 pushButton.SetBackgroundImage( image02 );
331 application.SendNotification();
332 application.Render();
334 size = pushButton.GetBackgroundImage().GetCurrentSize();
336 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
337 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
339 pushButton.SetBackgroundImage( imageActor02 );
341 application.SendNotification();
342 application.Render();
344 size = pushButton.GetBackgroundImage().GetCurrentSize();
346 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
347 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
349 pushButton.SetSelectedImage( image03 );
351 application.SendNotification();
352 application.Render();
354 size = pushButton.GetSelectedImage().GetCurrentSize();
356 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
357 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
359 pushButton.SetSelectedImage( imageActor03 );
361 application.SendNotification();
362 application.Render();
364 size = pushButton.GetSelectedImage().GetCurrentSize();
366 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
367 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
369 pushButton.SetDisabledBackgroundImage( image04 );
371 application.SendNotification();
372 application.Render();
374 size = pushButton.GetDisabledBackgroundImage().GetCurrentSize();
376 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
377 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
379 pushButton.SetDisabledBackgroundImage( imageActor04 );
381 application.SendNotification();
382 application.Render();
384 size = pushButton.GetDisabledBackgroundImage().GetCurrentSize();
386 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
387 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
389 pushButton.SetDisabledImage( image05 );
391 application.SendNotification();
392 application.Render();
394 size = pushButton.GetDisabledImage().GetCurrentSize();
396 DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
397 DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
399 pushButton.SetDisabledImage( imageActor05 );
401 application.SendNotification();
402 application.Render();
404 size = pushButton.GetDisabledImage().GetCurrentSize();
406 DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
407 DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
411 int UtcDaliPushButtonSetLabelText(void)
413 ToolkitTestApplication application;
414 tet_infoline(" UtcDaliPushButtonSetLabelText");
416 const std::string STR( "Hola!" );
418 PushButton pushButton = PushButton::New();
420 application.SendNotification();
421 application.Render();
423 pushButton.SetLabel( STR );
428 int UtcDaliPushButtonPressed(void)
430 ToolkitTestApplication application;
431 tet_infoline(" UtcDaliPushButtonPressed");
433 PushButton pushButton = PushButton::New();
434 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
435 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
436 pushButton.SetPosition( 240, 400 );
437 pushButton.SetSize( 100, 100 );
439 Stage::GetCurrent().Add( pushButton );
441 application.SendNotification();
442 application.Render();
444 gPushButtonPressed = false;
446 // connect to its touch signal
447 pushButton.PressedSignal().Connect( &PushButtonPressed );
449 Dali::Integration::TouchEvent eventDown;
450 eventDown.AddPoint( pointDownInside );
452 // flush the queue and render once
453 application.SendNotification();
454 application.Render();
455 application.ProcessEvent( eventDown );
457 DALI_TEST_CHECK( gPushButtonPressed );
461 int UtcDaliPushButtonReleased(void)
463 ToolkitTestApplication application;
464 tet_infoline(" UtcDaliPushButtonReleased");
466 PushButton pushButton = PushButton::New();
467 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
468 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
469 pushButton.SetPosition( 240, 400 );
470 pushButton.SetSize( 100, 100 );
472 Stage::GetCurrent().Add( pushButton );
474 application.SendNotification();
475 application.Render();
477 // connect to its touch signal
478 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
480 Dali::Integration::TouchEvent event;
482 // Test1. Touch point down and up inside the button.
484 gPushButtonReleased = false;
485 event = Dali::Integration::TouchEvent();
486 event.AddPoint( pointDownInside );
487 application.ProcessEvent( event );
489 event = Dali::Integration::TouchEvent();
490 event.AddPoint( pointUpInside );
491 application.ProcessEvent( event );
493 DALI_TEST_CHECK( gPushButtonReleased );
495 // Test2. Touch point down and up outside the button.
497 gPushButtonReleased = false;
498 event = Dali::Integration::TouchEvent();
499 event.AddPoint( pointDownOutside );
500 application.ProcessEvent( event );
502 event = Dali::Integration::TouchEvent();
503 event.AddPoint( pointUpOutside );
504 application.ProcessEvent( event );
506 DALI_TEST_CHECK( !gPushButtonReleased );
508 // Test3. Touch point down inside and up outside the button.
510 gPushButtonReleased = false;
511 event = Dali::Integration::TouchEvent();
512 event.AddPoint( pointDownInside );
513 application.ProcessEvent( event );
515 event = Dali::Integration::TouchEvent();
516 event.AddPoint( pointLeave );
517 application.ProcessEvent( event );
519 event = Dali::Integration::TouchEvent();
520 event.AddPoint( pointUpOutside );
521 application.ProcessEvent( event );
523 DALI_TEST_CHECK( gPushButtonReleased );
525 // Test4. Touch point down outside and up inside the button.
527 gPushButtonReleased = false;
528 event = Dali::Integration::TouchEvent();
529 event.AddPoint( pointDownOutside );
530 application.ProcessEvent( event );
532 event = Dali::Integration::TouchEvent();
533 event.AddPoint( pointEnter );
534 application.ProcessEvent( event );
536 event = Dali::Integration::TouchEvent();
537 event.AddPoint( pointUpInside );
538 application.ProcessEvent( event );
540 DALI_TEST_CHECK( !gPushButtonReleased );
544 int UtcDaliPushButtonSelected(void)
546 ToolkitTestApplication application;
547 tet_infoline(" UtcDaliPushButtonSelected");
549 PushButton pushButton = PushButton::New();
550 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
551 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
552 pushButton.SetPosition( 240, 400 );
553 pushButton.SetSize( 100, 100 );
555 Stage::GetCurrent().Add( pushButton );
557 application.SendNotification();
558 application.Render();
560 // connect to its touch signal
561 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
563 Dali::Integration::TouchEvent event;
565 // Test1. No togglable button.
567 gPushButtonSelectedState = false;
568 event = Dali::Integration::TouchEvent();
569 event.AddPoint( pointDownInside );
570 application.ProcessEvent( event );
572 event = Dali::Integration::TouchEvent();
573 event.AddPoint( pointUpInside );
574 application.ProcessEvent( event );
576 DALI_TEST_CHECK( !gPushButtonSelectedState );
578 // Set togglable property.
579 pushButton.SetTogglableButton( true );
581 // Test2. Touch point down and up inside the button twice.
582 gPushButtonSelectedState = false;
583 event = Dali::Integration::TouchEvent();
584 event.AddPoint( pointDownInside );
585 application.ProcessEvent( event );
587 event = Dali::Integration::TouchEvent();
588 event.AddPoint( pointUpInside );
589 application.ProcessEvent( event );
591 DALI_TEST_CHECK( gPushButtonSelectedState );
593 event = Dali::Integration::TouchEvent();
594 event.AddPoint( pointDownInside );
595 application.ProcessEvent( event );
597 event = Dali::Integration::TouchEvent();
598 event.AddPoint( pointUpInside );
599 application.ProcessEvent( event );
601 DALI_TEST_CHECK( !gPushButtonSelectedState );
603 // Test3. Touch point down and up outside the button.
605 gPushButtonSelectedState = false;
606 event = Dali::Integration::TouchEvent();
607 event.AddPoint( pointDownOutside );
608 application.ProcessEvent( event );
610 event = Dali::Integration::TouchEvent();
611 event.AddPoint( pointUpOutside );
612 application.ProcessEvent( event );
614 DALI_TEST_CHECK( !gPushButtonSelectedState );
616 // Test4. Touch point down inside and up outside the button.
618 gPushButtonSelectedState = false;
619 event = Dali::Integration::TouchEvent();
620 event.AddPoint( pointDownInside );
621 application.ProcessEvent( event );
623 event = Dali::Integration::TouchEvent();
624 event.AddPoint( pointLeave );
625 application.ProcessEvent( event );
627 event = Dali::Integration::TouchEvent();
628 event.AddPoint( pointUpOutside );
629 application.ProcessEvent( event );
631 DALI_TEST_CHECK( !gPushButtonSelectedState );
633 // Test5. Touch point down outside and up inside the button.
635 gPushButtonSelectedState = false;
636 event = Dali::Integration::TouchEvent();
637 event.AddPoint( pointDownOutside );
638 application.ProcessEvent( event );
640 event = Dali::Integration::TouchEvent();
641 event.AddPoint( pointEnter );
642 application.ProcessEvent( event );
644 event = Dali::Integration::TouchEvent();
645 event.AddPoint( pointUpInside );
646 application.ProcessEvent( event );
648 DALI_TEST_CHECK( !gPushButtonSelectedState );