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/devel-api/visuals/visual-properties-devel.h>
28 #include <dali-toolkit/devel-api/align-enums.h>
29 #include <dali-toolkit/devel-api/controls/control-devel.h>
30 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
31 #include <toolkit-event-thread-callback.h>
33 #include "dummy-control.h"
36 using namespace Dali::Toolkit;
38 void utc_dali_toolkit_control_startup(void)
40 test_return_value = TET_UNDEF;
43 void utc_dali_toolkit_control_cleanup(void)
45 test_return_value = TET_PASS;
48 ///////////////////////////////////////////////////////////////////////////////////////////////////
53 bool gObjectCreatedCallBackCalled;
55 void TestCallback(BaseHandle handle)
57 gObjectCreatedCallBackCalled = true;
60 void TestVoidCallback()
64 static bool gKeyInputFocusCallBackCalled;
66 static void TestKeyInputFocusCallback( Control control )
68 tet_infoline(" TestKeyInputFocusCallback");
70 gKeyInputFocusCallBackCalled = true;
73 const char* TEST_LARGE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/tbcol.png";
74 const char* TEST_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
78 ///////////////////////////////////////////////////////////////////////////////////////////////////
81 int UtcDaliControlConstructor(void)
83 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
87 DALI_TEST_CHECK( !Control::DownCast(dummy) );
89 dummy = DummyControl::New();
91 DALI_TEST_CHECK( Control::DownCast(dummy) );
95 int UtcDaliControlNew(void)
97 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
101 DALI_TEST_CHECK( !Control::DownCast(control) );
103 control = Control::New();
105 DALI_TEST_CHECK( Control::DownCast(control) );
110 int UtcDaliControlRegister(void)
112 ToolkitTestApplication application;
114 // Ensure the object is registered after creation
115 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
116 DALI_TEST_CHECK( registry );
118 gObjectCreatedCallBackCalled = false;
119 registry.ObjectCreatedSignal().Connect( &TestCallback );
121 Alignment alignment = Alignment::New();
123 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
127 int UtcDaliControlCopyAndAssignment(void)
129 ToolkitTestApplication application;
131 DummyControl control = DummyControl::New();
132 Control emptyControl;
134 Control controlCopy( control );
135 DALI_TEST_CHECK( control == controlCopy );
137 Control emptyControlCopy( emptyControl );
138 DALI_TEST_CHECK( emptyControl == emptyControlCopy );
140 Control controlEquals;
141 controlEquals = control;
142 DALI_TEST_CHECK( control == controlEquals );
144 Control emptyControlEquals;
145 emptyControlEquals = emptyControl;
146 DALI_TEST_CHECK( emptyControl == emptyControlEquals );
150 DALI_TEST_CHECK( control == controlCopy );
154 int UtcDaliControlDownCast(void)
156 ToolkitTestApplication application;
158 DummyControl control;
160 DALI_TEST_CHECK( !Control::DownCast( control ) );
162 control = DummyControl::New();
164 DALI_TEST_CHECK( Control::DownCast( control ) );
168 DALI_TEST_CHECK( !Control::DownCast( actor ) );
170 actor = Actor::New();
172 DALI_TEST_CHECK( !Control::DownCast( actor ) );
176 int UtcDaliControlDownCastTemplate(void)
178 ToolkitTestApplication application;
180 DummyControl control;
182 DALI_TEST_CHECK( !DummyControl::DownCast( control ));
184 control = DummyControl::New();
186 DALI_TEST_CHECK( DummyControl::DownCast( control ) );
190 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
192 actor = Actor::New();
194 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
198 int UtcDaliControlNavigationProperties(void)
200 ToolkitTestApplication application;
202 Control control = Control::New();
203 Stage::GetCurrent().Add( control );
205 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
206 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
207 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
208 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
210 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 );
211 DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
212 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 );
213 DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
214 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 );
215 DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
216 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 );
217 DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
219 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 );
220 DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
221 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 );
222 DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
223 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 );
224 DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
225 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 );
226 DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
231 int UtcDaliControlKeyInputFocus(void)
233 ToolkitTestApplication application;
234 Stage stage = Stage::GetCurrent();
236 DummyControl control;
238 PushButton pushButton1 = PushButton::New();
239 stage.Add( pushButton1 );
241 pushButton1.SetKeyInputFocus();
242 DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
244 pushButton1.ClearKeyInputFocus();
245 DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
249 int UtcDaliControlGetImplementationN(void)
251 ToolkitTestApplication application;
252 DummyControl control;
258 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
259 (void)controlImpl; // Avoid unused warning
260 tet_result(TET_FAIL);
262 catch (DaliException &exception)
264 tet_result(TET_PASS);
270 int UtcDaliControlGetImplementationConstN(void)
272 ToolkitTestApplication application;
273 DummyControl control;
279 const DummyControl constControl(control);
280 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
281 (void)controlImpl; // Avoid unused warning
282 tet_result(TET_FAIL);
284 catch (DaliException &exception)
286 tet_result(TET_PASS);
292 int UtcDaliControlGetImplementationP(void)
294 ToolkitTestApplication application;
295 DummyControl control = DummyControl::New();
301 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
302 (void)controlImpl; // Avoid unused warning
303 tet_result(TET_PASS);
305 catch (DaliException &exception)
307 tet_result(TET_FAIL);
313 int UtcDaliControlGetImplementationConstP(void)
315 ToolkitTestApplication application;
316 DummyControl control = DummyControl::New();
321 const DummyControl constControl(control);
322 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
323 (void)controlImpl; // Avoid unused warning
324 tet_result(TET_PASS);
326 catch (DaliException &exception)
328 tet_result(TET_FAIL);
334 int UtcDaliControlSignalConnectDisconnect(void)
336 ToolkitTestApplication application;
339 DummyControl dummy = DummyControlImpl::New();
341 Actor actor = Actor::New();
342 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
343 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
344 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
346 if( dummyImpl == NULL )
348 tet_result( TET_FAIL );
352 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
353 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
354 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
356 Stage::GetCurrent().Add( actor );
357 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
359 dummyImpl->mCustomSlot1Called = false;
360 actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
361 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
362 Stage::GetCurrent().Remove( actor );
363 Stage::GetCurrent().Add( actor );
364 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
369 int UtcDaliControlSignalAutomaticDisconnect(void)
371 ToolkitTestApplication application;
373 Actor actor = Actor::New();
376 DummyControl dummy = DummyControlImpl::New();
377 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
378 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
380 if( dummyImpl == NULL )
382 tet_result( TET_FAIL );
386 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
387 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
388 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
390 Stage::GetCurrent().Add( actor );
391 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
392 Stage::GetCurrent().Remove( actor );
394 // dummyControl automatically disconnects
396 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
398 const Vector3 ignoredSize( 20, 20, 0 );
399 actor.SetSize( ignoredSize );
403 int UtcDaliControlTestParameters(void)
405 ToolkitTestApplication application;
406 DummyControl test = DummyControl::New();
408 test.SetSize( 0.7f, 0.7f, 0.7f );
410 Stage::GetCurrent().Add( test );
412 application.SendNotification();
413 application.Render();
415 float width = 640.0f;
416 float height = test.GetHeightForWidth( width );
417 DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
418 DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
420 test.KeyEventSignal();
422 // Provide coverage for pointer destructor
423 Control* testControlPtr = new Control;
424 DALI_TEST_CHECK( testControlPtr );
425 delete testControlPtr;
429 int UtcDaliControlBackgroundColor(void)
431 ToolkitTestApplication application;
432 Control control = Control::New();
434 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
436 control.SetBackgroundColor( Color::RED );
438 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
439 Property::Map* resultMap = propValue.GetMap();
440 DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
441 DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
442 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
443 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
445 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
447 control.SetBackgroundColor( Color::YELLOW );
449 propValue = control.GetProperty( Control::Property::BACKGROUND );
450 resultMap = propValue.GetMap();
451 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
452 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
454 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
459 int UtcDaliControlBackgroundImage(void)
461 ToolkitTestApplication application;
462 Control control = Control::New();
464 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
466 Image image = ResourceImage::New("TestImage");
467 control.SetBackgroundImage( image );
469 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
470 Property::Map* resultMap = propValue.GetMap();
471 DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
472 DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
473 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
474 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
476 image = ResourceImage::New("TestImage2");
477 control.SetBackgroundImage( image );
479 propValue = control.GetProperty( Control::Property::BACKGROUND );
480 resultMap = propValue.GetMap();
481 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
482 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
487 int UtcDaliControlBackgroundProperties(void)
489 ToolkitTestApplication application;
490 Control control = Control::New();
492 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
493 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
495 Property::Map imageMap;
496 imageMap[ Visual::Property::TYPE ] = Visual::IMAGE;
497 imageMap[ ImageVisual::Property::URL ] = "TestImage";
498 control.SetProperty( Control::Property::BACKGROUND, imageMap );
499 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
500 Property::Map* resultMap = propValue.GetMap();
501 DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
502 DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
503 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
504 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
506 Property::Map rendererMap;
507 rendererMap[Visual::Property::TYPE] = Visual::COLOR;
508 rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
509 control.SetProperty( Control::Property::BACKGROUND, rendererMap );
510 propValue = control.GetProperty( Control::Property::BACKGROUND );
511 resultMap = propValue.GetMap();
512 DALI_TEST_CHECK( resultMap->Find( Visual::Property::TYPE ) );
513 DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
514 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
515 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
517 Property::Map emptyMap;
518 control.SetProperty( Control::Property::BACKGROUND, emptyMap );
519 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
522 control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
523 propValue = control.GetProperty( Control::Property::BACKGROUND );
524 resultMap = propValue.GetMap();
525 DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
526 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
529 control.SetProperty( Control::Property::BACKGROUND, Color::RED );
530 propValue = control.GetProperty( Control::Property::BACKGROUND );
531 resultMap = propValue.GetMap();
532 DALI_TEST_EQUALS( resultMap->Find( Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
533 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
535 // Deprecated Properties
536 control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
537 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
538 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
540 control.ClearBackground();
542 Property::Map deprecatedImageMap;
543 deprecatedImageMap[ "filename" ] = "TestImage";
544 control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
545 propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
546 resultMap = propValue.GetMap();
547 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
549 control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
550 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
555 int UtcDaliControlKeyProperties(void)
557 ToolkitTestApplication application;
559 Control control = Control::New();
560 Stage::GetCurrent().Add( control );
562 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
564 control.SetKeyInputFocus();
565 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
567 control.ClearKeyInputFocus();
568 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
570 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
571 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
576 int UtcDaliControlGestureSignals(void)
578 ToolkitTestApplication application;
579 ConnectionTracker connectionTracker;
580 Control control = Control::New();
582 // Each gesture detector gets created when connecting to the gesture signals
583 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
584 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
585 DALI_TEST_CHECK( control.GetTapGestureDetector() );
587 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
588 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
589 DALI_TEST_CHECK( control.GetPanGestureDetector() );
591 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
592 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
593 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
595 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
596 control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback );
597 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
602 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
604 ToolkitTestApplication application;
606 Control control = Control::New();
607 Stage::GetCurrent().Add( control );
609 gKeyInputFocusCallBackCalled = false;
610 control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
612 application.SendNotification();
613 application.Render();
615 control.SetKeyInputFocus();
617 DALI_TEST_CHECK( control.HasKeyInputFocus() );
619 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
624 int UtcDaliControlImplKeyInputFocusLostSignal(void)
626 ToolkitTestApplication application;
628 Control control = Control::New();
629 Stage::GetCurrent().Add( control );
631 gKeyInputFocusCallBackCalled = false;
632 control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
634 application.SendNotification();
635 application.Render();
637 control.SetKeyInputFocus();
639 DALI_TEST_CHECK( control.HasKeyInputFocus() );
641 control.ClearKeyInputFocus();
643 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
648 int UtcDaliControlImplGetControlExtensionP(void)
650 ToolkitTestApplication application;
651 Control control = Control::New();
653 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
655 DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
660 int UtcDaliControlAutoClipping(void)
662 ToolkitTestApplication application;
663 Control control = Control::New();
665 tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
667 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
669 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
671 Stage::GetCurrent().Add( control );
673 application.SendNotification();
674 application.Render();
676 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
681 int UtcDaliControlAutoClippingN(void)
683 ToolkitTestApplication application;
684 Control control = Control::New();
685 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
686 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
688 tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
690 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
692 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
694 Stage::GetCurrent().Add( control );
696 application.SendNotification();
697 application.Render();
699 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
701 // Ensure the background color is still RED rather than what's set by the automatic clipping
702 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
703 Property::Map* map = value.GetMap();
704 DALI_TEST_CHECK( map );
705 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
706 DALI_TEST_CHECK( colorValue );
707 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
712 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
714 ToolkitTestApplication application;
715 Control control = Control::New();
717 tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
719 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
721 Stage::GetCurrent().Add( control );
723 application.SendNotification();
724 application.Render();
726 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
728 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
730 application.SendNotification();
731 application.Render();
733 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
738 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
740 ToolkitTestApplication application;
741 Control control = Control::New();
742 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
743 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
745 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" );
747 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
749 Stage::GetCurrent().Add( control );
751 application.SendNotification();
752 application.Render();
754 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
756 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
758 application.SendNotification();
759 application.Render();
761 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
763 // Ensure the background color is still RED rather than what's set by the automatic clipping
764 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
765 Property::Map* map = value.GetMap();
766 DALI_TEST_CHECK( map );
767 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
768 DALI_TEST_CHECK( colorValue );
769 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
774 int UtcDaliControlSetTransformSize(void)
776 ToolkitTestApplication application;
777 Control control = Control::New();
779 Property::Map transformMap;
780 transformMap.Add( DevelVisual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
781 .Add( DevelVisual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
782 .Add( DevelVisual::Transform::Property::ORIGIN, Align::BOTTOM_END )
783 .Add( DevelVisual::Transform::Property::SIZE, Vector2( 10, 20 ) );
785 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Visual::Property::TYPE, Visual::COLOR )
786 .Add( DevelVisual::Property::TRANSFORM, transformMap ) );
788 tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
790 Stage::GetCurrent().Add( control );
792 application.SendNotification();
793 application.Render();
795 // Ensure the transform property still matches what we set
796 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
797 Property::Map* map = value.GetMap();
798 DALI_TEST_CHECK( map );
799 Property::Value* transformValue = map->Find( DevelVisual::Property::TRANSFORM );
800 DALI_TEST_CHECK( transformValue );
802 Property::Map* retMap = transformValue->GetMap();
803 DALI_TEST_CHECK( retMap );
804 DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
805 DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
806 DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
807 DALI_TEST_EQUALS( retMap->Find( DevelVisual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
813 int UtcDaliControlResourcesReady(void)
815 ToolkitTestApplication application;
816 tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
818 VisualFactory factory = VisualFactory::Get();
819 DALI_TEST_CHECK( factory );
821 Property::Map propertyMapLarge;
822 propertyMapLarge.Insert( Visual::Property::TYPE, Visual::IMAGE );
823 propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
825 Property::Map propertyMapSmall;
826 propertyMapSmall.Insert( Visual::Property::TYPE, Visual::IMAGE );
827 propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
829 Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
830 smallVisual.SetName("smallVisual");
831 DALI_TEST_CHECK( smallVisual );
833 DummyControl actor = DummyControl::New();
834 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
835 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
837 actor.SetSize( 200.f, 200.f );
838 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
839 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
841 Stage::GetCurrent().Add( actor );
842 application.SendNotification();
843 application.Render();
845 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
847 application.SendNotification();
848 application.Render();
850 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
851 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
853 Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
854 largeVisual.SetName("largeVisual");
855 DALI_TEST_CHECK( largeVisual );
857 tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
859 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
861 application.SendNotification();
862 application.Render();
864 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
865 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );