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 BufferImage imageData = BufferImage::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;
99 int UtcDaliPushButtonConstructorP(void)
101 TestApplication application;
105 DALI_TEST_CHECK( !button );
109 int UtcDaliPushButtonCopyConstructorP(void)
111 TestApplication application;
113 // Initialize an object, ref count == 1
114 PushButton button = PushButton::New();
116 PushButton copy( button );
117 DALI_TEST_CHECK( copy );
121 int UtcDaliPushButtonAssignmentOperatorP(void)
123 TestApplication application;
125 PushButton button = PushButton::New();
127 PushButton copy( button );
128 DALI_TEST_CHECK( copy );
130 DALI_TEST_CHECK( button == copy );
134 int UtcDaliPushButtonNewP(void)
136 TestApplication application;
138 PushButton button = PushButton::New();
140 DALI_TEST_CHECK( button );
144 int UtcDaliPushButtonDownCastP(void)
146 TestApplication application;
148 PushButton button = PushButton::New();
150 BaseHandle object(button);
152 PushButton button2 = PushButton::DownCast( object );
153 DALI_TEST_CHECK(button2);
155 PushButton button3 = DownCast< PushButton >(object);
156 DALI_TEST_CHECK(button3);
160 int UtcDaliPushButtonDownCastN(void)
162 TestApplication application;
164 BaseHandle unInitializedObject;
166 PushButton button1 = PushButton::DownCast( unInitializedObject );
167 DALI_TEST_CHECK( !button1 );
169 PushButton button2 = DownCast< PushButton >( unInitializedObject );
170 DALI_TEST_CHECK( !button2 );
174 int UtcDaliPushButtonSetButtonImage(void)
176 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliPushButtonSetButtonImage");
179 Image image = CreateSolidColorImage( Color::RED, 10, 10 );
180 ImageActor imageActor = CreateSolidColorActor( Color::RED );
181 imageActor.SetSize( 20, 20 );
183 PushButton pushButton = PushButton::New();
184 Stage::GetCurrent().Add( pushButton );
186 application.SendNotification();
187 application.Render();
189 pushButton.SetSize( Vector2( 20.0f, 20.0f ) );
190 pushButton.SetButtonImage( image );
192 DALI_TEST_CHECK( pushButton.GetButtonImage() );
194 application.SendNotification();
195 application.Render();
197 Vector3 size = pushButton.GetCurrentSize();
199 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
200 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
202 pushButton.SetButtonImage( imageActor );
204 DALI_TEST_CHECK( pushButton.GetButtonImage() );
208 int UtcDaliPushButtonSetBackgroundImageP(void)
210 ToolkitTestApplication application;
211 tet_infoline(" UtcDaliPushButtonSetBackgroundImageP");
213 Image image = CreateSolidColorImage( Color::RED, 10, 10 );
214 ImageActor imageActor = CreateSolidColorActor( Color::RED );
215 imageActor.SetSize( 20, 20 );
217 PushButton pushButton = PushButton::New();
219 pushButton.SetBackgroundImage( image );
221 DALI_TEST_CHECK( pushButton.GetBackgroundImage() );
223 pushButton.SetBackgroundImage( imageActor );
225 DALI_TEST_CHECK( pushButton.GetBackgroundImage() );
230 int UtcDaliPushButtonSetSelectedImageP(void)
232 ToolkitTestApplication application;
233 tet_infoline(" UtcDaliPushButtonSetSelectedImageP");
235 Image image = CreateSolidColorImage( Color::RED, 10, 10 );
236 ImageActor imageActor = CreateSolidColorActor( Color::RED );
237 imageActor.SetSize( 20, 20 );
239 PushButton pushButton = PushButton::New();
241 pushButton.SetSelectedImage( image );
243 DALI_TEST_CHECK( pushButton.GetSelectedImage() );
245 pushButton.SetSelectedImage( imageActor );
247 DALI_TEST_CHECK( pushButton.GetSelectedImage() );
252 int UtcDaliPushButtonSetSelectedBackgroundImageP(void)
254 ToolkitTestApplication application;
255 tet_infoline(" UtcDaliPushButtonSetSelectedBackgroundImageP");
257 Image image = CreateSolidColorImage( Color::RED, 10, 10 );
258 ImageActor imageActor = CreateSolidColorActor( Color::RED );
259 imageActor.SetSize( 20, 20 );
261 PushButton pushButton = PushButton::New();
263 pushButton.SetSelectedBackgroundImage( image );
265 DALI_TEST_CHECK( pushButton.GetSelectedBackgroundImage() );
267 pushButton.SetSelectedBackgroundImage( imageActor );
269 DALI_TEST_CHECK( pushButton.GetSelectedBackgroundImage() );
274 int UtcDaliPushButtonSetDisabledBackgroundImageP(void)
276 ToolkitTestApplication application;
277 tet_infoline(" UtcDaliPushButtonSetDisabledBackgroundImageP");
279 Image image = CreateSolidColorImage( Color::RED, 10, 10 );
280 ImageActor imageActor = CreateSolidColorActor( Color::RED );
281 imageActor.SetSize( 20, 20 );
283 PushButton pushButton = PushButton::New();
285 pushButton.SetDisabledBackgroundImage( image );
287 DALI_TEST_CHECK( pushButton.GetDisabledBackgroundImage() );
289 pushButton.SetDisabledBackgroundImage( imageActor );
291 DALI_TEST_CHECK( pushButton.GetDisabledBackgroundImage() );
296 int UtcDaliPushButtonSetDisabledImageP(void)
298 ToolkitTestApplication application;
299 tet_infoline(" UtcDaliPushButtonSetDisabledImageP");
301 Image image = CreateSolidColorImage( Color::RED, 10, 10 );
302 ImageActor imageActor = CreateSolidColorActor( Color::RED );
303 imageActor.SetSize( 20, 20 );
305 PushButton pushButton = PushButton::New();
307 pushButton.SetDisabledImage( image );
309 DALI_TEST_CHECK( pushButton.GetDisabledImage() );
311 pushButton.SetDisabledImage( imageActor );
313 DALI_TEST_CHECK( pushButton.GetDisabledImage() );
318 int UtcDaliPushButtonSetGetAutoRepeating(void)
320 ToolkitTestApplication application;
321 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
323 PushButton pushButton = PushButton::New();
325 pushButton.SetAutoRepeating( true );
327 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
329 pushButton.SetAutoRepeating( false );
331 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
333 pushButton.SetAutoRepeating( true );
335 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
339 int UtcDaliPushButtonSetGetTogglableButton(void)
341 ToolkitTestApplication application;
342 tet_infoline(" UtcDaliPushButtonSetGetTogglableButton");
344 PushButton pushButton = PushButton::New();
346 pushButton.SetTogglableButton( true );
348 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
350 pushButton.SetTogglableButton( false );
352 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
354 pushButton.SetTogglableButton( true );
356 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
360 int UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton(void)
362 ToolkitTestApplication application;
363 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndTogglableButton");
365 PushButton pushButton = PushButton::New();
367 pushButton.SetAutoRepeating( true );
368 pushButton.SetTogglableButton( true );
370 DALI_TEST_CHECK( pushButton.IsTogglableButton() );
371 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
373 pushButton.SetTogglableButton( true );
374 pushButton.SetAutoRepeating( true );
376 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
377 DALI_TEST_CHECK( !pushButton.IsTogglableButton() );
381 int UtcDaliPushButtonSetGetSelected01(void)
383 ToolkitTestApplication application;
384 tet_infoline(" UtcDaliPushButtonSetGetSelected01");
386 PushButton pushButton = PushButton::New();
388 pushButton.SetTogglableButton( true );
389 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
391 gPushButtonSelectedState = false;
392 pushButton.SetSelected( true );
394 DALI_TEST_CHECK( pushButton.IsSelected() );
395 DALI_TEST_CHECK( gPushButtonSelectedState );
397 pushButton.SetSelected( false );
399 DALI_TEST_CHECK( !pushButton.IsSelected() );
400 DALI_TEST_CHECK( !gPushButtonSelectedState );
402 pushButton.SetSelected( true );
404 DALI_TEST_CHECK( pushButton.IsSelected() );
405 DALI_TEST_CHECK( gPushButtonSelectedState );
409 int UtcDaliPushButtonSetGetSelected02(void)
411 ToolkitTestApplication application;
412 tet_infoline(" UtcDaliPushButtonSetGetSelected02");
414 PushButton pushButton = PushButton::New();
416 pushButton.SetTogglableButton( false );
417 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
419 gPushButtonSelectedState = false;
420 pushButton.SetSelected( true );
422 DALI_TEST_CHECK( !pushButton.IsSelected() );
423 DALI_TEST_CHECK( !gPushButtonSelectedState );
425 pushButton.SetSelected( false );
427 DALI_TEST_CHECK( !pushButton.IsSelected() );
428 DALI_TEST_CHECK( !gPushButtonSelectedState );
430 pushButton.SetSelected( true );
432 DALI_TEST_CHECK( !pushButton.IsSelected() );
433 DALI_TEST_CHECK( !gPushButtonSelectedState );
437 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
439 ToolkitTestApplication application;
440 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
442 PushButton pushButton = PushButton::New();
444 pushButton.SetAutoRepeating( true );
446 pushButton.SetInitialAutoRepeatingDelay( 1.f );
447 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
449 pushButton.SetNextAutoRepeatingDelay( 1.f );
450 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
454 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
456 ToolkitTestApplication application;
457 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
459 PushButton pushButton = PushButton::New();
461 bool assert1( false );
462 bool assert2( false );
464 pushButton.SetAutoRepeating( true );
468 pushButton.SetInitialAutoRepeatingDelay( -1.f );
470 catch( Dali::DaliException& e )
472 DALI_TEST_PRINT_ASSERT( e );
473 DALI_TEST_EQUALS(e.condition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
479 pushButton.SetNextAutoRepeatingDelay( -1.f );
481 catch( Dali::DaliException& e )
483 DALI_TEST_PRINT_ASSERT( e );
484 DALI_TEST_EQUALS(e.condition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
488 DALI_TEST_CHECK( assert1 && assert2 );
492 int UtcDaliPushButtonSetLabelText(void)
494 ToolkitTestApplication application;
495 tet_infoline(" UtcDaliPushButtonSetLabelText");
497 const std::string STR( "Hola!" );
499 PushButton pushButton = PushButton::New();
501 application.SendNotification();
502 application.Render();
504 pushButton.SetLabel( STR );
506 TextLabel label = TextLabel::DownCast( pushButton.GetLabel() );
507 DALI_TEST_CHECK( STR == label.GetProperty<std::string>( TextLabel::Property::TEXT ) );
512 int UtcDaliPushButtonPressed(void)
514 ToolkitTestApplication application;
515 tet_infoline(" UtcDaliPushButtonPressed");
517 PushButton pushButton = PushButton::New();
518 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
519 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
520 pushButton.SetPosition( 240, 400 );
521 pushButton.SetSize( 100, 100 );
523 Stage::GetCurrent().Add( pushButton );
525 application.SendNotification();
526 application.Render();
528 gPushButtonPressed = false;
530 // connect to its touch signal
531 pushButton.PressedSignal().Connect( &PushButtonPressed );
533 Dali::Integration::TouchEvent eventDown;
534 eventDown.AddPoint( pointDownInside );
536 // flush the queue and render once
537 application.SendNotification();
538 application.Render();
539 application.ProcessEvent( eventDown );
541 DALI_TEST_CHECK( gPushButtonPressed );
545 int UtcDaliPushButtonReleased(void)
547 ToolkitTestApplication application;
548 tet_infoline(" UtcDaliPushButtonReleased");
550 PushButton pushButton = PushButton::New();
551 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
552 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
553 pushButton.SetPosition( 240, 400 );
554 pushButton.SetSize( 100, 100 );
556 Stage::GetCurrent().Add( pushButton );
558 application.SendNotification();
559 application.Render();
561 // connect to its touch signal
562 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
564 Dali::Integration::TouchEvent event;
566 // Test1. Touch point down and up inside the button.
568 gPushButtonReleased = false;
569 event = Dali::Integration::TouchEvent();
570 event.AddPoint( pointDownInside );
571 application.ProcessEvent( event );
573 event = Dali::Integration::TouchEvent();
574 event.AddPoint( pointUpInside );
575 application.ProcessEvent( event );
577 DALI_TEST_CHECK( gPushButtonReleased );
579 // Test2. Touch point down and up outside the button.
581 gPushButtonReleased = false;
582 event = Dali::Integration::TouchEvent();
583 event.AddPoint( pointDownOutside );
584 application.ProcessEvent( event );
586 event = Dali::Integration::TouchEvent();
587 event.AddPoint( pointUpOutside );
588 application.ProcessEvent( event );
590 DALI_TEST_CHECK( !gPushButtonReleased );
592 // Test3. Touch point down inside and up outside the button.
594 gPushButtonReleased = false;
595 event = Dali::Integration::TouchEvent();
596 event.AddPoint( pointDownInside );
597 application.ProcessEvent( event );
599 event = Dali::Integration::TouchEvent();
600 event.AddPoint( pointLeave );
601 application.ProcessEvent( event );
603 event = Dali::Integration::TouchEvent();
604 event.AddPoint( pointUpOutside );
605 application.ProcessEvent( event );
607 DALI_TEST_CHECK( gPushButtonReleased );
609 // Test4. Touch point down outside and up inside the button.
611 gPushButtonReleased = false;
612 event = Dali::Integration::TouchEvent();
613 event.AddPoint( pointDownOutside );
614 application.ProcessEvent( event );
616 event = Dali::Integration::TouchEvent();
617 event.AddPoint( pointEnter );
618 application.ProcessEvent( event );
620 event = Dali::Integration::TouchEvent();
621 event.AddPoint( pointUpInside );
622 application.ProcessEvent( event );
624 DALI_TEST_CHECK( !gPushButtonReleased );
628 int UtcDaliPushButtonSelected(void)
630 ToolkitTestApplication application;
631 tet_infoline(" UtcDaliPushButtonSelected");
633 PushButton pushButton = PushButton::New();
634 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
635 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
636 pushButton.SetPosition( 240, 400 );
637 pushButton.SetSize( 100, 100 );
639 Stage::GetCurrent().Add( pushButton );
641 application.SendNotification();
642 application.Render();
644 // connect to its touch signal
645 pushButton.StateChangedSignal().Connect( &PushButtonSelected );
647 Dali::Integration::TouchEvent event;
649 // Test1. No togglable button.
651 gPushButtonSelectedState = false;
652 event = Dali::Integration::TouchEvent();
653 event.AddPoint( pointDownInside );
654 application.ProcessEvent( event );
656 event = Dali::Integration::TouchEvent();
657 event.AddPoint( pointUpInside );
658 application.ProcessEvent( event );
660 DALI_TEST_CHECK( !gPushButtonSelectedState );
662 // Set togglable property.
663 pushButton.SetTogglableButton( true );
665 // Test2. Touch point down and up inside the button twice.
666 gPushButtonSelectedState = false;
667 event = Dali::Integration::TouchEvent();
668 event.AddPoint( pointDownInside );
669 application.ProcessEvent( event );
671 event = Dali::Integration::TouchEvent();
672 event.AddPoint( pointUpInside );
673 application.ProcessEvent( event );
675 DALI_TEST_CHECK( gPushButtonSelectedState );
677 event = Dali::Integration::TouchEvent();
678 event.AddPoint( pointDownInside );
679 application.ProcessEvent( event );
681 event = Dali::Integration::TouchEvent();
682 event.AddPoint( pointUpInside );
683 application.ProcessEvent( event );
685 DALI_TEST_CHECK( !gPushButtonSelectedState );
687 // Test3. Touch point down and up outside the button.
689 gPushButtonSelectedState = false;
690 event = Dali::Integration::TouchEvent();
691 event.AddPoint( pointDownOutside );
692 application.ProcessEvent( event );
694 event = Dali::Integration::TouchEvent();
695 event.AddPoint( pointUpOutside );
696 application.ProcessEvent( event );
698 DALI_TEST_CHECK( !gPushButtonSelectedState );
700 // Test4. Touch point down inside and up outside the button.
702 gPushButtonSelectedState = false;
703 event = Dali::Integration::TouchEvent();
704 event.AddPoint( pointDownInside );
705 application.ProcessEvent( event );
707 event = Dali::Integration::TouchEvent();
708 event.AddPoint( pointLeave );
709 application.ProcessEvent( event );
711 event = Dali::Integration::TouchEvent();
712 event.AddPoint( pointUpOutside );
713 application.ProcessEvent( event );
715 DALI_TEST_CHECK( !gPushButtonSelectedState );
717 // Test5. Touch point down outside and up inside the button.
719 gPushButtonSelectedState = false;
720 event = Dali::Integration::TouchEvent();
721 event.AddPoint( pointDownOutside );
722 application.ProcessEvent( event );
724 event = Dali::Integration::TouchEvent();
725 event.AddPoint( pointEnter );
726 application.ProcessEvent( event );
728 event = Dali::Integration::TouchEvent();
729 event.AddPoint( pointUpInside );
730 application.ProcessEvent( event );
732 DALI_TEST_CHECK( !gPushButtonSelectedState );