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";
80 ///////////////////////////////////////////////////////////////////////////////////////////////////
83 int UtcDaliControlConstructor(void)
85 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
89 DALI_TEST_CHECK( !Control::DownCast(dummy) );
91 dummy = DummyControl::New();
93 DALI_TEST_CHECK( Control::DownCast(dummy) );
97 int UtcDaliControlNew(void)
99 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
103 DALI_TEST_CHECK( !Control::DownCast(control) );
105 control = Control::New();
107 DALI_TEST_CHECK( Control::DownCast(control) );
112 int UtcDaliControlRegister(void)
114 ToolkitTestApplication application;
116 // Ensure the object is registered after creation
117 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
118 DALI_TEST_CHECK( registry );
120 gObjectCreatedCallBackCalled = false;
121 registry.ObjectCreatedSignal().Connect( &TestCallback );
123 Alignment alignment = Alignment::New();
125 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
129 int UtcDaliControlCopyAndAssignment(void)
131 ToolkitTestApplication application;
133 DummyControl control = DummyControl::New();
134 Control emptyControl;
136 Control controlCopy( control );
137 DALI_TEST_CHECK( control == controlCopy );
139 Control emptyControlCopy( emptyControl );
140 DALI_TEST_CHECK( emptyControl == emptyControlCopy );
142 Control controlEquals;
143 controlEquals = control;
144 DALI_TEST_CHECK( control == controlEquals );
146 Control emptyControlEquals;
147 emptyControlEquals = emptyControl;
148 DALI_TEST_CHECK( emptyControl == emptyControlEquals );
152 DALI_TEST_CHECK( control == controlCopy );
156 int UtcDaliControlDownCast(void)
158 ToolkitTestApplication application;
160 DummyControl control;
162 DALI_TEST_CHECK( !Control::DownCast( control ) );
164 control = DummyControl::New();
166 DALI_TEST_CHECK( Control::DownCast( control ) );
170 DALI_TEST_CHECK( !Control::DownCast( actor ) );
172 actor = Actor::New();
174 DALI_TEST_CHECK( !Control::DownCast( actor ) );
178 int UtcDaliControlDownCastTemplate(void)
180 ToolkitTestApplication application;
182 DummyControl control;
184 DALI_TEST_CHECK( !DummyControl::DownCast( control ));
186 control = DummyControl::New();
188 DALI_TEST_CHECK( DummyControl::DownCast( control ) );
192 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
194 actor = Actor::New();
196 DALI_TEST_CHECK( !DummyControl::DownCast( actor ) );
200 int UtcDaliControlNavigationProperties(void)
202 ToolkitTestApplication application;
204 Control control = Control::New();
205 Stage::GetCurrent().Add( control );
207 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
208 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
209 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
210 DALI_TEST_EQUALS( -1, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
212 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 1 );
213 DALI_TEST_EQUALS( 1, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
214 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 2 );
215 DALI_TEST_EQUALS( 2, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
216 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 3 );
217 DALI_TEST_EQUALS( 3, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
218 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 4 );
219 DALI_TEST_EQUALS( 4, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
221 control.SetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID, 15 );
222 DALI_TEST_EQUALS( 15, control.GetProperty( DevelControl::Property::LEFT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
223 control.SetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID, 16 );
224 DALI_TEST_EQUALS( 16, control.GetProperty( DevelControl::Property::RIGHT_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
225 control.SetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID, 17 );
226 DALI_TEST_EQUALS( 17, control.GetProperty( DevelControl::Property::UP_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
227 control.SetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID, 18 );
228 DALI_TEST_EQUALS( 18, control.GetProperty( DevelControl::Property::DOWN_FOCUSABLE_ACTOR_ID ).Get< int >(), TEST_LOCATION );
233 int UtcDaliControlKeyInputFocus(void)
235 ToolkitTestApplication application;
236 Stage stage = Stage::GetCurrent();
238 DummyControl control;
240 PushButton pushButton1 = PushButton::New();
241 stage.Add( pushButton1 );
243 pushButton1.SetKeyInputFocus();
244 DALI_TEST_CHECK( pushButton1.HasKeyInputFocus() );
246 pushButton1.ClearKeyInputFocus();
247 DALI_TEST_CHECK( !pushButton1.HasKeyInputFocus() );
251 int UtcDaliControlGetImplementationN(void)
253 ToolkitTestApplication application;
254 DummyControl control;
260 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
261 (void)controlImpl; // Avoid unused warning
262 tet_result(TET_FAIL);
264 catch (DaliException &exception)
266 tet_result(TET_PASS);
272 int UtcDaliControlGetImplementationConstN(void)
274 ToolkitTestApplication application;
275 DummyControl control;
281 const DummyControl constControl(control);
282 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
283 (void)controlImpl; // Avoid unused warning
284 tet_result(TET_FAIL);
286 catch (DaliException &exception)
288 tet_result(TET_PASS);
294 int UtcDaliControlGetImplementationP(void)
296 ToolkitTestApplication application;
297 DummyControl control = DummyControl::New();
303 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
304 (void)controlImpl; // Avoid unused warning
305 tet_result(TET_PASS);
307 catch (DaliException &exception)
309 tet_result(TET_FAIL);
315 int UtcDaliControlGetImplementationConstP(void)
317 ToolkitTestApplication application;
318 DummyControl control = DummyControl::New();
323 const DummyControl constControl(control);
324 const Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( constControl );
325 (void)controlImpl; // Avoid unused warning
326 tet_result(TET_PASS);
328 catch (DaliException &exception)
330 tet_result(TET_FAIL);
336 int UtcDaliControlSignalConnectDisconnect(void)
338 ToolkitTestApplication application;
341 DummyControl dummy = DummyControlImpl::New();
343 Actor actor = Actor::New();
344 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
345 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
346 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
348 if( dummyImpl == NULL )
350 tet_result( TET_FAIL );
354 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
355 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
356 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
358 Stage::GetCurrent().Add( actor );
359 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
361 dummyImpl->mCustomSlot1Called = false;
362 actor.OnStageSignal().Disconnect( dummyImpl, &DummyControlImpl::CustomSlot1 );
363 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
364 Stage::GetCurrent().Remove( actor );
365 Stage::GetCurrent().Add( actor );
366 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
371 int UtcDaliControlSignalAutomaticDisconnect(void)
373 ToolkitTestApplication application;
375 Actor actor = Actor::New();
378 DummyControl dummy = DummyControlImpl::New();
379 Toolkit::Internal::Control& control = Toolkit::Internal::GetImplementation( dummy );
380 DummyControlImpl* dummyImpl = dynamic_cast<DummyControlImpl*>(&control);
382 if( dummyImpl == NULL )
384 tet_result( TET_FAIL );
388 actor.OnStageSignal().Connect( dummyImpl, &DummyControlImpl::CustomSlot1 );
389 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 1u, TEST_LOCATION );
390 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, false, TEST_LOCATION );
392 Stage::GetCurrent().Add( actor );
393 DALI_TEST_EQUALS( dummyImpl->mCustomSlot1Called, true, TEST_LOCATION );
394 Stage::GetCurrent().Remove( actor );
396 // dummyControl automatically disconnects
398 DALI_TEST_EQUALS( actor.OnStageSignal().GetConnectionCount(), 0u, TEST_LOCATION );
400 const Vector3 ignoredSize( 20, 20, 0 );
401 actor.SetSize( ignoredSize );
405 int UtcDaliControlTestParameters(void)
407 ToolkitTestApplication application;
408 DummyControl test = DummyControl::New();
410 test.SetSize( 0.7f, 0.7f, 0.7f );
412 Stage::GetCurrent().Add( test );
414 application.SendNotification();
415 application.Render();
417 float width = 640.0f;
418 float height = test.GetHeightForWidth( width );
419 DALI_TEST_EQUALS( 640.0f, height, TEST_LOCATION );
420 DALI_TEST_EQUALS( 640.0f, test.GetWidthForHeight( height ), TEST_LOCATION );
422 test.KeyEventSignal();
424 // Provide coverage for pointer destructor
425 Control* testControlPtr = new Control;
426 DALI_TEST_CHECK( testControlPtr );
427 delete testControlPtr;
431 int UtcDaliControlBackgroundColor(void)
433 ToolkitTestApplication application;
434 Control control = Control::New();
436 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
438 control.SetBackgroundColor( Color::RED );
440 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
441 Property::Map* resultMap = propValue.GetMap();
442 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
443 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::COLOR );
444 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
445 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::RED );
447 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::RED, TEST_LOCATION );
449 control.SetBackgroundColor( Color::YELLOW );
451 propValue = control.GetProperty( Control::Property::BACKGROUND );
452 resultMap = propValue.GetMap();
453 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
454 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>() == Color::YELLOW );
456 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::YELLOW, TEST_LOCATION );
461 int UtcDaliControlBackgroundImage(void)
463 ToolkitTestApplication application;
464 Control control = Control::New();
466 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
468 Image image = ResourceImage::New("TestImage");
469 control.SetBackgroundImage( image );
471 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
472 Property::Map* resultMap = propValue.GetMap();
473 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
474 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>() == Visual::IMAGE );
475 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
476 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage" );
478 image = ResourceImage::New("TestImage2");
479 control.SetBackgroundImage( image );
481 propValue = control.GetProperty( Control::Property::BACKGROUND );
482 resultMap = propValue.GetMap();
483 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
484 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>() == "TestImage2" );
489 int UtcDaliControlBackgroundProperties(void)
491 ToolkitTestApplication application;
492 Control control = Control::New();
494 DALI_TEST_EQUALS( control.GetBackgroundColor(), Color::TRANSPARENT, TEST_LOCATION );
495 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
497 Property::Map imageMap;
498 imageMap[ Toolkit::Visual::Property::TYPE ] = Visual::IMAGE;
499 imageMap[ ImageVisual::Property::URL ] = "TestImage";
500 control.SetProperty( Control::Property::BACKGROUND, imageMap );
501 Property::Value propValue = control.GetProperty( Control::Property::BACKGROUND );
502 Property::Map* resultMap = propValue.GetMap();
503 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
504 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(),(int)Visual::IMAGE, TEST_LOCATION );
505 DALI_TEST_CHECK( resultMap->Find( ImageVisual::Property::URL ) );
506 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "TestImage", TEST_LOCATION );
508 Property::Map rendererMap;
509 rendererMap[Visual::Property::TYPE] = Visual::COLOR;
510 rendererMap[ColorVisual::Property::MIX_COLOR] = Color::CYAN;
511 control.SetProperty( Control::Property::BACKGROUND, rendererMap );
512 propValue = control.GetProperty( Control::Property::BACKGROUND );
513 resultMap = propValue.GetMap();
514 DALI_TEST_CHECK( resultMap->Find( Toolkit::Visual::Property::TYPE ) );
515 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
516 DALI_TEST_CHECK( resultMap->Find( ColorVisual::Property::MIX_COLOR ) );
517 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::CYAN, TEST_LOCATION );
519 Property::Map emptyMap;
520 control.SetProperty( Control::Property::BACKGROUND, emptyMap );
521 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND ).Get< Property::Map >().Empty() );
524 control.SetProperty( Control::Property::BACKGROUND, "Foobar.png" );
525 propValue = control.GetProperty( Control::Property::BACKGROUND );
526 resultMap = propValue.GetMap();
527 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::IMAGE, TEST_LOCATION );
528 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get<std::string>(), "Foobar.png", TEST_LOCATION );
531 control.SetProperty( Control::Property::BACKGROUND, Color::RED );
532 propValue = control.GetProperty( Control::Property::BACKGROUND );
533 resultMap = propValue.GetMap();
534 DALI_TEST_EQUALS( resultMap->Find( Toolkit::Visual::Property::TYPE )->Get<int>(), (int)Visual::COLOR, TEST_LOCATION );
535 DALI_TEST_EQUALS( resultMap->Find( ColorVisual::Property::MIX_COLOR )->Get<Vector4>(), Color::RED, TEST_LOCATION );
537 // Deprecated Properties
538 control.SetProperty( Control::Property::BACKGROUND_COLOR, Color::YELLOW );
539 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), Color::YELLOW, TEST_LOCATION );
540 DALI_TEST_EQUALS( control.GetProperty( Control::Property::BACKGROUND_COLOR ).Get< Vector4 >(), control.GetBackgroundColor(), TEST_LOCATION );
542 control.ClearBackground();
544 Property::Map deprecatedImageMap;
545 deprecatedImageMap[ "filename" ] = "TestImage";
546 control.SetProperty( Control::Property::BACKGROUND_IMAGE, deprecatedImageMap );
547 propValue = control.GetProperty( Control::Property::BACKGROUND_IMAGE );
548 resultMap = propValue.GetMap();
549 DALI_TEST_EQUALS( resultMap->Find( ImageVisual::Property::URL )->Get< std::string >(), "TestImage" , TEST_LOCATION );
551 control.SetProperty( Control::Property::BACKGROUND_IMAGE, emptyMap );
552 DALI_TEST_CHECK( control.GetProperty( Control::Property::BACKGROUND_IMAGE ).Get< Property::Map >().Empty() );
557 int UtcDaliControlKeyProperties(void)
559 ToolkitTestApplication application;
561 Control control = Control::New();
562 Stage::GetCurrent().Add( control );
564 DALI_TEST_EQUALS( control.HasKeyInputFocus(), control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
566 control.SetKeyInputFocus();
567 DALI_TEST_EQUALS( true, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
569 control.ClearKeyInputFocus();
570 DALI_TEST_EQUALS( false, control.GetProperty( Control::Property::KEY_INPUT_FOCUS ).Get< bool >(), TEST_LOCATION );
572 control.SetProperty( Control::Property::KEY_INPUT_FOCUS, true );
573 DALI_TEST_EQUALS( true, control.HasKeyInputFocus(), TEST_LOCATION );
578 int UtcDaliControlGestureSignals(void)
580 ToolkitTestApplication application;
581 ConnectionTracker connectionTracker;
582 Control control = Control::New();
584 // Each gesture detector gets created when connecting to the gesture signals
585 DALI_TEST_CHECK( !control.GetTapGestureDetector() );
586 control.ConnectSignal( &connectionTracker, "tapped", &TestVoidCallback );
587 DALI_TEST_CHECK( control.GetTapGestureDetector() );
589 DALI_TEST_CHECK( !control.GetPanGestureDetector() );
590 control.ConnectSignal( &connectionTracker, "panned", &TestVoidCallback );
591 DALI_TEST_CHECK( control.GetPanGestureDetector() );
593 DALI_TEST_CHECK( !control.GetPinchGestureDetector() );
594 control.ConnectSignal( &connectionTracker, "pinched", &TestVoidCallback );
595 DALI_TEST_CHECK( control.GetPinchGestureDetector() );
597 DALI_TEST_CHECK( !control.GetLongPressGestureDetector() );
598 control.ConnectSignal( &connectionTracker, "longPressed", &TestVoidCallback );
599 DALI_TEST_CHECK( control.GetLongPressGestureDetector() );
604 int UtcDaliControlImplKeyInputFocusGainedSignal(void)
606 ToolkitTestApplication application;
608 Control control = Control::New();
609 Stage::GetCurrent().Add( control );
611 gKeyInputFocusCallBackCalled = false;
612 control.KeyInputFocusGainedSignal().Connect(&TestKeyInputFocusCallback);
614 application.SendNotification();
615 application.Render();
617 control.SetKeyInputFocus();
619 DALI_TEST_CHECK( control.HasKeyInputFocus() );
621 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
626 int UtcDaliControlImplKeyInputFocusLostSignal(void)
628 ToolkitTestApplication application;
630 Control control = Control::New();
631 Stage::GetCurrent().Add( control );
633 gKeyInputFocusCallBackCalled = false;
634 control.KeyInputFocusLostSignal().Connect(&TestKeyInputFocusCallback);
636 application.SendNotification();
637 application.Render();
639 control.SetKeyInputFocus();
641 DALI_TEST_CHECK( control.HasKeyInputFocus() );
643 control.ClearKeyInputFocus();
645 DALI_TEST_CHECK( gKeyInputFocusCallBackCalled );
650 int UtcDaliControlImplGetControlExtensionP(void)
652 ToolkitTestApplication application;
653 Control control = Control::New();
655 Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation( control );
657 DALI_TEST_CHECK( NULL == controlImpl.GetControlExtension() );
662 int UtcDaliControlAutoClipping(void)
664 ToolkitTestApplication application;
665 Control control = Control::New();
667 tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
669 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
671 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
673 Stage::GetCurrent().Add( control );
675 application.SendNotification();
676 application.Render();
678 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
683 int UtcDaliControlAutoClippingN(void)
685 ToolkitTestApplication application;
686 Control control = Control::New();
687 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
688 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
690 tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
692 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
694 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
696 Stage::GetCurrent().Add( control );
698 application.SendNotification();
699 application.Render();
701 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
703 // Ensure the background color is still RED rather than what's set by the automatic clipping
704 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
705 Property::Map* map = value.GetMap();
706 DALI_TEST_CHECK( map );
707 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
708 DALI_TEST_CHECK( colorValue );
709 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
714 int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
716 ToolkitTestApplication application;
717 Control control = Control::New();
719 tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
721 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
723 Stage::GetCurrent().Add( control );
725 application.SendNotification();
726 application.Render();
728 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
730 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
732 application.SendNotification();
733 application.Render();
735 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
740 int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
742 ToolkitTestApplication application;
743 Control control = Control::New();
744 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
745 .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
747 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" );
749 DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
751 Stage::GetCurrent().Add( control );
753 application.SendNotification();
754 application.Render();
756 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
758 control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
760 application.SendNotification();
761 application.Render();
763 DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
765 // Ensure the background color is still RED rather than what's set by the automatic clipping
766 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
767 Property::Map* map = value.GetMap();
768 DALI_TEST_CHECK( map );
769 Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
770 DALI_TEST_CHECK( colorValue );
771 DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
776 int UtcDaliControlSetTransformSize(void)
778 ToolkitTestApplication application;
779 Control control = Control::New();
781 Property::Map transformMap;
782 transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
783 .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
784 .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
785 .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
787 control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
788 .Add( Visual::Property::TRANSFORM, transformMap ) );
790 tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
792 Stage::GetCurrent().Add( control );
794 application.SendNotification();
795 application.Render();
797 // Ensure the transform property still matches what we set
798 Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
799 Property::Map* map = value.GetMap();
800 DALI_TEST_CHECK( map );
801 Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
802 DALI_TEST_CHECK( transformValue );
804 Property::Map* retMap = transformValue->GetMap();
805 DALI_TEST_CHECK( retMap );
806 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
807 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
808 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
809 DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
815 int UtcDaliControlResourcesReady(void)
817 ToolkitTestApplication application;
818 tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
820 VisualFactory factory = VisualFactory::Get();
821 DALI_TEST_CHECK( factory );
823 Property::Map propertyMapLarge;
824 propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
825 propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
827 Property::Map propertyMapSmall;
828 propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
829 propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
831 Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
832 smallVisual.SetName("smallVisual");
833 DALI_TEST_CHECK( smallVisual );
835 DummyControl actor = DummyControl::New();
836 DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
837 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
839 actor.SetSize( 200.f, 200.f );
841 Toolkit::Visual::ResourceStatus resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL);
842 DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
843 DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
844 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
846 Stage::GetCurrent().Add( actor );
847 application.SendNotification();
848 application.Render();
850 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
852 application.SendNotification();
853 application.Render();
855 resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL);
856 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
857 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
858 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
860 Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
861 largeVisual.SetName("largeVisual");
862 DALI_TEST_CHECK( largeVisual );
864 tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
866 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
868 resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL2);
869 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
871 application.SendNotification();
873 resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL2);
874 DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
875 DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
876 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
878 dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
880 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
882 application.SendNotification();
884 resourceStatus = DevelControl::GetVisualResourceStatus(dummyImpl, DummyControl::Property::TEST_VISUAL2);
885 DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
890 int UtcDaliControlMarginProperty(void)
892 ToolkitTestApplication application;
894 Control control = Control::New();
895 control.SetBackgroundColor( Color::BLUE );
897 control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
899 Stage::GetCurrent().Add( control );
901 application.SendNotification();
902 application.Render();
904 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
906 // Parent control has one ImageView as a Child.
907 ImageView image = ImageView::New();
908 image.SetBackgroundColor( Color::RED );
909 image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
910 image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
911 control.Add( image );
913 application.SendNotification();
914 application.Render();
916 DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
921 int UtcDaliControlPaddingProperty(void)
923 ToolkitTestApplication application;
925 Control control = Control::New();
926 control.SetBackgroundColor( Color::BLUE );
928 control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
930 Stage::GetCurrent().Add( control );
932 application.SendNotification();
933 application.Render();
935 DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
937 Control child = Control::New();
940 application.SendNotification();
941 application.Render();
943 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
945 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
946 application.SendNotification();
947 application.Render();
948 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
950 control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT);
951 application.SendNotification();
952 application.Render();
954 DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
959 int UtcDaliControlDoAction(void)
961 ToolkitTestApplication application;
962 tet_infoline( "DoAction on a visual registered with a control" );
964 // Set up trace debug
965 TestGlAbstraction& gl = application.GetGlAbstraction();
966 TraceCallStack& textureTrace = gl.GetTextureTrace();
967 textureTrace.Enable( true );
969 //Created AnimatedImageVisual
970 VisualFactory factory = VisualFactory::Get();
971 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
973 DummyControl dummyControl = DummyControl::New(true);
974 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
976 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
977 dummyControl.SetSize(200.f, 200.f);
978 Stage::GetCurrent().Add( dummyControl );
980 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
982 application.SendNotification();
983 application.Render();
984 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
985 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
986 textureTrace.Reset();
988 Property::Map attributes;
989 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
991 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
992 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
994 application.SendNotification();
995 application.Render();
996 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
997 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1001 int UtcDaliControlDoActionWhenNotStage(void)
1003 ToolkitTestApplication application;
1004 tet_infoline( "DoAction on a visual registered with a control but not staged" );
1006 // Set up trace debug
1007 TestGlAbstraction& gl = application.GetGlAbstraction();
1008 TraceCallStack& textureTrace = gl.GetTextureTrace();
1009 textureTrace.Enable( true );
1011 //Created AnimatedImageVisual
1012 VisualFactory factory = VisualFactory::Get();
1013 Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
1015 DummyControl dummyControl = DummyControl::New(true);
1016 Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
1018 dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
1019 dummyControl.SetSize(200.f, 200.f);
1021 application.SendNotification();
1022 application.Render();
1023 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1024 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1025 textureTrace.Reset();
1027 Property::Map attributes;
1028 DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
1030 tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
1031 DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
1033 application.SendNotification();
1034 application.Render();
1035 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
1036 textureTrace.Reset();
1038 tet_infoline( "Adding control to stage will in turn add the visual to the stage" );
1040 Stage::GetCurrent().Add( dummyControl );
1041 application.SendNotification();
1042 application.Render();
1043 tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" );
1045 DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
1046 DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
1047 textureTrace.Reset();