+
+int UtcDaliControlAutoClipping(void)
+{
+ ToolkitTestApplication application;
+ Control control = Control::New();
+
+ tet_infoline( "Test to see if a renderer gets added when we are clipping children" );
+
+ DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
+
+ control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlAutoClippingN(void)
+{
+ ToolkitTestApplication application;
+ Control control = Control::New();
+ control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
+ .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
+
+ tet_infoline( "Test to ensure that a renderer does NOT get added when we are clipping children and already have renderers/visuals" );
+
+ DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
+
+ control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Only 1, not 2
+
+ // Ensure the background color is still RED rather than what's set by the automatic clipping
+ Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
+ Property::Map* map = value.GetMap();
+ DALI_TEST_CHECK( map );
+ Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
+ DALI_TEST_CHECK( colorValue );
+ DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlAutoClippingWhenAlreadyOnStage(void)
+{
+ ToolkitTestApplication application;
+ Control control = Control::New();
+
+ tet_infoline( "Test to see if a renderer gets added when we are clipping children and when already on stage" );
+
+ DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
+
+ control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlAutoClippingWhenAlreadyOnStageN(void)
+{
+ ToolkitTestApplication application;
+ Control control = Control::New();
+ control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
+ .Add( ColorVisual::Property::MIX_COLOR, Color::RED ) );
+
+ 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" );
+
+ DALI_TEST_EQUALS( 0, control.GetRendererCount(), TEST_LOCATION );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION );
+
+ control.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( 1, control.GetRendererCount(), TEST_LOCATION ); // Still should be 1
+
+ // Ensure the background color is still RED rather than what's set by the automatic clipping
+ Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
+ Property::Map* map = value.GetMap();
+ DALI_TEST_CHECK( map );
+ Property::Value* colorValue = map->Find(ColorVisual::Property::MIX_COLOR );
+ DALI_TEST_CHECK( colorValue );
+ DALI_TEST_EQUALS( colorValue->Get< Vector4 >(), Color::RED, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlSetTransformSize(void)
+{
+ ToolkitTestApplication application;
+ Control control = Control::New();
+
+ Property::Map transformMap;
+ transformMap.Add( Visual::Transform::Property::OFFSET, Vector2( 10, 10 ) )
+ .Add( Visual::Transform::Property::ANCHOR_POINT, Align::BOTTOM_END )
+ .Add( Visual::Transform::Property::ORIGIN, Align::BOTTOM_END )
+ .Add( Visual::Transform::Property::SIZE, Vector2( 10, 20 ) );
+
+ control.SetProperty( Control::Property::BACKGROUND, Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
+ .Add( Visual::Property::TRANSFORM, transformMap ) );
+
+ tet_infoline( "Test to ensure that the control background transform does not get overwritten when adding to the stage" );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ // Ensure the transform property still matches what we set
+ Property::Value value = control.GetProperty( Control::Property::BACKGROUND );
+ Property::Map* map = value.GetMap();
+ DALI_TEST_CHECK( map );
+ Property::Value* transformValue = map->Find( Visual::Property::TRANSFORM );
+ DALI_TEST_CHECK( transformValue );
+
+ Property::Map* retMap = transformValue->GetMap();
+ DALI_TEST_CHECK( retMap );
+ DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::OFFSET )->Get< Vector2 >(), Vector2( 10, 10 ), TEST_LOCATION );
+ DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ANCHOR_POINT )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
+ DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::ORIGIN )->Get< int >(), (int)Align::BOTTOM_END, TEST_LOCATION );
+ DALI_TEST_EQUALS( retMap->Find( Visual::Transform::Property::SIZE )->Get< Vector2 >(), Vector2( 10, 20 ), TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliControlResourcesReady(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "Register 2 visuals and check ResourceReady when a visual is disabled" );
+
+ VisualFactory factory = VisualFactory::Get();
+ DALI_TEST_CHECK( factory );
+
+ Property::Map propertyMapLarge;
+ propertyMapLarge.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
+ propertyMapLarge.Insert( ImageVisual::Property::URL, TEST_LARGE_IMAGE_FILE_NAME );
+
+ Property::Map propertyMapSmall;
+ propertyMapSmall.Insert( Toolkit::Visual::Property::TYPE, Visual::IMAGE );
+ propertyMapSmall.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
+
+ Visual::Base smallVisual = factory.CreateVisual( propertyMapSmall );
+ smallVisual.SetName("smallVisual");
+ DALI_TEST_CHECK( smallVisual );
+
+ DummyControl actor = DummyControl::New();
+ DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, smallVisual );
+
+ actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
+
+ Toolkit::Visual::ResourceStatus resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
+ DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.IsResourceReady(), false, TEST_LOCATION );
+ DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
+
+ application.GetScene().Add( actor );
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL);
+ DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
+ DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
+
+ Visual::Base largeVisual = factory.CreateVisual( propertyMapLarge );
+ largeVisual.SetName("largeVisual");
+ DALI_TEST_CHECK( largeVisual );
+
+ tet_infoline( "Register Visual but set disabled, IsResourceReady should be true" );
+
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL2, largeVisual, false );
+
+ resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
+ DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
+
+ application.SendNotification();
+
+ resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
+ DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.IsResourceReady(), true, TEST_LOCATION );
+ DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::PREPARING), TEST_LOCATION );
+
+ dummyImpl.EnableVisual( DummyControl::Property::TEST_VISUAL2, true );
+
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+
+ resourceStatus = actor.GetVisualResourceStatus(DummyControl::Property::TEST_VISUAL2);
+ DALI_TEST_EQUALS( static_cast<int>(resourceStatus), static_cast<int>(Toolkit::Visual::ResourceStatus::READY), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlResourcesReady02(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "Change a resource during ResourceReady callback" );
+
+ gResourceReadySignalFired = false;
+
+ Control control = Control::New();
+ control.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
+ control.ResourceReadySignal().Connect( &ResourceReadySignal );
+
+ Property::Map propertyMap;
+ propertyMap.Insert( ImageVisual::Property::URL, "invalid.jpg" );
+ control.SetProperty( Control::Property::BACKGROUND, propertyMap );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( control.IsResourceReady(), true, TEST_LOCATION );
+ DALI_TEST_EQUALS( gResourceReadySignalFired, true, TEST_LOCATION );
+ gResourceReadySignalFired = false;
+
+ END_TEST;
+}
+
+int UtcDaliControlMarginProperty(void)
+{
+ ToolkitTestApplication application;
+
+ Control control = Control::New();
+ control.SetBackgroundColor( Color::BLUE );
+
+ control.SetProperty( Control::Property::MARGIN, Extents( 20, 10, 0, 0 ) );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::MARGIN ), Extents( 20, 10, 0, 0 ), TEST_LOCATION );
+
+ // Parent control has one ImageView as a Child.
+ ImageView image = ImageView::New();
+ image.SetBackgroundColor( Color::RED );
+ image.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ image.SetProperty( Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
+ control.Add( image );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( image.GetProperty<Extents>( Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlPaddingProperty(void)
+{
+ ToolkitTestApplication application;
+
+ Control control = Control::New();
+ control.SetBackgroundColor( Color::BLUE );
+
+ control.SetProperty( Control::Property::PADDING, Extents( 15, 10, 5, 10 ) );
+
+ application.GetScene().Add( control );
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( control.GetProperty<Extents>( Control::Property::PADDING ), Extents( 15, 10, 5, 10 ), TEST_LOCATION );
+
+ Control child = Control::New();
+ control.Add(child);
+
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
+
+ control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 10, 5, 0 ), TEST_LOCATION );
+
+ control.SetProperty( Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::LEFT_TO_RIGHT);
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_EQUALS( child.GetProperty<Vector3>( Dali::Actor::Property::POSITION ), Vector3( 15, 5, 0 ), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliControlDoAction(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "DoAction on a visual registered with a control" );
+
+ // Set up trace debug
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable( true );
+
+ //Created AnimatedImageVisual
+ VisualFactory factory = VisualFactory::Get();
+ Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
+
+ DummyControl dummyControl = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
+ dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
+ application.GetScene().Add( dummyControl );
+
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
+ textureTrace.Reset();
+
+ Property::Map attributes;
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
+
+ tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
+ END_TEST;
+}
+
+int UtcDaliControlDoActionWhenNotStage(void)
+{
+ ToolkitTestApplication application;
+ tet_infoline( "DoAction on a visual registered with a control but not staged" );
+
+ // Set up trace debug
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ TraceCallStack& textureTrace = gl.GetTextureTrace();
+ textureTrace.Enable( true );
+
+ //Created AnimatedImageVisual
+ VisualFactory factory = VisualFactory::Get();
+ Visual::Base imageVisual = factory.CreateVisual( TEST_IMAGE_FILE_NAME, ImageDimensions() );
+
+ DummyControl dummyControl = DummyControl::New(true);
+ Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+
+ dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, imageVisual );
+ dummyControl.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) );
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
+ textureTrace.Reset();
+
+ Property::Map attributes;
+ DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, DevelImageVisual::Action::RELOAD, attributes );
+
+ tet_infoline( "Perform RELOAD action. should reload Image and generate a texture" );
+ DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION );
+ textureTrace.Reset();
+
+ tet_infoline( "Adding control to stage will in turn add the visual to the stage" );
+
+ application.GetScene().Add( dummyControl );
+ application.SendNotification();
+ application.Render();
+ tet_infoline( "No change in textures could occurs as already loaded and cached texture will be used" );
+
+ DALI_TEST_EQUALS( textureTrace.CountMethod("DeleteTextures"), 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), false, TEST_LOCATION );
+ textureTrace.Reset();
+
+ END_TEST;
+}