2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali-toolkit/dali-toolkit.h>
29 using namespace Toolkit;
31 void utc_dali_toolkit_pushbutton_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_pushbutton_cleanup(void)
38 test_return_value = TET_PASS;
44 static bool gPushButtonToggleState = false;
45 bool PushButtonToggled( Button button, bool toggled )
47 gPushButtonToggleState = toggled && ( toggled == static_cast<PushButton&>( button ).IsToggled() );
51 static bool gPushButtonPressed = false;
53 static bool PushButtonPressed( Button button )
55 gPushButtonPressed = true;
59 static bool gPushButtonReleased = false;
61 static bool PushButtonReleased( Button button )
63 gPushButtonReleased = true;
67 const Dali::TouchPoint pointDownInside( 0, TouchPoint::Down, 240, 400 );
68 const Dali::TouchPoint pointUpInside( 0, TouchPoint::Up, 240, 400 );
69 const Dali::TouchPoint pointLeave( 0, TouchPoint::Leave, 240, 400 );
70 const Dali::TouchPoint pointEnter( 0, TouchPoint::Motion, 240, 400 );
71 const Dali::TouchPoint pointMotionOut( 0, TouchPoint::Motion, 10, 10 );
72 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10, 10 );
73 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10, 10 );
75 static bool gOnTouchPointInterrupted = false;
78 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
80 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
83 PixelBuffer* pixbuf = imageData.GetBuffer();
84 unsigned int size = width * height;
86 for( size_t i = 0; i < size; i++ )
88 pixbuf[i*4+0] = 0xFF * color.r;
89 pixbuf[i*4+1] = 0xFF * color.g;
90 pixbuf[i*4+2] = 0xFF * color.b;
91 pixbuf[i*4+3] = 0xFF * color.a;
102 int UtcDaliPushButtonSetGetAutoRepeating(void)
104 ToolkitTestApplication application;
105 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
107 PushButton pushButton = PushButton::New();
109 pushButton.SetAutoRepeating( true );
111 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
113 pushButton.SetAutoRepeating( false );
115 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
117 pushButton.SetAutoRepeating( true );
119 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
123 int UtcDaliPushButtonSetGetToggleButton(void)
125 ToolkitTestApplication application;
126 tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
128 PushButton pushButton = PushButton::New();
130 pushButton.SetToggleButton( true );
132 DALI_TEST_CHECK( pushButton.IsToggleButton() );
134 pushButton.SetToggleButton( false );
136 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
138 pushButton.SetToggleButton( true );
140 DALI_TEST_CHECK( pushButton.IsToggleButton() );
144 int UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton(void)
146 ToolkitTestApplication application;
147 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
149 PushButton pushButton = PushButton::New();
151 pushButton.SetAutoRepeating( true );
152 pushButton.SetToggleButton( true );
154 DALI_TEST_CHECK( pushButton.IsToggleButton() );
155 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
157 pushButton.SetToggleButton( true );
158 pushButton.SetAutoRepeating( true );
160 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
161 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
165 int UtcDaliPushButtonSetGetToggled01(void)
167 ToolkitTestApplication application;
168 tet_infoline(" UtcDaliPushButtonSetGetToggled01");
170 PushButton pushButton = PushButton::New();
172 pushButton.SetToggleButton( true );
173 pushButton.ToggledSignal().Connect( &PushButtonToggled );
175 gPushButtonToggleState = false;
176 pushButton.SetToggled( true );
178 DALI_TEST_CHECK( pushButton.IsToggled() );
179 DALI_TEST_CHECK( gPushButtonToggleState );
181 pushButton.SetToggled( false );
183 DALI_TEST_CHECK( !pushButton.IsToggled() );
184 DALI_TEST_CHECK( !gPushButtonToggleState );
186 pushButton.SetToggled( true );
188 DALI_TEST_CHECK( pushButton.IsToggled() );
189 DALI_TEST_CHECK( gPushButtonToggleState );
193 int UtcDaliPushButtonSetGetToggled02(void)
195 ToolkitTestApplication application;
196 tet_infoline(" UtcDaliPushButtonSetGetToggled02");
198 PushButton pushButton = PushButton::New();
200 pushButton.SetToggleButton( false );
201 pushButton.ToggledSignal().Connect( &PushButtonToggled );
203 gPushButtonToggleState = false;
204 pushButton.SetToggled( true );
206 DALI_TEST_CHECK( !pushButton.IsToggled() );
207 DALI_TEST_CHECK( !gPushButtonToggleState );
209 pushButton.SetToggled( false );
211 DALI_TEST_CHECK( !pushButton.IsToggled() );
212 DALI_TEST_CHECK( !gPushButtonToggleState );
214 pushButton.SetToggled( true );
216 DALI_TEST_CHECK( !pushButton.IsToggled() );
217 DALI_TEST_CHECK( !gPushButtonToggleState );
221 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
223 ToolkitTestApplication application;
224 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
226 PushButton pushButton = PushButton::New();
228 pushButton.SetAutoRepeating( true );
230 pushButton.SetInitialAutoRepeatingDelay( 1.f );
231 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
233 pushButton.SetNextAutoRepeatingDelay( 1.f );
234 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
238 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
240 ToolkitTestApplication application;
241 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
243 PushButton pushButton = PushButton::New();
245 bool assert1( false );
246 bool assert2( false );
248 pushButton.SetAutoRepeating( true );
252 pushButton.SetInitialAutoRepeatingDelay( -1.f );
254 catch( Dali::DaliException& e )
256 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
257 DALI_TEST_EQUALS(e.mCondition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
263 pushButton.SetNextAutoRepeatingDelay( -1.f );
265 catch( Dali::DaliException& e )
267 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
268 DALI_TEST_EQUALS(e.mCondition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
272 DALI_TEST_CHECK( assert1 && assert2 );
276 int UtcDaliPushButtonSetImages(void)
278 ToolkitTestApplication application;
279 tet_infoline(" UtcDaliPushButtonSetImages");
283 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
284 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
285 imageActor01.SetSize( 20.f, 20.f );
287 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
288 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
289 imageActor02.SetSize( 40.f, 40.f );
291 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
292 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
293 imageActor03.SetSize( 60.f, 60.f );
295 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
296 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
297 imageActor04.SetSize( 80.f, 80.f );
299 Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
300 ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
301 imageActor05.SetSize( 100.f, 100.f );
304 PushButton pushButton = PushButton::New();
306 application.SendNotification();
307 application.Render();
309 // Just check if check box button size changes when a bigger image is set.
311 pushButton.SetButtonImage( image01 );
313 application.SendNotification();
314 application.Render();
316 size = pushButton.GetButtonImage().GetCurrentSize();
318 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
319 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
321 pushButton.SetButtonImage( imageActor01 );
323 application.SendNotification();
324 application.Render();
326 size = pushButton.GetButtonImage().GetCurrentSize();
328 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
329 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
331 pushButton.SetBackgroundImage( image02 );
333 application.SendNotification();
334 application.Render();
336 size = pushButton.GetBackgroundImage().GetCurrentSize();
338 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
339 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
341 pushButton.SetBackgroundImage( imageActor02 );
343 application.SendNotification();
344 application.Render();
346 size = pushButton.GetBackgroundImage().GetCurrentSize();
348 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
349 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
351 pushButton.SetPressedImage( image03 );
353 application.SendNotification();
354 application.Render();
356 size = pushButton.GetPressedImage().GetCurrentSize();
358 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
359 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
361 pushButton.SetPressedImage( imageActor03 );
363 application.SendNotification();
364 application.Render();
366 size = pushButton.GetPressedImage().GetCurrentSize();
368 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
369 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
371 pushButton.SetDimmedBackgroundImage( image04 );
373 application.SendNotification();
374 application.Render();
376 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
378 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
379 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
381 pushButton.SetDimmedBackgroundImage( imageActor04 );
383 application.SendNotification();
384 application.Render();
386 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
388 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
389 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
391 pushButton.SetDimmedImage( image05 );
393 application.SendNotification();
394 application.Render();
396 size = pushButton.GetDimmedImage().GetCurrentSize();
398 DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
399 DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
401 pushButton.SetDimmedImage( imageActor05 );
403 application.SendNotification();
404 application.Render();
406 size = pushButton.GetDimmedImage().GetCurrentSize();
408 DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
409 DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
413 int UtcDaliPushButtonSetLabelText(void)
415 ToolkitTestApplication application;
416 tet_infoline(" UtcDaliPushButtonSetLabelText");
418 const std::string STR( "Hola!" );
420 PushButton pushButton = PushButton::New();
422 application.SendNotification();
423 application.Render();
427 pushButton.SetLabelText( STR );
429 textView = TextView::DownCast( pushButton.GetLabelText() );
430 DALI_TEST_CHECK( STR == textView.GetText() );
432 TextView text = TextView::New( STR );
433 pushButton.SetLabelText( text );
435 textView = TextView::DownCast( pushButton.GetLabelText() );
436 DALI_TEST_CHECK( STR == textView.GetText() );
440 int UtcDaliPushButtonPressed(void)
442 ToolkitTestApplication application;
443 tet_infoline(" UtcDaliPushButtonPressed");
445 PushButton pushButton = PushButton::New();
446 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
447 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
448 pushButton.SetPosition( 240, 400 );
449 pushButton.SetSize( 100, 100 );
451 Stage::GetCurrent().Add( pushButton );
453 application.SendNotification();
454 application.Render();
456 gPushButtonPressed = false;
458 // connect to its touch signal
459 pushButton.PressedSignal().Connect( &PushButtonPressed );
461 Dali::Integration::TouchEvent eventDown;
462 eventDown.AddPoint( pointDownInside );
464 // flush the queue and render once
465 application.SendNotification();
466 application.Render();
467 application.ProcessEvent( eventDown );
469 DALI_TEST_CHECK( gPushButtonPressed );
473 int UtcDaliPushButtonReleased(void)
475 ToolkitTestApplication application;
476 tet_infoline(" UtcDaliPushButtonReleased");
478 PushButton pushButton = PushButton::New();
479 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
480 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
481 pushButton.SetPosition( 240, 400 );
482 pushButton.SetSize( 100, 100 );
484 Stage::GetCurrent().Add( pushButton );
486 application.SendNotification();
487 application.Render();
489 // connect to its touch signal
490 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
492 Dali::Integration::TouchEvent event;
494 // Test1. Touch point down and up inside the button.
496 gPushButtonReleased = false;
497 event = Dali::Integration::TouchEvent();
498 event.AddPoint( pointDownInside );
499 application.ProcessEvent( event );
501 event = Dali::Integration::TouchEvent();
502 event.AddPoint( pointUpInside );
503 application.ProcessEvent( event );
505 DALI_TEST_CHECK( gPushButtonReleased );
507 // Test2. Touch point down and up outside the button.
509 gPushButtonReleased = false;
510 event = Dali::Integration::TouchEvent();
511 event.AddPoint( pointDownOutside );
512 application.ProcessEvent( event );
514 event = Dali::Integration::TouchEvent();
515 event.AddPoint( pointUpOutside );
516 application.ProcessEvent( event );
518 DALI_TEST_CHECK( !gPushButtonReleased );
520 // Test3. Touch point down inside and up outside the button.
522 gPushButtonReleased = false;
523 event = Dali::Integration::TouchEvent();
524 event.AddPoint( pointDownInside );
525 application.ProcessEvent( event );
527 event = Dali::Integration::TouchEvent();
528 event.AddPoint( pointLeave );
529 application.ProcessEvent( event );
531 event = Dali::Integration::TouchEvent();
532 event.AddPoint( pointUpOutside );
533 application.ProcessEvent( event );
535 DALI_TEST_CHECK( gPushButtonReleased );
537 // Test4. Touch point down outside and up inside the button.
539 gPushButtonReleased = false;
540 event = Dali::Integration::TouchEvent();
541 event.AddPoint( pointDownOutside );
542 application.ProcessEvent( event );
544 event = Dali::Integration::TouchEvent();
545 event.AddPoint( pointEnter );
546 application.ProcessEvent( event );
548 event = Dali::Integration::TouchEvent();
549 event.AddPoint( pointUpInside );
550 application.ProcessEvent( event );
552 DALI_TEST_CHECK( !gPushButtonReleased );
556 int UtcDaliPushButtonToggled(void)
558 ToolkitTestApplication application;
559 tet_infoline(" UtcDaliPushButtonToggled");
561 PushButton pushButton = PushButton::New();
562 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
563 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
564 pushButton.SetPosition( 240, 400 );
565 pushButton.SetSize( 100, 100 );
567 Stage::GetCurrent().Add( pushButton );
569 application.SendNotification();
570 application.Render();
572 // connect to its touch signal
573 pushButton.ToggledSignal().Connect( &PushButtonToggled );
575 Dali::Integration::TouchEvent event;
577 // Test1. No toggle button.
579 gPushButtonToggleState = false;
580 event = Dali::Integration::TouchEvent();
581 event.AddPoint( pointDownInside );
582 application.ProcessEvent( event );
584 event = Dali::Integration::TouchEvent();
585 event.AddPoint( pointUpInside );
586 application.ProcessEvent( event );
588 DALI_TEST_CHECK( !gPushButtonToggleState );
590 // Set toggle property.
591 pushButton.SetToggleButton( true );
593 // Test2. Touch point down and up inside the button twice.
594 gPushButtonToggleState = false;
595 event = Dali::Integration::TouchEvent();
596 event.AddPoint( pointDownInside );
597 application.ProcessEvent( event );
599 event = Dali::Integration::TouchEvent();
600 event.AddPoint( pointUpInside );
601 application.ProcessEvent( event );
603 DALI_TEST_CHECK( gPushButtonToggleState );
605 event = Dali::Integration::TouchEvent();
606 event.AddPoint( pointDownInside );
607 application.ProcessEvent( event );
609 event = Dali::Integration::TouchEvent();
610 event.AddPoint( pointUpInside );
611 application.ProcessEvent( event );
613 DALI_TEST_CHECK( !gPushButtonToggleState );
615 // Test3. Touch point down and up outside the button.
617 gPushButtonToggleState = false;
618 event = Dali::Integration::TouchEvent();
619 event.AddPoint( pointDownOutside );
620 application.ProcessEvent( event );
622 event = Dali::Integration::TouchEvent();
623 event.AddPoint( pointUpOutside );
624 application.ProcessEvent( event );
626 DALI_TEST_CHECK( !gPushButtonToggleState );
628 // Test4. Touch point down inside and up outside the button.
630 gPushButtonToggleState = false;
631 event = Dali::Integration::TouchEvent();
632 event.AddPoint( pointDownInside );
633 application.ProcessEvent( event );
635 event = Dali::Integration::TouchEvent();
636 event.AddPoint( pointLeave );
637 application.ProcessEvent( event );
639 event = Dali::Integration::TouchEvent();
640 event.AddPoint( pointUpOutside );
641 application.ProcessEvent( event );
643 DALI_TEST_CHECK( !gPushButtonToggleState );
645 // Test5. Touch point down outside and up inside the button.
647 gPushButtonToggleState = false;
648 event = Dali::Integration::TouchEvent();
649 event.AddPoint( pointDownOutside );
650 application.ProcessEvent( event );
652 event = Dali::Integration::TouchEvent();
653 event.AddPoint( pointEnter );
654 application.ProcessEvent( event );
656 event = Dali::Integration::TouchEvent();
657 event.AddPoint( pointUpInside );
658 application.ProcessEvent( event );
660 DALI_TEST_CHECK( !gPushButtonToggleState );