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 UtcDaliControlShadowProperties(void)
621 ToolkitTestApplication application;
622 Control control = Control::New();
624 DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() );
626 Property::Map imageMap;
627 imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
628 imageMap[ ImageVisual::Property::URL ] = "TestImage";
629 control.SetProperty( DevelControl::Property::SHADOW, imageMap );
630 Property::Value propValue = control.GetProperty( DevelControl::Property::SHADOW );
631 Property::Map* resultMap = propValue.GetMap();
632 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
633 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
634 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
635 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
637 Property::Map colorMap;
638 colorMap[Visual::Property::TYPE] = Visual::COLOR;
639 colorMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
640 control.SetProperty( DevelControl::Property::SHADOW, colorMap );
641 propValue = control.GetProperty( DevelControl::Property::SHADOW );
642 resultMap = propValue.GetMap();
643 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
644 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
645 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
646 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
648 Property::Map emptyMap;
649 control.SetProperty( DevelControl::Property::SHADOW, emptyMap );
650 DALI_TEST_CHECK( control.GetProperty( DevelControl::Property::SHADOW ).Get< Property::Map >().Empty() );
655 int UtcDaliControlKeyProperties(void)
657 ToolkitTestApplication application;
659 Control control = Control::New();
660 Stage::GetCurrent().Add( control );
662 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
664 control.SetKeyInputFocus();
665 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
667 control.ClearKeyInputFocus();
668 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
670 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
671 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
676 int UtcDaliControlGestureSignals(void)
678 ToolkitTestApplication application;
679 ConnectionTracker connectionTracker;
680 Control control = Control::New();
682 // Each gesture detector gets created when connecting to the gesture signals
683 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
684 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
685 DALI_TEST_CHECK( control.GetTapGestureDetector() );
687 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
688 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
689 DALI_TEST_CHECK( control.GetPanGestureDetector() );
691 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
692 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
693 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
695 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
696 control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback );
697 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
702 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
704 ToolkitTestApplication application;
706 Control control = Control::New();
707 Stage::GetCurrent().Add( control );
709 gKeyInputFocusCallBackCalled = false;
710 control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
712 application.SendNotification();
713 application.Render();
715 control.SetKeyInputFocus();
717 DALI_TEST_CHECK( control.HasKeyInputFocus() );
719 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
724 int UtcDaliControlImplKeyInputFocusLostSignal(void)
726 ToolkitTestApplication application;
728 Control control = Control::New();
729 Stage::GetCurrent().Add( control );
731 gKeyInputFocusCallBackCalled = false;
732 control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
734 application.SendNotification();
735 application.Render();
737 control.SetKeyInputFocus();
739 DALI_TEST_CHECK( control.HasKeyInputFocus() );
741 control.ClearKeyInputFocus();
743 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
748 int UtcDaliControlImplGetControlExtensionP(void)
750 ToolkitTestApplication application;
751 Control control = Control::New();
753 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
755 DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
760 int UtcDaliControlAutoClipping(void)
762 ToolkitTestApplication application;
763 Control control = Control::New();
765 tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
767 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
769 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
771 Stage::GetCurrent().Add( control );
773 application.SendNotification();
774 application.Render();
776 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
781 int UtcDaliControlAutoClippingN(void)
783 ToolkitTestApplication application;
784 Control control = Control::New();
785 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
786 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
788 tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
790 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
792 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
794 Stage::GetCurrent().Add( control );
796 application.SendNotification();
797 application.Render();
799 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
801 // Ensure the background color is still RED rather than what's set by the automatic clipping
802 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
803 Property::Map* map = value.GetMap();
804 DALI_TEST_CHECK( map );
805 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
806 DALI_TEST_CHECK( colorValue );
807 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
812 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
814 ToolkitTestApplication application;
815 Control control = Control::New();
817 tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
819 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
821 Stage::GetCurrent().Add( control );
823 application.SendNotification();
824 application.Render();
826 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
828 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
830 application.SendNotification();
831 application.Render();
833 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
838 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
840 ToolkitTestApplication application;
841 Control control = Control::New();
842 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
843 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
845 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" );
847 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
849 Stage::GetCurrent().Add( control );
851 application.SendNotification();
852 application.Render();
854 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
856 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
858 application.SendNotification();
859 application.Render();
861 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
863 // Ensure the background color is still RED rather than what's set by the automatic clipping
864 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
865 Property::Map* map = value.GetMap();
866 DALI_TEST_CHECK( map );
867 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
868 DALI_TEST_CHECK( colorValue );
869 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
874 int UtcDaliControlSetTransformSize(void)
876 ToolkitTestApplication application;
877 Control control = Control::New();
879 Property::Map transformMap;
880 transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
881 .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
882 .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
883 .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
885 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
886 .Add( Visual::Property::TRANSFORM, transformMap ) );
888 tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
890 Stage::GetCurrent().Add( control );
892 application.SendNotification();
893 application.Render();
895 // Ensure the transform property still matches what we set
896 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
897 Property::Map* map = value.GetMap();
898 DALI_TEST_CHECK( map );
899 Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
900 DALI_TEST_CHECK( transformValue );
902 Property::Map* retMap = transformValue->GetMap();
903 DALI_TEST_CHECK( retMap );
904 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
905 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
906 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
907 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
913 int UtcDaliControlResourcesReady(void)
915 ToolkitTestApplication application;
916 tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
918 VisualFactory factory = VisualFactory::Get();
919 DALI_TEST_CHECK( factory );
921 Property::Map propertyMapLarge;
922 propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
923 propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
925 Property::Map propertyMapSmall;
926 propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
927 propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
929 Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
930 smallVisual.SetName("smallVisual");
931 DALI_TEST_CHECK( smallVisual );
933 DummyControl actor = DummyControl::New();
934 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
936 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
938 actor.SetSize( 200.f, 200.f );
940 Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
941 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
942 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
943 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
945 Stage::GetCurrent().Add( actor );
946 application.SendNotification();
947 application.Render();
949 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
951 application.SendNotification();
952 application.Render();
954 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
955 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
956 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
957 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
959 Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
960 largeVisual.SetName("largeVisual");
961 DALI_TEST_CHECK( largeVisual );
963 tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
965 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
967 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
968 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
970 application.SendNotification();
972 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
973 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
974 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
975 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
977 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
979 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
981 application.SendNotification();
983 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
984 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
989 int UtcDaliControlMarginProperty(void)
991 ToolkitTestApplication application;
993 Control control = Control::New();
994 control.SetBackgroundColor( Color::BLUE );
996 control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
998 Stage::GetCurrent().Add( control );
1000 application.SendNotification();
1001 application.Render();
1003 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
1005 // Parent control has one ImageView as a Child.
1006 ImageView image = ImageView::New();
1007 image.SetBackgroundColor( Color::RED );
1008 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
1009 image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
1010 control.Add( image );
1012 application.SendNotification();
1013 application.Render();
1015 DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
1020 int UtcDaliControlPaddingProperty(void)
1022 ToolkitTestApplication application;
1024 Control control = Control::New();
1025 control.SetBackgroundColor( Color::BLUE );
1027 control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1029 Stage::GetCurrent().Add( control );
1031 application.SendNotification();
1032 application.Render();
1034 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1036 Control child = Control::New();
1039 application.SendNotification();
1040 application.Render();
1042 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1044 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
1045 application.SendNotification();
1046 application.Render();
1047 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
1049 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT);
1050 application.SendNotification();
1051 application.Render();
1053 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1058 int UtcDaliControlDoAction(void)
1060 ToolkitTestApplication application;
1061 tet_infoline( "DoAction on a visual registered with a control" );
1063 // Set up trace debug
1064 TestGlAbstraction& gl = application.GetGlAbstraction();
1065 TraceCallStack& textureTrace = gl.GetTextureTrace();
1066 textureTrace.Enable( true );
1068 //Created AnimatedImageVisual
1069 VisualFactory factory = VisualFactory::Get();
1070 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1072 DummyControl dummyControl = DummyControl::New(true);
1073 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1075 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1076 dummyControl.SetSize(200.f, 200.f);
1077 Stage::GetCurrent().Add( dummyControl );
1079 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1081 application.SendNotification();
1082 application.Render();
1083 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1084 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1085 textureTrace.Reset();
1087 Property::Map attributes;
1088 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1090 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1091 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1093 application.SendNotification();
1094 application.Render();
1095 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1096 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1100 int UtcDaliControlDoActionWhenNotStage(void)
1102 ToolkitTestApplication application;
1103 tet_infoline( "DoAction on a visual registered with a control but not staged" );
1105 // Set up trace debug
1106 TestGlAbstraction& gl = application.GetGlAbstraction();
1107 TraceCallStack& textureTrace = gl.GetTextureTrace();
1108 textureTrace.Enable( true );
1110 //Created AnimatedImageVisual
1111 VisualFactory factory = VisualFactory::Get();
1112 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1114 DummyControl dummyControl = DummyControl::New(true);
1115 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1117 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1118 dummyControl.SetSize(200.f, 200.f);
1120 application.SendNotification();
1121 application.Render();
1122 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1123 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1124 textureTrace.Reset();
1126 Property::Map attributes;
1127 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1129 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1130 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1132 application.SendNotification();
1133 application.Render();
1134 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1135 textureTrace.Reset();
1137 tet_infoline( "Adding control to stage will in turn add the visual to the stage" );
1139 Stage::GetCurrent().Add( dummyControl );
1140 application.SendNotification();
1141 application.Render();
1142 tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" );
1144 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1145 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1146 textureTrace.Reset();