2 * Copyright (c) 2019 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-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/public-api/align-enumerations.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
30 #include <dali-toolkit/devel-api/visuals/image-visual-actions-devel.h>
33 #include <toolkit-event-thread-callback.h>
35 #include "dummy-control.h"
38 using namespace Dali::Toolkit;
40 void utc_dali_toolkit_control_startup(void)
42 test_return_value = TET_UNDEF;
45 void utc_dali_toolkit_control_cleanup(void)
47 test_return_value = TET_PASS;
50 ///////////////////////////////////////////////////////////////////////////////////////////////////
55 bool gObjectCreatedCallBackCalled;
57 void TestCallback(BaseHandle handle)
59 gObjectCreatedCallBackCalled = true;
62 void TestVoidCallback()
66 static bool gKeyInputFocusCallBackCalled;
68 static void TestKeyInputFocusCallback( Control control )
70 tet_infoline(" TestKeyInputFocusCallback");
72 gKeyInputFocusCallBackCalled = true;
75 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
76 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
78 Vector4 GetControlBackgroundColor( Control& control )
80 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
81 Property::Map* resultMap = propValue.GetMap();
82 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
85 resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get( color );
92 ///////////////////////////////////////////////////////////////////////////////////////////////////
95 int UtcDaliControlConstructor(void)
97 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
101 DALI_TEST_CHECK( !Control::DownCast(dummy) );
103 dummy = DummyControl::New();
105 DALI_TEST_CHECK( Control::DownCast(dummy) );
109 int UtcDaliControlNew(void)
111 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
115 DALI_TEST_CHECK( !Control::DownCast(control) );
117 control = Control::New();
119 DALI_TEST_CHECK( Control::DownCast(control) );
124 int UtcDaliControlRegister(void)
126 ToolkitTestApplication application;
128 // Ensure the object is registered after creation
129 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
130 DALI_TEST_CHECK( registry );
132 gObjectCreatedCallBackCalled = false;
133 registry.ObjectCreatedSignal().Connect( &TestCallback );
135 Alignment alignment = Alignment::New();
137 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
141 int UtcDaliControlCopyAndAssignment(void)
143 ToolkitTestApplication application;
145 DummyControl control = DummyControl::New();
146 Control emptyControl;
148 Control controlCopy( control );
149 DALI_TEST_CHECK( control == controlCopy );
151 Control emptyControlCopy( emptyControl );
152 DALI_TEST_CHECK( emptyControl == emptyControlCopy );
154 Control controlEquals;
155 controlEquals = control;
156 DALI_TEST_CHECK( control == controlEquals );
158 Control emptyControlEquals;
159 emptyControlEquals = emptyControl;
160 DALI_TEST_CHECK( emptyControl == emptyControlEquals );
164 DALI_TEST_CHECK( control == controlCopy );
168 int UtcDaliControlDownCast(void)
170 ToolkitTestApplication application;
172 DummyControl control;
174 DALI_TEST_CHECK( !Control::DownCast( control ) );
176 control = DummyControl::New();
178 DALI_TEST_CHECK( Control::DownCast( control ) );
182 DALI_TEST_CHECK( !Control::DownCast( actor ) );
184 actor = Actor::New();
186 DALI_TEST_CHECK( !Control::DownCast( actor ) );
190 int UtcDaliControlDownCastTemplate(void)
192 ToolkitTestApplication application;
194 DummyControl control;
196 DALI_TEST_CHECK( !DummyControl::DownCast( control ));
198 control = DummyControl::New();
200 DALI_TEST_CHECK( DummyControl::DownCast( control ) );
204 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
206 actor = Actor::New();
208 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
212 int UtcDaliControlNavigationProperties(void)
214 ToolkitTestApplication application;
216 Control control = Control::New();
217 Stage::GetCurrent().Add( control );
219 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
220 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
221 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
222 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
224 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 );
225 DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
226 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 );
227 DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
228 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 );
229 DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
230 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 );
231 DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
233 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 );
234 DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
235 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 );
236 DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
237 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 );
238 DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
239 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 );
240 DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
245 int UtcDaliControlKeyInputFocus(void)
247 ToolkitTestApplication application;
248 Stage stage = Stage::GetCurrent();
250 DummyControl control;
252 PushButton pushButton1 = PushButton::New();
253 stage.Add( pushButton1 );
255 pushButton1.SetKeyInputFocus();
256 DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
258 pushButton1.ClearKeyInputFocus();
259 DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
263 int UtcDaliControlGetImplementationN(void)
265 ToolkitTestApplication application;
266 DummyControl control;
272 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
273 (void)controlImpl; // Avoid unused warning
274 tet_result(TET_FAIL);
276 catch (DaliException &exception)
278 tet_result(TET_PASS);
284 int UtcDaliControlGetImplementationConstN(void)
286 ToolkitTestApplication application;
287 DummyControl control;
293 const DummyControl constControl(control);
294 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
295 (void)controlImpl; // Avoid unused warning
296 tet_result(TET_FAIL);
298 catch (DaliException &exception)
300 tet_result(TET_PASS);
306 int UtcDaliControlGetImplementationP(void)
308 ToolkitTestApplication application;
309 DummyControl control = DummyControl::New();
315 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
316 (void)controlImpl; // Avoid unused warning
317 tet_result(TET_PASS);
319 catch (DaliException &exception)
321 tet_result(TET_FAIL);
327 int UtcDaliControlGetImplementationConstP(void)
329 ToolkitTestApplication application;
330 DummyControl control = DummyControl::New();
335 const DummyControl constControl(control);
336 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
337 (void)controlImpl; // Avoid unused warning
338 tet_result(TET_PASS);
340 catch (DaliException &exception)
342 tet_result(TET_FAIL);
348 int UtcDaliControlSignalConnectDisconnect(void)
350 ToolkitTestApplication application;
353 DummyControl dummy = DummyControlImpl::New();
355 Actor actor = Actor::New();
356 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
357 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
358 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
360 if( dummyImpl == NULL )
362 tet_result( TET_FAIL );
366 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
367 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
368 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
370 Stage::GetCurrent().Add( actor );
371 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
373 dummyImpl->mCustomSlot1Called = false;
374 actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
375 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
376 Stage::GetCurrent().Remove( actor );
377 Stage::GetCurrent().Add( actor );
378 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
383 int UtcDaliControlSignalAutomaticDisconnect(void)
385 ToolkitTestApplication application;
387 Actor actor = Actor::New();
390 DummyControl dummy = DummyControlImpl::New();
391 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
392 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
394 if( dummyImpl == NULL )
396 tet_result( TET_FAIL );
400 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
401 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
402 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
404 Stage::GetCurrent().Add( actor );
405 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
406 Stage::GetCurrent().Remove( actor );
408 // dummyControl automatically disconnects
410 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
412 const Vector3 ignoredSize( 20, 20, 0 );
413 actor.SetSize( ignoredSize );
417 int UtcDaliControlTestParameters(void)
419 ToolkitTestApplication application;
420 DummyControl test = DummyControl::New();
422 test.SetSize( 0.7f, 0.7f, 0.7f );
424 Stage::GetCurrent().Add( test );
426 application.SendNotification();
427 application.Render();
429 float width = 640.0f;
430 float height = test.GetHeightForWidth( width );
431 DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
432 DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
434 test.KeyEventSignal();
436 // Provide coverage for pointer destructor
437 Control* testControlPtr = new Control;
438 DALI_TEST_CHECK( testControlPtr );
439 delete testControlPtr;
443 int UtcDaliControlBackgroundColor(void)
445 ToolkitTestApplication application;
446 Control control = Control::New();
448 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
450 control.SetProperty( Control::Property::BACKGROUND, Color::RED );
452 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
453 Property::Map* resultMap = propValue.GetMap();
454 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
455 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
456 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
457 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
459 control.SetProperty( Control::Property::BACKGROUND, Color::YELLOW );
461 propValue = control.GetProperty( Control::Property::BACKGROUND );
462 resultMap = propValue.GetMap();
463 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
464 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
469 int UtcDaliControlBackgroundColorRendererCount(void)
471 tet_infoline( "Test ensures we only create renderers when non-transparent color is requested or if we our clipping-mode is set to CLIP_CHILDREN" );
473 ToolkitTestApplication application;
474 Control control = Control::New();
475 Stage::GetCurrent().Add( control );
477 tet_infoline( "Set transparent, no renderers should be created" );
478 control.SetBackgroundColor( Color::TRANSPARENT );
479 application.SendNotification();
480 application.Render();
481 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
483 tet_infoline( "Set transparent alpha with positive RGB values, no renderers should be created, but returned color should reflect what we set" );
484 const Vector4 alphaZero( 1.0f, 0.5f, 0.25f, 0.0f );
485 control.SetBackgroundColor( alphaZero );
486 application.SendNotification();
487 application.Render();
488 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
489 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), alphaZero, TEST_LOCATION );
491 tet_infoline( "Set semi transparent alpha with positive RGB values, 1 renderer should be created, but returned color should reflect what we set" );
492 const Vector4 semiTransparent( 1.0f, 0.75f, 0.5f, 0.5f );
493 control.SetBackgroundColor( semiTransparent );
494 application.SendNotification();
495 application.Render();
496 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
497 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), semiTransparent, TEST_LOCATION );
499 tet_infoline( "Set transparent, ensure no renderers are created" );
500 control.SetBackgroundColor( Color::TRANSPARENT );
501 application.SendNotification();
502 application.Render();
503 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
504 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
506 tet_infoline( "Set control to clip its children, a renderer should be created which will be transparent" );
507 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
508 application.SendNotification();
509 application.Render();
510 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
511 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
513 tet_infoline( "Set a color, only 1 renderer should exist" );
514 control.SetBackgroundColor( Color::RED );
515 application.SendNotification();
516 application.Render();
517 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
518 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::RED, TEST_LOCATION );
520 tet_infoline( "Clear the background, no renderers" );
521 control.ClearBackground();
522 application.SendNotification();
523 application.Render();
524 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
526 tet_infoline( "Set control to clip its children again, a renderer should be created which will be transparent" );
527 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
528 application.SendNotification();
529 application.Render();
530 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
531 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
533 tet_infoline( "Disable clipping, no renderers" );
534 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED );
535 application.SendNotification();
536 application.Render();
537 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
538 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
543 int UtcDaliControlBackgroundImage(void)
545 ToolkitTestApplication application;
546 Control control = Control::New();
548 tet_infoline( "Set first background image" );
549 control.SetProperty( Control::Property::BACKGROUND, "TestImage" );
551 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
552 Property::Map* resultMap = propValue.GetMap();
553 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
554 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
555 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
556 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
558 tet_infoline( "Set replacement background image" );
559 control.SetProperty( Control::Property::BACKGROUND, "TestImage2" );
561 propValue = control.GetProperty( Control::Property::BACKGROUND );
562 resultMap = propValue.GetMap();
563 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
564 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
569 int UtcDaliControlBackgroundProperties(void)
571 ToolkitTestApplication application;
572 Control control = Control::New();
574 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
576 Property::Map imageMap;
577 imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
578 imageMap[ ImageVisual::Property::URL ] = "TestImage";
579 control.SetProperty( Control::Property::BACKGROUND, imageMap );
580 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
581 Property::Map* resultMap = propValue.GetMap();
582 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
583 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
584 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
585 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
587 Property::Map rendererMap;
588 rendererMap[Visual::Property::TYPE] = Visual::COLOR;
589 rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
590 control.SetProperty( Control::Property::BACKGROUND, rendererMap );
591 propValue = control.GetProperty( Control::Property::BACKGROUND );
592 resultMap = propValue.GetMap();
593 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
594 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
595 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
596 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
598 Property::Map emptyMap;
599 control.SetProperty( Control::Property::BACKGROUND, emptyMap );
600 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
603 control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
604 propValue = control.GetProperty( Control::Property::BACKGROUND );
605 resultMap = propValue.GetMap();
606 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
607 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
610 control.SetProperty( Control::Property::BACKGROUND, Color::RED );
611 propValue = control.GetProperty( Control::Property::BACKGROUND );
612 resultMap = propValue.GetMap();
613 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
614 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
619 int UtcDaliControlKeyProperties(void)
621 ToolkitTestApplication application;
623 Control control = Control::New();
624 Stage::GetCurrent().Add( control );
626 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
628 control.SetKeyInputFocus();
629 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
631 control.ClearKeyInputFocus();
632 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
634 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
635 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
640 int UtcDaliControlGestureSignals(void)
642 ToolkitTestApplication application;
643 ConnectionTracker connectionTracker;
644 Control control = Control::New();
646 // Each gesture detector gets created when connecting to the gesture signals
647 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
648 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
649 DALI_TEST_CHECK( control.GetTapGestureDetector() );
651 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
652 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
653 DALI_TEST_CHECK( control.GetPanGestureDetector() );
655 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
656 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
657 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
659 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
660 control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback );
661 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
666 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
668 ToolkitTestApplication application;
670 Control control = Control::New();
671 Stage::GetCurrent().Add( control );
673 gKeyInputFocusCallBackCalled = false;
674 control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
676 application.SendNotification();
677 application.Render();
679 control.SetKeyInputFocus();
681 DALI_TEST_CHECK( control.HasKeyInputFocus() );
683 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
688 int UtcDaliControlImplKeyInputFocusLostSignal(void)
690 ToolkitTestApplication application;
692 Control control = Control::New();
693 Stage::GetCurrent().Add( control );
695 gKeyInputFocusCallBackCalled = false;
696 control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
698 application.SendNotification();
699 application.Render();
701 control.SetKeyInputFocus();
703 DALI_TEST_CHECK( control.HasKeyInputFocus() );
705 control.ClearKeyInputFocus();
707 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
712 int UtcDaliControlImplGetControlExtensionP(void)
714 ToolkitTestApplication application;
715 Control control = Control::New();
717 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
719 DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
724 int UtcDaliControlAutoClipping(void)
726 ToolkitTestApplication application;
727 Control control = Control::New();
729 tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
731 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
733 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
735 Stage::GetCurrent().Add( control );
737 application.SendNotification();
738 application.Render();
740 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
745 int UtcDaliControlAutoClippingN(void)
747 ToolkitTestApplication application;
748 Control control = Control::New();
749 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
750 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
752 tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
754 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
756 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
758 Stage::GetCurrent().Add( control );
760 application.SendNotification();
761 application.Render();
763 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
765 // Ensure the background color is still RED rather than what's set by the automatic clipping
766 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
767 Property::Map* map = value.GetMap();
768 DALI_TEST_CHECK( map );
769 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
770 DALI_TEST_CHECK( colorValue );
771 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
776 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
778 ToolkitTestApplication application;
779 Control control = Control::New();
781 tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
783 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
785 Stage::GetCurrent().Add( control );
787 application.SendNotification();
788 application.Render();
790 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
792 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
794 application.SendNotification();
795 application.Render();
797 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
802 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
804 ToolkitTestApplication application;
805 Control control = Control::New();
806 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
807 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
809 tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals and when already on stage" );
811 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
813 Stage::GetCurrent().Add( control );
815 application.SendNotification();
816 application.Render();
818 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
820 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
822 application.SendNotification();
823 application.Render();
825 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
827 // Ensure the background color is still RED rather than what's set by the automatic clipping
828 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
829 Property::Map* map = value.GetMap();
830 DALI_TEST_CHECK( map );
831 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
832 DALI_TEST_CHECK( colorValue );
833 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
838 int UtcDaliControlSetTransformSize(void)
840 ToolkitTestApplication application;
841 Control control = Control::New();
843 Property::Map transformMap;
844 transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
845 .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
846 .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
847 .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
849 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
850 .Add( Visual::Property::TRANSFORM, transformMap ) );
852 tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
854 Stage::GetCurrent().Add( control );
856 application.SendNotification();
857 application.Render();
859 // Ensure the transform property still matches what we set
860 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
861 Property::Map* map = value.GetMap();
862 DALI_TEST_CHECK( map );
863 Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
864 DALI_TEST_CHECK( transformValue );
866 Property::Map* retMap = transformValue->GetMap();
867 DALI_TEST_CHECK( retMap );
868 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
869 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
870 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
871 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
877 int UtcDaliControlResourcesReady(void)
879 ToolkitTestApplication application;
880 tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
882 VisualFactory factory = VisualFactory::Get();
883 DALI_TEST_CHECK( factory );
885 Property::Map propertyMapLarge;
886 propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
887 propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
889 Property::Map propertyMapSmall;
890 propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
891 propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
893 Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
894 smallVisual.SetName("smallVisual");
895 DALI_TEST_CHECK( smallVisual );
897 DummyControl actor = DummyControl::New();
898 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
900 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
902 actor.SetSize( 200.f, 200.f );
904 Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
905 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
906 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
907 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
909 Stage::GetCurrent().Add( actor );
910 application.SendNotification();
911 application.Render();
913 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
915 application.SendNotification();
916 application.Render();
918 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
919 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
920 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
921 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
923 Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
924 largeVisual.SetName("largeVisual");
925 DALI_TEST_CHECK( largeVisual );
927 tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
929 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
931 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
932 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
934 application.SendNotification();
936 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
937 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
938 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
939 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
941 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
943 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
945 application.SendNotification();
947 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
948 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
953 int UtcDaliControlMarginProperty(void)
955 ToolkitTestApplication application;
957 Control control = Control::New();
958 control.SetBackgroundColor( Color::BLUE );
960 control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
962 Stage::GetCurrent().Add( control );
964 application.SendNotification();
965 application.Render();
967 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
969 // Parent control has one ImageView as a Child.
970 ImageView image = ImageView::New();
971 image.SetBackgroundColor( Color::RED );
972 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
973 image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
974 control.Add( image );
976 application.SendNotification();
977 application.Render();
979 DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
984 int UtcDaliControlPaddingProperty(void)
986 ToolkitTestApplication application;
988 Control control = Control::New();
989 control.SetBackgroundColor( Color::BLUE );
991 control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
993 Stage::GetCurrent().Add( control );
995 application.SendNotification();
996 application.Render();
998 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1000 Control child = Control::New();
1003 application.SendNotification();
1004 application.Render();
1006 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1008 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
1009 application.SendNotification();
1010 application.Render();
1011 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
1013 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT);
1014 application.SendNotification();
1015 application.Render();
1017 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1022 int UtcDaliControlDoAction(void)
1024 ToolkitTestApplication application;
1025 tet_infoline( "DoAction on a visual registered with a control" );
1027 // Set up trace debug
1028 TestGlAbstraction& gl = application.GetGlAbstraction();
1029 TraceCallStack& textureTrace = gl.GetTextureTrace();
1030 textureTrace.Enable( true );
1032 //Created AnimatedImageVisual
1033 VisualFactory factory = VisualFactory::Get();
1034 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1036 DummyControl dummyControl = DummyControl::New(true);
1037 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1039 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1040 dummyControl.SetSize(200.f, 200.f);
1041 Stage::GetCurrent().Add( dummyControl );
1043 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1045 application.SendNotification();
1046 application.Render();
1047 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1048 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1049 textureTrace.Reset();
1051 Property::Map attributes;
1052 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1054 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1055 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1057 application.SendNotification();
1058 application.Render();
1059 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1060 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1064 int UtcDaliControlDoActionWhenNotStage(void)
1066 ToolkitTestApplication application;
1067 tet_infoline( "DoAction on a visual registered with a control but not staged" );
1069 // Set up trace debug
1070 TestGlAbstraction& gl = application.GetGlAbstraction();
1071 TraceCallStack& textureTrace = gl.GetTextureTrace();
1072 textureTrace.Enable( true );
1074 //Created AnimatedImageVisual
1075 VisualFactory factory = VisualFactory::Get();
1076 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1078 DummyControl dummyControl = DummyControl::New(true);
1079 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1081 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1082 dummyControl.SetSize(200.f, 200.f);
1084 application.SendNotification();
1085 application.Render();
1086 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1087 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1088 textureTrace.Reset();
1090 Property::Map attributes;
1091 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1093 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1094 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1096 application.SendNotification();
1097 application.Render();
1098 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1099 textureTrace.Reset();
1101 tet_infoline( "Adding control to stage will in turn add the visual to the stage" );
1103 Stage::GetCurrent().Add( dummyControl );
1104 application.SendNotification();
1105 application.Render();
1106 tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" );
1108 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1109 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1110 textureTrace.Reset();