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 <toolkit-event-thread-callback.h>
32 #include "dummy-control.h"
35 using namespace Dali::Toolkit;
37 void utc_dali_toolkit_control_startup(void)
39 test_return_value = TET_UNDEF;
42 void utc_dali_toolkit_control_cleanup(void)
44 test_return_value = TET_PASS;
47 ///////////////////////////////////////////////////////////////////////////////////////////////////
52 bool gObjectCreatedCallBackCalled;
54 void TestCallback(BaseHandle handle)
56 gObjectCreatedCallBackCalled = true;
59 void TestVoidCallback()
63 static bool gKeyInputFocusCallBackCalled;
65 static void TestKeyInputFocusCallback( Control control )
67 tet_infoline(" TestKeyInputFocusCallback");
69 gKeyInputFocusCallBackCalled = true;
72 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
73 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
77 ///////////////////////////////////////////////////////////////////////////////////////////////////
80 int UtcDaliControlConstructor(void)
82 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
86 DALI_TEST_CHECK( !Control::DownCast(dummy) );
88 dummy = DummyControl::New();
90 DALI_TEST_CHECK( Control::DownCast(dummy) );
94 int UtcDaliControlNew(void)
96 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
100 DALI_TEST_CHECK( !Control::DownCast(control) );
102 control = Control::New();
104 DALI_TEST_CHECK( Control::DownCast(control) );
109 int UtcDaliControlRegister(void)
111 ToolkitTestApplication application;
113 // Ensure the object is registered after creation
114 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
115 DALI_TEST_CHECK( registry );
117 gObjectCreatedCallBackCalled = false;
118 registry.ObjectCreatedSignal().Connect( &TestCallback );
120 Alignment alignment = Alignment::New();
122 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
126 int UtcDaliControlCopyAndAssignment(void)
128 ToolkitTestApplication application;
130 DummyControl control = DummyControl::New();
131 Control emptyControl;
133 Control controlCopy( control );
134 DALI_TEST_CHECK( control == controlCopy );
136 Control emptyControlCopy( emptyControl );
137 DALI_TEST_CHECK( emptyControl == emptyControlCopy );
139 Control controlEquals;
140 controlEquals = control;
141 DALI_TEST_CHECK( control == controlEquals );
143 Control emptyControlEquals;
144 emptyControlEquals = emptyControl;
145 DALI_TEST_CHECK( emptyControl == emptyControlEquals );
149 DALI_TEST_CHECK( control == controlCopy );
153 int UtcDaliControlDownCast(void)
155 ToolkitTestApplication application;
157 DummyControl control;
159 DALI_TEST_CHECK( !Control::DownCast( control ) );
161 control = DummyControl::New();
163 DALI_TEST_CHECK( Control::DownCast( control ) );
167 DALI_TEST_CHECK( !Control::DownCast( actor ) );
169 actor = Actor::New();
171 DALI_TEST_CHECK( !Control::DownCast( actor ) );
175 int UtcDaliControlDownCastTemplate(void)
177 ToolkitTestApplication application;
179 DummyControl control;
181 DALI_TEST_CHECK( !DummyControl::DownCast( control ));
183 control = DummyControl::New();
185 DALI_TEST_CHECK( DummyControl::DownCast( control ) );
189 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
191 actor = Actor::New();
193 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
197 int UtcDaliControlNavigationProperties(void)
199 ToolkitTestApplication application;
201 Control control = Control::New();
202 Stage::GetCurrent().Add( control );
204 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
205 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
206 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
207 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
209 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 );
210 DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
211 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 );
212 DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
213 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 );
214 DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
215 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 );
216 DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
218 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 );
219 DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
220 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 );
221 DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
222 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 );
223 DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
224 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 );
225 DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
230 int UtcDaliControlKeyInputFocus(void)
232 ToolkitTestApplication application;
233 Stage stage = Stage::GetCurrent();
235 DummyControl control;
237 PushButton pushButton1 = PushButton::New();
238 stage.Add( pushButton1 );
240 pushButton1.SetKeyInputFocus();
241 DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
243 pushButton1.ClearKeyInputFocus();
244 DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
248 int UtcDaliControlGetImplementationN(void)
250 ToolkitTestApplication application;
251 DummyControl control;
257 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
258 (void)controlImpl; // Avoid unused warning
259 tet_result(TET_FAIL);
261 catch (DaliException &exception)
263 tet_result(TET_PASS);
269 int UtcDaliControlGetImplementationConstN(void)
271 ToolkitTestApplication application;
272 DummyControl control;
278 const DummyControl constControl(control);
279 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
280 (void)controlImpl; // Avoid unused warning
281 tet_result(TET_FAIL);
283 catch (DaliException &exception)
285 tet_result(TET_PASS);
291 int UtcDaliControlGetImplementationP(void)
293 ToolkitTestApplication application;
294 DummyControl control = DummyControl::New();
300 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
301 (void)controlImpl; // Avoid unused warning
302 tet_result(TET_PASS);
304 catch (DaliException &exception)
306 tet_result(TET_FAIL);
312 int UtcDaliControlGetImplementationConstP(void)
314 ToolkitTestApplication application;
315 DummyControl control = DummyControl::New();
320 const DummyControl constControl(control);
321 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
322 (void)controlImpl; // Avoid unused warning
323 tet_result(TET_PASS);
325 catch (DaliException &exception)
327 tet_result(TET_FAIL);
333 int UtcDaliControlSignalConnectDisconnect(void)
335 ToolkitTestApplication application;
338 DummyControl dummy = DummyControlImpl::New();
340 Actor actor = Actor::New();
341 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
342 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
343 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
345 if( dummyImpl == NULL )
347 tet_result( TET_FAIL );
351 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
352 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
353 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
355 Stage::GetCurrent().Add( actor );
356 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
358 dummyImpl->mCustomSlot1Called = false;
359 actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
360 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
361 Stage::GetCurrent().Remove( actor );
362 Stage::GetCurrent().Add( actor );
363 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
368 int UtcDaliControlSignalAutomaticDisconnect(void)
370 ToolkitTestApplication application;
372 Actor actor = Actor::New();
375 DummyControl dummy = DummyControlImpl::New();
376 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
377 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
379 if( dummyImpl == NULL )
381 tet_result( TET_FAIL );
385 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
386 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
387 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
389 Stage::GetCurrent().Add( actor );
390 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
391 Stage::GetCurrent().Remove( actor );
393 // dummyControl automatically disconnects
395 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
397 const Vector3 ignoredSize( 20, 20, 0 );
398 actor.SetSize( ignoredSize );
402 int UtcDaliControlTestParameters(void)
404 ToolkitTestApplication application;
405 DummyControl test = DummyControl::New();
407 test.SetSize( 0.7f, 0.7f, 0.7f );
409 Stage::GetCurrent().Add( test );
411 application.SendNotification();
412 application.Render();
414 float width = 640.0f;
415 float height = test.GetHeightForWidth( width );
416 DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
417 DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
419 test.KeyEventSignal();
421 // Provide coverage for pointer destructor
422 Control* testControlPtr = new Control;
423 DALI_TEST_CHECK( testControlPtr );
424 delete testControlPtr;
428 int UtcDaliControlBackgroundColor(void)
430 ToolkitTestApplication application;
431 Control control = Control::New();
433 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
435 control.SetBackgroundColor( Color::RED );
437 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
438 Property::Map* resultMap = propValue.GetMap();
439 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
440 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
441 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
442 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
444 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
446 control.SetBackgroundColor( Color::YELLOW );
448 propValue = control.GetProperty( Control::Property::BACKGROUND );
449 resultMap = propValue.GetMap();
450 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
451 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
453 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
458 int UtcDaliControlBackgroundImage(void)
460 ToolkitTestApplication application;
461 Control control = Control::New();
463 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
465 Image image = ResourceImage::New("TestImage");
466 control.SetBackgroundImage( image );
468 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
469 Property::Map* resultMap = propValue.GetMap();
470 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
471 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
472 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
473 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
475 image = ResourceImage::New("TestImage2");
476 control.SetBackgroundImage( image );
478 propValue = control.GetProperty( Control::Property::BACKGROUND );
479 resultMap = propValue.GetMap();
480 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
481 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
486 int UtcDaliControlBackgroundProperties(void)
488 ToolkitTestApplication application;
489 Control control = Control::New();
491 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
492 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
494 Property::Map imageMap;
495 imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
496 imageMap[ ImageVisual::Property::URL ] = "TestImage";
497 control.SetProperty( Control::Property::BACKGROUND, imageMap );
498 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
499 Property::Map* resultMap = propValue.GetMap();
500 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
501 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
502 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
503 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
505 Property::Map rendererMap;
506 rendererMap[Visual::Property::TYPE] = Visual::COLOR;
507 rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
508 control.SetProperty( Control::Property::BACKGROUND, rendererMap );
509 propValue = control.GetProperty( Control::Property::BACKGROUND );
510 resultMap = propValue.GetMap();
511 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
512 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
513 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
514 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
516 Property::Map emptyMap;
517 control.SetProperty( Control::Property::BACKGROUND, emptyMap );
518 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
521 control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
522 propValue = control.GetProperty( Control::Property::BACKGROUND );
523 resultMap = propValue.GetMap();
524 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
525 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
528 control.SetProperty( Control::Property::BACKGROUND, Color::RED );
529 propValue = control.GetProperty( Control::Property::BACKGROUND );
530 resultMap = propValue.GetMap();
531 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
532 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
534 // Deprecated Properties
535 control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
536 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
537 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
539 control.ClearBackground();
541 Property::Map deprecatedImageMap;
542 deprecatedImageMap[ "filename" ] = "TestImage";
543 control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
544 propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
545 resultMap = propValue.GetMap();
546 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
548 control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
549 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
554 int UtcDaliControlKeyProperties(void)
556 ToolkitTestApplication application;
558 Control control = Control::New();
559 Stage::GetCurrent().Add( control );
561 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
563 control.SetKeyInputFocus();
564 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
566 control.ClearKeyInputFocus();
567 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
569 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
570 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
575 int UtcDaliControlGestureSignals(void)
577 ToolkitTestApplication application;
578 ConnectionTracker connectionTracker;
579 Control control = Control::New();
581 // Each gesture detector gets created when connecting to the gesture signals
582 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
583 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
584 DALI_TEST_CHECK( control.GetTapGestureDetector() );
586 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
587 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
588 DALI_TEST_CHECK( control.GetPanGestureDetector() );
590 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
591 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
592 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
594 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
595 control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback );
596 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
601 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
603 ToolkitTestApplication application;
605 Control control = Control::New();
606 Stage::GetCurrent().Add( control );
608 gKeyInputFocusCallBackCalled = false;
609 control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
611 application.SendNotification();
612 application.Render();
614 control.SetKeyInputFocus();
616 DALI_TEST_CHECK( control.HasKeyInputFocus() );
618 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
623 int UtcDaliControlImplKeyInputFocusLostSignal(void)
625 ToolkitTestApplication application;
627 Control control = Control::New();
628 Stage::GetCurrent().Add( control );
630 gKeyInputFocusCallBackCalled = false;
631 control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
633 application.SendNotification();
634 application.Render();
636 control.SetKeyInputFocus();
638 DALI_TEST_CHECK( control.HasKeyInputFocus() );
640 control.ClearKeyInputFocus();
642 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
647 int UtcDaliControlImplGetControlExtensionP(void)
649 ToolkitTestApplication application;
650 Control control = Control::New();
652 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
654 DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
659 int UtcDaliControlAutoClipping(void)
661 ToolkitTestApplication application;
662 Control control = Control::New();
664 tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
666 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
668 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
670 Stage::GetCurrent().Add( control );
672 application.SendNotification();
673 application.Render();
675 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
680 int UtcDaliControlAutoClippingN(void)
682 ToolkitTestApplication application;
683 Control control = Control::New();
684 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
685 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
687 tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
689 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
691 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
693 Stage::GetCurrent().Add( control );
695 application.SendNotification();
696 application.Render();
698 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
700 // Ensure the background color is still RED rather than what's set by the automatic clipping
701 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
702 Property::Map* map = value.GetMap();
703 DALI_TEST_CHECK( map );
704 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
705 DALI_TEST_CHECK( colorValue );
706 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
711 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
713 ToolkitTestApplication application;
714 Control control = Control::New();
716 tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
718 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
720 Stage::GetCurrent().Add( control );
722 application.SendNotification();
723 application.Render();
725 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
727 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
729 application.SendNotification();
730 application.Render();
732 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
737 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
739 ToolkitTestApplication application;
740 Control control = Control::New();
741 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
742 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
744 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" );
746 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
748 Stage::GetCurrent().Add( control );
750 application.SendNotification();
751 application.Render();
753 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
755 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
757 application.SendNotification();
758 application.Render();
760 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
762 // Ensure the background color is still RED rather than what's set by the automatic clipping
763 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
764 Property::Map* map = value.GetMap();
765 DALI_TEST_CHECK( map );
766 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
767 DALI_TEST_CHECK( colorValue );
768 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
773 int UtcDaliControlSetTransformSize(void)
775 ToolkitTestApplication application;
776 Control control = Control::New();
778 Property::Map transformMap;
779 transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
780 .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
781 .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
782 .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
784 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
785 .Add( Visual::Property::TRANSFORM, transformMap ) );
787 tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
789 Stage::GetCurrent().Add( control );
791 application.SendNotification();
792 application.Render();
794 // Ensure the transform property still matches what we set
795 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
796 Property::Map* map = value.GetMap();
797 DALI_TEST_CHECK( map );
798 Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
799 DALI_TEST_CHECK( transformValue );
801 Property::Map* retMap = transformValue->GetMap();
802 DALI_TEST_CHECK( retMap );
803 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
804 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
805 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
806 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
812 int UtcDaliControlResourcesReady(void)
814 ToolkitTestApplication application;
815 tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
817 VisualFactory factory = VisualFactory::Get();
818 DALI_TEST_CHECK( factory );
820 Property::Map propertyMapLarge;
821 propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
822 propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
824 Property::Map propertyMapSmall;
825 propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
826 propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
828 Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
829 smallVisual.SetName("smallVisual");
830 DALI_TEST_CHECK( smallVisual );
832 DummyControl actor = DummyControl::New();
833 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
834 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
836 actor.SetSize( 200.f, 200.f );
837 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
838 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
840 Stage::GetCurrent().Add( actor );
841 application.SendNotification();
842 application.Render();
844 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
846 application.SendNotification();
847 application.Render();
849 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
850 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
852 Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
853 largeVisual.SetName("largeVisual");
854 DALI_TEST_CHECK( largeVisual );
856 tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
858 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
860 application.SendNotification();
861 application.Render();
863 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
864 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
869 int UtcDaliControlMarginProperty(void)
871 ToolkitTestApplication application;
873 Control control = Control::New();
874 control.SetBackgroundColor( Color::BLUE );
876 control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
878 Stage::GetCurrent().Add( control );
880 application.SendNotification();
881 application.Render();
883 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
885 // Parent control has one ImageView as a Child.
886 ImageView image = ImageView::New();
887 image.SetBackgroundColor( Color::RED );
888 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
889 image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
890 control.Add( image );
892 application.SendNotification();
893 application.Render();
895 DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
900 int UtcDaliControlPaddingProperty(void)
902 ToolkitTestApplication application;
904 Control control = Control::New();
905 control.SetBackgroundColor( Color::BLUE );
907 control.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
909 Stage::GetCurrent().Add( control );
911 application.SendNotification();
912 application.Render();
914 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );