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 static bool gOnTouchPointInterrupted = false;
79 Image CreateSolidColorImage( const Vector4& color, unsigned int width, unsigned int height )
81 BitmapImage imageData = BitmapImage::New( width, height, Pixel::RGBA8888 );
84 PixelBuffer* pixbuf = imageData.GetBuffer();
85 unsigned int size = width * height;
87 for( size_t i = 0; i < size; i++ )
89 pixbuf[i*4+0] = 0xFF * color.r;
90 pixbuf[i*4+1] = 0xFF * color.g;
91 pixbuf[i*4+2] = 0xFF * color.b;
92 pixbuf[i*4+3] = 0xFF * color.a;
103 int UtcDaliPushButtonSetGetAutoRepeating(void)
105 ToolkitTestApplication application;
106 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeating");
108 PushButton pushButton = PushButton::New();
110 pushButton.SetAutoRepeating( true );
112 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
114 pushButton.SetAutoRepeating( false );
116 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
118 pushButton.SetAutoRepeating( true );
120 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
124 int UtcDaliPushButtonSetGetToggleButton(void)
126 ToolkitTestApplication application;
127 tet_infoline(" UtcDaliPushButtonSetGetToggleButton");
129 PushButton pushButton = PushButton::New();
131 pushButton.SetToggleButton( true );
133 DALI_TEST_CHECK( pushButton.IsToggleButton() );
135 pushButton.SetToggleButton( false );
137 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
139 pushButton.SetToggleButton( true );
141 DALI_TEST_CHECK( pushButton.IsToggleButton() );
145 int UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton(void)
147 ToolkitTestApplication application;
148 tet_infoline(" UtcDaliPushButtonSetGetAutoRepeatingAndToggleButton");
150 PushButton pushButton = PushButton::New();
152 pushButton.SetAutoRepeating( true );
153 pushButton.SetToggleButton( true );
155 DALI_TEST_CHECK( pushButton.IsToggleButton() );
156 DALI_TEST_CHECK( !pushButton.IsAutoRepeating() );
158 pushButton.SetToggleButton( true );
159 pushButton.SetAutoRepeating( true );
161 DALI_TEST_CHECK( pushButton.IsAutoRepeating() );
162 DALI_TEST_CHECK( !pushButton.IsToggleButton() );
166 int UtcDaliPushButtonSetGetToggled01(void)
168 ToolkitTestApplication application;
169 tet_infoline(" UtcDaliPushButtonSetGetToggled01");
171 PushButton pushButton = PushButton::New();
173 pushButton.SetToggleButton( true );
174 pushButton.ToggledSignal().Connect( &PushButtonToggled );
176 gPushButtonToggleState = false;
177 pushButton.SetToggled( true );
179 DALI_TEST_CHECK( pushButton.IsToggled() );
180 DALI_TEST_CHECK( gPushButtonToggleState );
182 pushButton.SetToggled( false );
184 DALI_TEST_CHECK( !pushButton.IsToggled() );
185 DALI_TEST_CHECK( !gPushButtonToggleState );
187 pushButton.SetToggled( true );
189 DALI_TEST_CHECK( pushButton.IsToggled() );
190 DALI_TEST_CHECK( gPushButtonToggleState );
194 int UtcDaliPushButtonSetGetToggled02(void)
196 ToolkitTestApplication application;
197 tet_infoline(" UtcDaliPushButtonSetGetToggled02");
199 PushButton pushButton = PushButton::New();
201 pushButton.SetToggleButton( false );
202 pushButton.ToggledSignal().Connect( &PushButtonToggled );
204 gPushButtonToggleState = false;
205 pushButton.SetToggled( true );
207 DALI_TEST_CHECK( !pushButton.IsToggled() );
208 DALI_TEST_CHECK( !gPushButtonToggleState );
210 pushButton.SetToggled( false );
212 DALI_TEST_CHECK( !pushButton.IsToggled() );
213 DALI_TEST_CHECK( !gPushButtonToggleState );
215 pushButton.SetToggled( true );
217 DALI_TEST_CHECK( !pushButton.IsToggled() );
218 DALI_TEST_CHECK( !gPushButtonToggleState );
222 int UtcDaliPushButtonSetGetAutorepeatingDelayValues01(void)
224 ToolkitTestApplication application;
225 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues01");
227 PushButton pushButton = PushButton::New();
229 pushButton.SetAutoRepeating( true );
231 pushButton.SetInitialAutoRepeatingDelay( 1.f );
232 DALI_TEST_EQUALS( pushButton.GetInitialAutoRepeatingDelay(), 1.f, TEST_LOCATION );
234 pushButton.SetNextAutoRepeatingDelay( 1.f );
235 DALI_TEST_EQUALS( pushButton.GetNextAutoRepeatingDelay(), 1.f, TEST_LOCATION );
239 int UtcDaliPushButtonSetGetAutorepeatingDelayValues02(void)
241 ToolkitTestApplication application;
242 tet_infoline(" UtcDaliPushButtonSetGetAutorepeatingDelayValues02");
244 PushButton pushButton = PushButton::New();
246 bool assert1( false );
247 bool assert2( false );
249 pushButton.SetAutoRepeating( true );
253 pushButton.SetInitialAutoRepeatingDelay( -1.f );
255 catch( Dali::DaliException& e )
257 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
258 DALI_TEST_EQUALS(e.mCondition, "initialAutoRepeatingDelay > 0.f", TEST_LOCATION);
264 pushButton.SetNextAutoRepeatingDelay( -1.f );
266 catch( Dali::DaliException& e )
268 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
269 DALI_TEST_EQUALS(e.mCondition, "nextAutoRepeatingDelay > 0.f", TEST_LOCATION);
273 DALI_TEST_CHECK( assert1 && assert2 );
277 int UtcDaliPushButtonSetImages(void)
279 ToolkitTestApplication application;
280 tet_infoline(" UtcDaliPushButtonSetImages");
284 Image image01 = CreateSolidColorImage( Color::RED, 10, 10 );
285 ImageActor imageActor01 = CreateSolidColorActor( Color::RED );
286 imageActor01.SetSize( 20.f, 20.f );
288 Image image02 = CreateSolidColorImage( Color::RED, 30, 30 );
289 ImageActor imageActor02 = CreateSolidColorActor( Color::RED );
290 imageActor02.SetSize( 40.f, 40.f );
292 Image image03 = CreateSolidColorImage( Color::RED, 50, 50 );
293 ImageActor imageActor03 = CreateSolidColorActor( Color::RED );
294 imageActor03.SetSize( 60.f, 60.f );
296 Image image04 = CreateSolidColorImage( Color::RED, 70, 70 );
297 ImageActor imageActor04 = CreateSolidColorActor( Color::RED );
298 imageActor04.SetSize( 80.f, 80.f );
300 Image image05 = CreateSolidColorImage( Color::RED, 90, 90 );
301 ImageActor imageActor05 = CreateSolidColorActor( Color::RED );
302 imageActor05.SetSize( 100.f, 100.f );
305 PushButton pushButton = PushButton::New();
307 application.SendNotification();
308 application.Render();
310 // Just check if check box button size changes when a bigger image is set.
312 pushButton.SetButtonImage( image01 );
314 application.SendNotification();
315 application.Render();
317 size = pushButton.GetButtonImage().GetCurrentSize();
319 DALI_TEST_EQUALS( size.width, 10.f, TEST_LOCATION );
320 DALI_TEST_EQUALS( size.height, 10.f, TEST_LOCATION );
322 pushButton.SetButtonImage( imageActor01 );
324 application.SendNotification();
325 application.Render();
327 size = pushButton.GetButtonImage().GetCurrentSize();
329 DALI_TEST_EQUALS( size.width, 20.f, TEST_LOCATION );
330 DALI_TEST_EQUALS( size.height, 20.f, TEST_LOCATION );
332 pushButton.SetBackgroundImage( image02 );
334 application.SendNotification();
335 application.Render();
337 size = pushButton.GetBackgroundImage().GetCurrentSize();
339 DALI_TEST_EQUALS( size.width, 30.f, TEST_LOCATION );
340 DALI_TEST_EQUALS( size.height, 30.f, TEST_LOCATION );
342 pushButton.SetBackgroundImage( imageActor02 );
344 application.SendNotification();
345 application.Render();
347 size = pushButton.GetBackgroundImage().GetCurrentSize();
349 DALI_TEST_EQUALS( size.width, 40.f, TEST_LOCATION );
350 DALI_TEST_EQUALS( size.height, 40.f, TEST_LOCATION );
352 pushButton.SetPressedImage( image03 );
354 application.SendNotification();
355 application.Render();
357 size = pushButton.GetPressedImage().GetCurrentSize();
359 DALI_TEST_EQUALS( size.width, 50.f, TEST_LOCATION );
360 DALI_TEST_EQUALS( size.height, 50.f, TEST_LOCATION );
362 pushButton.SetPressedImage( imageActor03 );
364 application.SendNotification();
365 application.Render();
367 size = pushButton.GetPressedImage().GetCurrentSize();
369 DALI_TEST_EQUALS( size.width, 60.f, TEST_LOCATION );
370 DALI_TEST_EQUALS( size.height, 60.f, TEST_LOCATION );
372 pushButton.SetDimmedBackgroundImage( image04 );
374 application.SendNotification();
375 application.Render();
377 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
379 DALI_TEST_EQUALS( size.width, 70.f, TEST_LOCATION );
380 DALI_TEST_EQUALS( size.height, 70.f, TEST_LOCATION );
382 pushButton.SetDimmedBackgroundImage( imageActor04 );
384 application.SendNotification();
385 application.Render();
387 size = pushButton.GetDimmedBackgroundImage().GetCurrentSize();
389 DALI_TEST_EQUALS( size.width, 80.f, TEST_LOCATION );
390 DALI_TEST_EQUALS( size.height, 80.f, TEST_LOCATION );
392 pushButton.SetDimmedImage( image05 );
394 application.SendNotification();
395 application.Render();
397 size = pushButton.GetDimmedImage().GetCurrentSize();
399 DALI_TEST_EQUALS( size.width, 90.f, TEST_LOCATION );
400 DALI_TEST_EQUALS( size.height, 90.f, TEST_LOCATION );
402 pushButton.SetDimmedImage( imageActor05 );
404 application.SendNotification();
405 application.Render();
407 size = pushButton.GetDimmedImage().GetCurrentSize();
409 DALI_TEST_EQUALS( size.width, 100.f, TEST_LOCATION );
410 DALI_TEST_EQUALS( size.height, 100.f, TEST_LOCATION );
414 int UtcDaliPushButtonSetLabelText(void)
416 ToolkitTestApplication application;
417 tet_infoline(" UtcDaliPushButtonSetLabelText");
419 const std::string STR( "Hola!" );
421 PushButton pushButton = PushButton::New();
423 application.SendNotification();
424 application.Render();
428 pushButton.SetLabelText( STR );
430 textView = TextView::DownCast( pushButton.GetLabelText() );
431 DALI_TEST_CHECK( STR == textView.GetText() );
433 TextView text = TextView::New( STR );
434 pushButton.SetLabelText( text );
436 textView = TextView::DownCast( pushButton.GetLabelText() );
437 DALI_TEST_CHECK( STR == textView.GetText() );
441 int UtcDaliPushButtonPressed(void)
443 ToolkitTestApplication application;
444 tet_infoline(" UtcDaliPushButtonPressed");
446 PushButton pushButton = PushButton::New();
447 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
448 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
449 pushButton.SetPosition( 240, 400 );
450 pushButton.SetSize( 100, 100 );
452 Stage::GetCurrent().Add( pushButton );
454 application.SendNotification();
455 application.Render();
457 gPushButtonPressed = false;
459 // connect to its touch signal
460 pushButton.PressedSignal().Connect( &PushButtonPressed );
462 Dali::Integration::TouchEvent eventDown;
463 eventDown.AddPoint( pointDownInside );
465 // flush the queue and render once
466 application.SendNotification();
467 application.Render();
468 application.ProcessEvent( eventDown );
470 DALI_TEST_CHECK( gPushButtonPressed );
474 int UtcDaliPushButtonReleased(void)
476 ToolkitTestApplication application;
477 tet_infoline(" UtcDaliPushButtonReleased");
479 PushButton pushButton = PushButton::New();
480 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
481 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
482 pushButton.SetPosition( 240, 400 );
483 pushButton.SetSize( 100, 100 );
485 Stage::GetCurrent().Add( pushButton );
487 application.SendNotification();
488 application.Render();
490 // connect to its touch signal
491 pushButton.ReleasedSignal().Connect( &PushButtonReleased );
493 Dali::Integration::TouchEvent event;
495 // Test1. Touch point down and up inside the button.
497 gPushButtonReleased = false;
498 event = Dali::Integration::TouchEvent();
499 event.AddPoint( pointDownInside );
500 application.ProcessEvent( event );
502 event = Dali::Integration::TouchEvent();
503 event.AddPoint( pointUpInside );
504 application.ProcessEvent( event );
506 DALI_TEST_CHECK( gPushButtonReleased );
508 // Test2. Touch point down and up outside the button.
510 gPushButtonReleased = false;
511 event = Dali::Integration::TouchEvent();
512 event.AddPoint( pointDownOutside );
513 application.ProcessEvent( event );
515 event = Dali::Integration::TouchEvent();
516 event.AddPoint( pointUpOutside );
517 application.ProcessEvent( event );
519 DALI_TEST_CHECK( !gPushButtonReleased );
521 // Test3. Touch point down inside and up outside the button.
523 gPushButtonReleased = false;
524 event = Dali::Integration::TouchEvent();
525 event.AddPoint( pointDownInside );
526 application.ProcessEvent( event );
528 event = Dali::Integration::TouchEvent();
529 event.AddPoint( pointLeave );
530 application.ProcessEvent( event );
532 event = Dali::Integration::TouchEvent();
533 event.AddPoint( pointUpOutside );
534 application.ProcessEvent( event );
536 DALI_TEST_CHECK( gPushButtonReleased );
538 // Test4. Touch point down outside and up inside the button.
540 gPushButtonReleased = false;
541 event = Dali::Integration::TouchEvent();
542 event.AddPoint( pointDownOutside );
543 application.ProcessEvent( event );
545 event = Dali::Integration::TouchEvent();
546 event.AddPoint( pointEnter );
547 application.ProcessEvent( event );
549 event = Dali::Integration::TouchEvent();
550 event.AddPoint( pointUpInside );
551 application.ProcessEvent( event );
553 DALI_TEST_CHECK( !gPushButtonReleased );
557 int UtcDaliPushButtonToggled(void)
559 ToolkitTestApplication application;
560 tet_infoline(" UtcDaliPushButtonToggled");
562 PushButton pushButton = PushButton::New();
563 pushButton.SetAnchorPoint( AnchorPoint::TOP_LEFT );
564 pushButton.SetParentOrigin( ParentOrigin::TOP_LEFT );
565 pushButton.SetPosition( 240, 400 );
566 pushButton.SetSize( 100, 100 );
568 Stage::GetCurrent().Add( pushButton );
570 application.SendNotification();
571 application.Render();
573 // connect to its touch signal
574 pushButton.ToggledSignal().Connect( &PushButtonToggled );
576 Dali::Integration::TouchEvent event;
578 // Test1. No toggle button.
580 gPushButtonToggleState = false;
581 event = Dali::Integration::TouchEvent();
582 event.AddPoint( pointDownInside );
583 application.ProcessEvent( event );
585 event = Dali::Integration::TouchEvent();
586 event.AddPoint( pointUpInside );
587 application.ProcessEvent( event );
589 DALI_TEST_CHECK( !gPushButtonToggleState );
591 // Set toggle property.
592 pushButton.SetToggleButton( true );
594 // Test2. Touch point down and up inside the button twice.
595 gPushButtonToggleState = false;
596 event = Dali::Integration::TouchEvent();
597 event.AddPoint( pointDownInside );
598 application.ProcessEvent( event );
600 event = Dali::Integration::TouchEvent();
601 event.AddPoint( pointUpInside );
602 application.ProcessEvent( event );
604 DALI_TEST_CHECK( gPushButtonToggleState );
606 event = Dali::Integration::TouchEvent();
607 event.AddPoint( pointDownInside );
608 application.ProcessEvent( event );
610 event = Dali::Integration::TouchEvent();
611 event.AddPoint( pointUpInside );
612 application.ProcessEvent( event );
614 DALI_TEST_CHECK( !gPushButtonToggleState );
616 // Test3. Touch point down and up outside the button.
618 gPushButtonToggleState = false;
619 event = Dali::Integration::TouchEvent();
620 event.AddPoint( pointDownOutside );
621 application.ProcessEvent( event );
623 event = Dali::Integration::TouchEvent();
624 event.AddPoint( pointUpOutside );
625 application.ProcessEvent( event );
627 DALI_TEST_CHECK( !gPushButtonToggleState );
629 // Test4. Touch point down inside and up outside the button.
631 gPushButtonToggleState = false;
632 event = Dali::Integration::TouchEvent();
633 event.AddPoint( pointDownInside );
634 application.ProcessEvent( event );
636 event = Dali::Integration::TouchEvent();
637 event.AddPoint( pointLeave );
638 application.ProcessEvent( event );
640 event = Dali::Integration::TouchEvent();
641 event.AddPoint( pointUpOutside );
642 application.ProcessEvent( event );
644 DALI_TEST_CHECK( !gPushButtonToggleState );
646 // Test5. Touch point down outside and up inside the button.
648 gPushButtonToggleState = false;
649 event = Dali::Integration::TouchEvent();
650 event.AddPoint( pointDownOutside );
651 application.ProcessEvent( event );
653 event = Dali::Integration::TouchEvent();
654 event.AddPoint( pointEnter );
655 application.ProcessEvent( event );
657 event = Dali::Integration::TouchEvent();
658 event.AddPoint( pointUpInside );
659 application.ProcessEvent( event );
661 DALI_TEST_CHECK( !gPushButtonToggleState );