2 * Copyright (c) 2017 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_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
450 control.SetBackgroundColor( 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 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
461 control.SetBackgroundColor( Color::YELLOW );
463 propValue = control.GetProperty( Control::Property::BACKGROUND );
464 resultMap = propValue.GetMap();
465 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
466 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
468 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
473 int UtcDaliControlBackgroundColorRendererCount(void)
475 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" );
477 ToolkitTestApplication application;
478 Control control = Control::New();
479 Stage::GetCurrent().Add( control );
481 tet_infoline( "Set transparent, no renderers should be created" );
482 control.SetBackgroundColor( Color::TRANSPARENT );
483 application.SendNotification();
484 application.Render();
485 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
487 tet_infoline( "Set transparent alpha with positive RGB values, no renderers should be created, but returned color should reflect what we set" );
488 const Vector4 alphaZero( 1.0f, 0.5f, 0.25f, 0.0f );
489 control.SetBackgroundColor( alphaZero );
490 application.SendNotification();
491 application.Render();
492 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
493 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), alphaZero, TEST_LOCATION );
495 tet_infoline( "Set semi transparent alpha with positive RGB values, 1 renderer should be created, but returned color should reflect what we set" );
496 const Vector4 semiTransparent( 1.0f, 0.75f, 0.5f, 0.5f );
497 control.SetBackgroundColor( semiTransparent );
498 application.SendNotification();
499 application.Render();
500 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
501 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), semiTransparent, TEST_LOCATION );
503 tet_infoline( "Set transparent, ensure no renderers are created" );
504 control.SetBackgroundColor( Color::TRANSPARENT );
505 application.SendNotification();
506 application.Render();
507 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
508 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
510 tet_infoline( "Set control to clip its children, a renderer should be created which will be transparent" );
511 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
512 application.SendNotification();
513 application.Render();
514 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
515 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
517 tet_infoline( "Set a color, only 1 renderer should exist" );
518 control.SetBackgroundColor( Color::RED );
519 application.SendNotification();
520 application.Render();
521 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
522 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::RED, TEST_LOCATION );
524 tet_infoline( "Clear the background, no renderers" );
525 control.ClearBackground();
526 application.SendNotification();
527 application.Render();
528 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
530 tet_infoline( "Set control to clip its children again, a renderer should be created which will be transparent" );
531 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
532 application.SendNotification();
533 application.Render();
534 DALI_TEST_EQUALS( control.GetRendererCount(), 1u, TEST_LOCATION );
535 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
537 tet_infoline( "Disable clipping, no renderers" );
538 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::DISABLED );
539 application.SendNotification();
540 application.Render();
541 DALI_TEST_EQUALS( control.GetRendererCount(), 0u, TEST_LOCATION );
542 DALI_TEST_EQUALS( GetControlBackgroundColor( control ), Color::TRANSPARENT, TEST_LOCATION );
547 int UtcDaliControlBackgroundImage(void)
549 ToolkitTestApplication application;
550 Control control = Control::New();
552 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
554 Image image = ResourceImage::New("TestImage");
555 control.SetBackgroundImage( image );
557 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
558 Property::Map* resultMap = propValue.GetMap();
559 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
560 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
561 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
562 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
564 image = ResourceImage::New("TestImage2");
565 control.SetBackgroundImage( image );
567 propValue = control.GetProperty( Control::Property::BACKGROUND );
568 resultMap = propValue.GetMap();
569 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
570 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
575 int UtcDaliControlBackgroundProperties(void)
577 ToolkitTestApplication application;
578 Control control = Control::New();
580 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
581 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
583 Property::Map imageMap;
584 imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
585 imageMap[ ImageVisual::Property::URL ] = "TestImage";
586 control.SetProperty( Control::Property::BACKGROUND, imageMap );
587 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
588 Property::Map* resultMap = propValue.GetMap();
589 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
590 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
591 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
592 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
594 Property::Map rendererMap;
595 rendererMap[Visual::Property::TYPE] = Visual::COLOR;
596 rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
597 control.SetProperty( Control::Property::BACKGROUND, rendererMap );
598 propValue = control.GetProperty( Control::Property::BACKGROUND );
599 resultMap = propValue.GetMap();
600 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
601 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
602 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
603 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
605 Property::Map emptyMap;
606 control.SetProperty( Control::Property::BACKGROUND, emptyMap );
607 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
610 control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
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::IMAGE, TEST_LOCATION );
614 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
617 control.SetProperty( Control::Property::BACKGROUND, Color::RED );
618 propValue = control.GetProperty( Control::Property::BACKGROUND );
619 resultMap = propValue.GetMap();
620 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
621 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
623 // Deprecated Properties
624 control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
625 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
626 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
628 control.ClearBackground();
630 Property::Map deprecatedImageMap;
631 deprecatedImageMap[ "filename" ] = "TestImage";
632 control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
633 propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
634 resultMap = propValue.GetMap();
635 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
637 control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
638 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
643 int UtcDaliControlKeyProperties(void)
645 ToolkitTestApplication application;
647 Control control = Control::New();
648 Stage::GetCurrent().Add( control );
650 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
652 control.SetKeyInputFocus();
653 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
655 control.ClearKeyInputFocus();
656 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
658 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
659 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
664 int UtcDaliControlGestureSignals(void)
666 ToolkitTestApplication application;
667 ConnectionTracker connectionTracker;
668 Control control = Control::New();
670 // Each gesture detector gets created when connecting to the gesture signals
671 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
672 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
673 DALI_TEST_CHECK( control.GetTapGestureDetector() );
675 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
676 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
677 DALI_TEST_CHECK( control.GetPanGestureDetector() );
679 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
680 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
681 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
683 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
684 control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback );
685 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
690 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
692 ToolkitTestApplication application;
694 Control control = Control::New();
695 Stage::GetCurrent().Add( control );
697 gKeyInputFocusCallBackCalled = false;
698 control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
700 application.SendNotification();
701 application.Render();
703 control.SetKeyInputFocus();
705 DALI_TEST_CHECK( control.HasKeyInputFocus() );
707 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
712 int UtcDaliControlImplKeyInputFocusLostSignal(void)
714 ToolkitTestApplication application;
716 Control control = Control::New();
717 Stage::GetCurrent().Add( control );
719 gKeyInputFocusCallBackCalled = false;
720 control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
722 application.SendNotification();
723 application.Render();
725 control.SetKeyInputFocus();
727 DALI_TEST_CHECK( control.HasKeyInputFocus() );
729 control.ClearKeyInputFocus();
731 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
736 int UtcDaliControlImplGetControlExtensionP(void)
738 ToolkitTestApplication application;
739 Control control = Control::New();
741 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
743 DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
748 int UtcDaliControlAutoClipping(void)
750 ToolkitTestApplication application;
751 Control control = Control::New();
753 tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
755 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
757 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
759 Stage::GetCurrent().Add( control );
761 application.SendNotification();
762 application.Render();
764 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
769 int UtcDaliControlAutoClippingN(void)
771 ToolkitTestApplication application;
772 Control control = Control::New();
773 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
774 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
776 tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
778 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
780 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
782 Stage::GetCurrent().Add( control );
784 application.SendNotification();
785 application.Render();
787 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
789 // Ensure the background color is still RED rather than what's set by the automatic clipping
790 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
791 Property::Map* map = value.GetMap();
792 DALI_TEST_CHECK( map );
793 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
794 DALI_TEST_CHECK( colorValue );
795 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
800 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
802 ToolkitTestApplication application;
803 Control control = Control::New();
805 tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
807 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
809 Stage::GetCurrent().Add( control );
811 application.SendNotification();
812 application.Render();
814 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
816 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
818 application.SendNotification();
819 application.Render();
821 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
826 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
828 ToolkitTestApplication application;
829 Control control = Control::New();
830 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
831 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
833 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" );
835 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
837 Stage::GetCurrent().Add( control );
839 application.SendNotification();
840 application.Render();
842 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
844 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
846 application.SendNotification();
847 application.Render();
849 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
851 // Ensure the background color is still RED rather than what's set by the automatic clipping
852 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
853 Property::Map* map = value.GetMap();
854 DALI_TEST_CHECK( map );
855 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
856 DALI_TEST_CHECK( colorValue );
857 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
862 int UtcDaliControlSetTransformSize(void)
864 ToolkitTestApplication application;
865 Control control = Control::New();
867 Property::Map transformMap;
868 transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
869 .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
870 .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
871 .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
873 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
874 .Add( Visual::Property::TRANSFORM, transformMap ) );
876 tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
878 Stage::GetCurrent().Add( control );
880 application.SendNotification();
881 application.Render();
883 // Ensure the transform property still matches what we set
884 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
885 Property::Map* map = value.GetMap();
886 DALI_TEST_CHECK( map );
887 Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
888 DALI_TEST_CHECK( transformValue );
890 Property::Map* retMap = transformValue->GetMap();
891 DALI_TEST_CHECK( retMap );
892 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
893 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
894 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
895 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
901 int UtcDaliControlResourcesReady(void)
903 ToolkitTestApplication application;
904 tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
906 VisualFactory factory = VisualFactory::Get();
907 DALI_TEST_CHECK( factory );
909 Property::Map propertyMapLarge;
910 propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
911 propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
913 Property::Map propertyMapSmall;
914 propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
915 propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
917 Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
918 smallVisual.SetName("smallVisual");
919 DALI_TEST_CHECK( smallVisual );
921 DummyControl actor = DummyControl::New();
922 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
924 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
926 actor.SetSize( 200.f, 200.f );
928 Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
929 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
930 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
931 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
933 Stage::GetCurrent().Add( actor );
934 application.SendNotification();
935 application.Render();
937 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
939 application.SendNotification();
940 application.Render();
942 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
943 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
944 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
945 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
947 Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
948 largeVisual.SetName("largeVisual");
949 DALI_TEST_CHECK( largeVisual );
951 tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
953 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
955 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
956 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
958 application.SendNotification();
960 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
961 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
962 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
963 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
965 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
967 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
969 application.SendNotification();
971 resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
972 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
977 int UtcDaliControlMarginProperty(void)
979 ToolkitTestApplication application;
981 Control control = Control::New();
982 control.SetBackgroundColor( Color::BLUE );
984 control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
986 Stage::GetCurrent().Add( control );
988 application.SendNotification();
989 application.Render();
991 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
993 // Parent control has one ImageView as a Child.
994 ImageView image = ImageView::New();
995 image.SetBackgroundColor( Color::RED );
996 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
997 image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
998 control.Add( image );
1000 application.SendNotification();
1001 application.Render();
1003 DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
1008 int UtcDaliControlPaddingProperty(void)
1010 ToolkitTestApplication application;
1012 Control control = Control::New();
1013 control.SetBackgroundColor( Color::BLUE );
1015 control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
1017 Stage::GetCurrent().Add( control );
1019 application.SendNotification();
1020 application.Render();
1022 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
1024 Control child = Control::New();
1027 application.SendNotification();
1028 application.Render();
1030 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1032 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
1033 application.SendNotification();
1034 application.Render();
1035 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
1037 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT);
1038 application.SendNotification();
1039 application.Render();
1041 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
1046 int UtcDaliControlDoAction(void)
1048 ToolkitTestApplication application;
1049 tet_infoline( "DoAction on a visual registered with a control" );
1051 // Set up trace debug
1052 TestGlAbstraction& gl = application.GetGlAbstraction();
1053 TraceCallStack& textureTrace = gl.GetTextureTrace();
1054 textureTrace.Enable( true );
1056 //Created AnimatedImageVisual
1057 VisualFactory factory = VisualFactory::Get();
1058 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1060 DummyControl dummyControl = DummyControl::New(true);
1061 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1063 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1064 dummyControl.SetSize(200.f, 200.f);
1065 Stage::GetCurrent().Add( dummyControl );
1067 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1069 application.SendNotification();
1070 application.Render();
1071 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1072 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1073 textureTrace.Reset();
1075 Property::Map attributes;
1076 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1078 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1079 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1081 application.SendNotification();
1082 application.Render();
1083 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
1084 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1088 int UtcDaliControlDoActionWhenNotStage(void)
1090 ToolkitTestApplication application;
1091 tet_infoline( "DoAction on a visual registered with a control but not staged" );
1093 // Set up trace debug
1094 TestGlAbstraction& gl = application.GetGlAbstraction();
1095 TraceCallStack& textureTrace = gl.GetTextureTrace();
1096 textureTrace.Enable( true );
1098 //Created AnimatedImageVisual
1099 VisualFactory factory = VisualFactory::Get();
1100 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1102 DummyControl dummyControl = DummyControl::New(true);
1103 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1105 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1106 dummyControl.SetSize(200.f, 200.f);
1108 application.SendNotification();
1109 application.Render();
1110 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1111 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1112 textureTrace.Reset();
1114 Property::Map attributes;
1115 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1117 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1118 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1120 application.SendNotification();
1121 application.Render();
1122 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1123 textureTrace.Reset();
1125 tet_infoline( "Adding control to stage will in turn add the visual to the stage" );
1127 Stage::GetCurrent().Add( dummyControl );
1128 application.SendNotification();
1129 application.Render();
1130 tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" );
1132 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1133 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1134 textureTrace.Reset();