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 gPushButtonToggleState = false;
46 bool PushButtonToggled( Button button, bool toggled )
48 gPushButtonToggleState = toggled && ( toggled == static_cast<PushButton&>( button ).IsToggled() );
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 UtcDaliPushButtonSetGetToggleButton(void)
123 ToolkitTestApplication application;
124 tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
126 PushButton pushButton = PushButton::New();
128 pushButton.SetToggleButton( true );
130 DALI_TEST_CHECK( pushButton.IsToggleButton() );
132 pushButton.SetToggleButton( false );
134 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
136 pushButton.SetToggleButton( true );
138 DALI_TEST_CHECK( pushButton.IsToggleButton() );
142 int UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton(void)
144 ToolkitTestApplication application;
145 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
147 PushButton pushButton = PushButton::New();
149 pushButton.SetAutoRepeating( true );
150 pushButton.SetToggleButton( true );
152 DALI_TEST_CHECK( pushButton.IsToggleButton() );
153 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
155 pushButton.SetToggleButton( true );
156 pushButton.SetAutoRepeating( true );
158 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
159 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
163 int UtcDaliPushButtonSetGetToggled01(void)
165 ToolkitTestApplication application;
166 tet_infoline(" UtcDaliPushButtonSetGetToggled01");
168 PushButton pushButton = PushButton::New();
170 pushButton.SetToggleButton( true );
171 pushButton.ToggledSignal().Connect( &PushButtonToggled );
173 gPushButtonToggleState = false;
174 pushButton.SetToggled( true );
176 DALI_TEST_CHECK( pushButton.IsToggled() );
177 DALI_TEST_CHECK( gPushButtonToggleState );
179 pushButton.SetToggled( false );
181 DALI_TEST_CHECK( !pushButton.IsToggled() );
182 DALI_TEST_CHECK( !gPushButtonToggleState );
184 pushButton.SetToggled( true );
186 DALI_TEST_CHECK( pushButton.IsToggled() );
187 DALI_TEST_CHECK( gPushButtonToggleState );
191 int UtcDaliPushButtonSetGetToggled02(void)
193 ToolkitTestApplication application;
194 tet_infoline(" UtcDaliPushButtonSetGetToggled02");
196 PushButton pushButton = PushButton::New();
198 pushButton.SetToggleButton( false );
199 pushButton.ToggledSignal().Connect( &PushButtonToggled );
201 gPushButtonToggleState = false;
202 pushButton.SetToggled( true );
204 DALI_TEST_CHECK( !pushButton.IsToggled() );
205 DALI_TEST_CHECK( !gPushButtonToggleState );
207 pushButton.SetToggled( false );
209 DALI_TEST_CHECK( !pushButton.IsToggled() );
210 DALI_TEST_CHECK( !gPushButtonToggleState );
212 pushButton.SetToggled( true );
214 DALI_TEST_CHECK( !pushButton.IsToggled() );
215 DALI_TEST_CHECK( !gPushButtonToggleState );
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.SetPressedImage( image03 );
351 application.SendNotification();
352 application.Render();
354 size = pushButton.GetPressedImage().GetCurrentSize();
356 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
357 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
359 pushButton.SetPressedImage( imageActor03 );
361 application.SendNotification();
362 application.Render();
364 size = pushButton.GetPressedImage().GetCurrentSize();
366 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
367 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
369 pushButton.SetDimmedBackgroundImage( image04 );
371 application.SendNotification();
372 application.Render();
374 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
376 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
377 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
379 pushButton.SetDimmedBackgroundImage( imageActor04 );
381 application.SendNotification();
382 application.Render();
384 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
386 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
387 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
389 pushButton.SetDimmedImage( image05 );
391 application.SendNotification();
392 application.Render();
394 size = pushButton.GetDimmedImage().GetCurrentSize();
396 DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
397 DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
399 pushButton.SetDimmedImage( imageActor05 );
401 application.SendNotification();
402 application.Render();
404 size = pushButton.GetDimmedImage().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();
425 pushButton.SetLabelText( STR );
427 textView = TextView::DownCast( pushButton.GetLabelText() );
428 DALI_TEST_CHECK( STR == textView.GetText() );
430 TextView text = TextView::New( STR );
431 pushButton.SetLabelText( text );
433 textView = TextView::DownCast( pushButton.GetLabelText() );
434 DALI_TEST_CHECK( STR == textView.GetText() );
438 int UtcDaliPushButtonPressed(void)
440 ToolkitTestApplication application;
441 tet_infoline(" UtcDaliPushButtonPressed");
443 PushButton pushButton = PushButton::New();
444 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
445 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
446 pushButton.SetPosition( 240, 400 );
447 pushButton.SetSize( 100, 100 );
449 Stage::GetCurrent().Add( pushButton );
451 application.SendNotification();
452 application.Render();
454 gPushButtonPressed = false;
456 // connect to its touch signal
457 pushButton.PressedSignal().Connect( &PushButtonPressed );
459 Dali::Integration::TouchEvent eventDown;
460 eventDown.AddPoint( pointDownInside );
462 // flush the queue and render once
463 application.SendNotification();
464 application.Render();
465 application.ProcessEvent( eventDown );
467 DALI_TEST_CHECK( gPushButtonPressed );
471 int UtcDaliPushButtonReleased(void)
473 ToolkitTestApplication application;
474 tet_infoline(" UtcDaliPushButtonReleased");
476 PushButton pushButton = PushButton::New();
477 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
478 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
479 pushButton.SetPosition( 240, 400 );
480 pushButton.SetSize( 100, 100 );
482 Stage::GetCurrent().Add( pushButton );
484 application.SendNotification();
485 application.Render();
487 // connect to its touch signal
488 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
490 Dali::Integration::TouchEvent event;
492 // Test1. Touch point down and up inside the button.
494 gPushButtonReleased = false;
495 event = Dali::Integration::TouchEvent();
496 event.AddPoint( pointDownInside );
497 application.ProcessEvent( event );
499 event = Dali::Integration::TouchEvent();
500 event.AddPoint( pointUpInside );
501 application.ProcessEvent( event );
503 DALI_TEST_CHECK( gPushButtonReleased );
505 // Test2. Touch point down and up outside the button.
507 gPushButtonReleased = false;
508 event = Dali::Integration::TouchEvent();
509 event.AddPoint( pointDownOutside );
510 application.ProcessEvent( event );
512 event = Dali::Integration::TouchEvent();
513 event.AddPoint( pointUpOutside );
514 application.ProcessEvent( event );
516 DALI_TEST_CHECK( !gPushButtonReleased );
518 // Test3. Touch point down inside and up outside the button.
520 gPushButtonReleased = false;
521 event = Dali::Integration::TouchEvent();
522 event.AddPoint( pointDownInside );
523 application.ProcessEvent( event );
525 event = Dali::Integration::TouchEvent();
526 event.AddPoint( pointLeave );
527 application.ProcessEvent( event );
529 event = Dali::Integration::TouchEvent();
530 event.AddPoint( pointUpOutside );
531 application.ProcessEvent( event );
533 DALI_TEST_CHECK( gPushButtonReleased );
535 // Test4. Touch point down outside and up inside the button.
537 gPushButtonReleased = false;
538 event = Dali::Integration::TouchEvent();
539 event.AddPoint( pointDownOutside );
540 application.ProcessEvent( event );
542 event = Dali::Integration::TouchEvent();
543 event.AddPoint( pointEnter );
544 application.ProcessEvent( event );
546 event = Dali::Integration::TouchEvent();
547 event.AddPoint( pointUpInside );
548 application.ProcessEvent( event );
550 DALI_TEST_CHECK( !gPushButtonReleased );
554 int UtcDaliPushButtonToggled(void)
556 ToolkitTestApplication application;
557 tet_infoline(" UtcDaliPushButtonToggled");
559 PushButton pushButton = PushButton::New();
560 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
561 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
562 pushButton.SetPosition( 240, 400 );
563 pushButton.SetSize( 100, 100 );
565 Stage::GetCurrent().Add( pushButton );
567 application.SendNotification();
568 application.Render();
570 // connect to its touch signal
571 pushButton.ToggledSignal().Connect( &PushButtonToggled );
573 Dali::Integration::TouchEvent event;
575 // Test1. No toggle button.
577 gPushButtonToggleState = false;
578 event = Dali::Integration::TouchEvent();
579 event.AddPoint( pointDownInside );
580 application.ProcessEvent( event );
582 event = Dali::Integration::TouchEvent();
583 event.AddPoint( pointUpInside );
584 application.ProcessEvent( event );
586 DALI_TEST_CHECK( !gPushButtonToggleState );
588 // Set toggle property.
589 pushButton.SetToggleButton( true );
591 // Test2. Touch point down and up inside the button twice.
592 gPushButtonToggleState = false;
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( gPushButtonToggleState );
603 event = Dali::Integration::TouchEvent();
604 event.AddPoint( pointDownInside );
605 application.ProcessEvent( event );
607 event = Dali::Integration::TouchEvent();
608 event.AddPoint( pointUpInside );
609 application.ProcessEvent( event );
611 DALI_TEST_CHECK( !gPushButtonToggleState );
613 // Test3. Touch point down and up outside the button.
615 gPushButtonToggleState = false;
616 event = Dali::Integration::TouchEvent();
617 event.AddPoint( pointDownOutside );
618 application.ProcessEvent( event );
620 event = Dali::Integration::TouchEvent();
621 event.AddPoint( pointUpOutside );
622 application.ProcessEvent( event );
624 DALI_TEST_CHECK( !gPushButtonToggleState );
626 // Test4. Touch point down inside and up outside the button.
628 gPushButtonToggleState = false;
629 event = Dali::Integration::TouchEvent();
630 event.AddPoint( pointDownInside );
631 application.ProcessEvent( event );
633 event = Dali::Integration::TouchEvent();
634 event.AddPoint( pointLeave );
635 application.ProcessEvent( event );
637 event = Dali::Integration::TouchEvent();
638 event.AddPoint( pointUpOutside );
639 application.ProcessEvent( event );
641 DALI_TEST_CHECK( !gPushButtonToggleState );
643 // Test5. Touch point down outside and up inside the button.
645 gPushButtonToggleState = false;
646 event = Dali::Integration::TouchEvent();
647 event.AddPoint( pointDownOutside );
648 application.ProcessEvent( event );
650 event = Dali::Integration::TouchEvent();
651 event.AddPoint( pointEnter );
652 application.ProcessEvent( event );
654 event = Dali::Integration::TouchEvent();
655 event.AddPoint( pointUpInside );
656 application.ProcessEvent( event );
658 DALI_TEST_CHECK( !gPushButtonToggleState );