X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-VisualFactory.cpp;h=929825ce572e62e5a40b8299079247ea84dd8509;hp=c7f4282da5ef0e539d1a6c5f406933f59f5c1d75;hb=e9ce8b35ce64531e5c6c6214527a5bf9b9747a36;hpb=071b25e591f0fff83d85087e3963fbe6387b7551 diff --git a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp index c7f4282..929825c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "dummy-control.h" #include @@ -33,7 +34,7 @@ using namespace Dali::Toolkit; namespace { -typedef Toolkit::Internal::NPatchLoader::StretchRanges StretchRanges; +typedef Toolkit::NPatchUtility::StretchRanges StretchRanges; const char* TEST_9_PATCH_FILE_NAME = TEST_RESOURCE_DIR "/demo-tile-texture-focused.9.png"; const char* TEST_NPATCH_FILE_NAME = TEST_RESOURCE_DIR "/heartsframe.9.png"; @@ -72,10 +73,10 @@ void TestVisualRender( ToolkitTestApplication& application, DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add( actor ); application.SendNotification(); application.Render(); @@ -93,10 +94,10 @@ void TestVisualAsynchronousRender( ToolkitTestApplication& application, DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add( actor ); application.SendNotification(); application.Render(); @@ -231,7 +232,7 @@ int UtcDaliVisualFactoryGetColorVisual2(void) DALI_TEST_EQUALS( actualValue, Vector3(testColor), TEST_LOCATION ); DALI_TEST_EQUALS( actualColor.a, testColor.a, TEST_LOCATION ); - Stage::GetCurrent().Remove(actor); + application.GetScene().Remove(actor); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); END_TEST; @@ -258,8 +259,8 @@ int UtcDaliVisualFactoryGetBorderVisual1(void) DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize(200.f, 200.f); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f)); DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); @@ -306,8 +307,8 @@ int UtcDaliVisualFactoryGetBorderVisual2(void) DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize(200.f, 200.f); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f)); DALI_TEST_CHECK( actor.GetRendererCount() == 1u ); @@ -339,7 +340,7 @@ int UtcDaliVisualFactoryGetBorderVisual2(void) visual = factory.CreateVisual( map ); dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add( actor ); blendMode = actor.GetRendererAt(0u).GetProperty( Renderer::Property::BLEND_MODE ); DALI_TEST_EQUALS( static_cast(blendMode), BlendMode::ON, TEST_LOCATION ); @@ -458,7 +459,7 @@ int UtcDaliVisualFactoryDefaultOffsetsGradientVisual(void) DummyControl actor = DummyControl::New(true); TestVisualRender( application, actor, visual ); - Stage::GetCurrent().Remove( actor ); + application.GetScene().Remove( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); END_TEST; @@ -770,9 +771,6 @@ int UtcDaliVisualFactoryGetNPatchVisual3(void) DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION ); - Stage::GetCurrent().Remove( actor ); - DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); - Vector2 naturalSize( 0.0f, 0.0f ); visual.GetNaturalSize( naturalSize ); DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); @@ -796,7 +794,7 @@ int UtcDaliVisualFactoryGetNPatchVisual3(void) visual.GetNaturalSize( naturalSize ); DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); - Stage::GetCurrent().Remove( actor ); + application.GetScene().Remove( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); } @@ -831,18 +829,6 @@ int UtcDaliVisualFactoryGetNPatchVisual4(void) textureTrace.Reset(); - ResourceImage image = ResourceImage::New( TEST_9_PATCH_FILE_NAME ); - Visual::Base nPatchVisual = factory.CreateVisual( image ); - - DummyControl actor1 = DummyControl::New(true); - TestVisualRender( application, actor1, nPatchVisual ); - - DALI_TEST_EQUALS( textureTrace.CountMethod("BindTexture"), 0, TEST_LOCATION ); // The same texture should be used with the first visual. - - naturalSize = Vector2( 0.0f, 0.0f ); - nPatchVisual.GetNaturalSize( naturalSize ); - DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); - END_TEST; } @@ -908,7 +894,7 @@ int UtcDaliVisualFactoryGetNPatchVisual6(void) visual.GetNaturalSize( naturalSize ); DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); - Stage::GetCurrent().Remove( actor ); + application.GetScene().Remove( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); } @@ -936,7 +922,7 @@ int UtcDaliVisualFactoryGetNPatchVisual6(void) visual.GetNaturalSize( naturalSize ); DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth() - 2.0f, imageSize.GetHeight() - 2.0f ), TEST_LOCATION ); - Stage::GetCurrent().Remove( actor ); + application.GetScene().Remove( actor ); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); } @@ -975,10 +961,10 @@ int UtcDaliVisualFactoryGetNPatchVisual7(void) DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add( actor ); actor.Unparent(); application.SendNotification(); @@ -995,7 +981,80 @@ int UtcDaliVisualFactoryGetNPatchVisual7(void) END_TEST; } -int UtcDaliNPatchVisualAuxiliaryImage(void) +int UtcDaliVisualFactoryGetNPatchVisual8(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliVisualFactoryGetNPatchVisual8: Add 9-patch visual on stage, instantly remove it and add new 9-patch visual with same propertyMap" ); + + VisualFactory factory = VisualFactory::Get(); + DALI_TEST_CHECK( factory ); + + // Get actual size of test image + ImageDimensions imageSize = Dali::GetClosestImageSize( TEST_9_PATCH_FILE_NAME ); + + Property::Map propertyMap; + propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::N_PATCH ); + propertyMap.Insert( ImageVisual::Property::URL, TEST_9_PATCH_FILE_NAME ); + propertyMap.Insert( ImageVisual::Property::SYNCHRONOUS_LOADING, false ); + { + Visual::Base visual = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + Vector2 naturalSize( 0.0f, 0.0f ); + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth(), imageSize.GetHeight() ), TEST_LOCATION ); + + TestGlAbstraction& gl = application.GetGlAbstraction(); + TraceCallStack& textureTrace = gl.GetTextureTrace(); + textureTrace.Enable(true); + + DummyControl actor = DummyControl::New(true); + + DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); + dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + + application.GetScene().Add( actor ); + actor.Unparent(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + visual = factory.CreateVisual( propertyMap ); + DALI_TEST_CHECK( visual ); + + visual.GetNaturalSize( naturalSize ); + DALI_TEST_EQUALS( naturalSize, Vector2( imageSize.GetWidth(), imageSize.GetHeight() ), TEST_LOCATION ); + + actor = DummyControl::New(true); + + DummyControlImpl& dummyImpl2 = static_cast(actor.GetImplementation()); + dummyImpl2.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); + + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION ); + + application.GetScene().Add( actor ); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger(1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + Renderer renderer = actor.GetRendererAt( 0 ); + auto textures = renderer.GetTextures(); + + DALI_TEST_EQUALS( textures.GetTextureCount(), 1, TEST_LOCATION ); + } + + END_TEST; +} + +int UtcDaliNPatchVisualAuxiliaryImage01(void) { ToolkitTestApplication application; tet_infoline( "NPatchVisual with aux image" ); @@ -1027,8 +1086,8 @@ int UtcDaliNPatchVisualAuxiliaryImage(void) dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); dummyImpl.SetLayout( DummyControl::Property::TEST_VISUAL, transformMap ); dummy.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS ); - dummy.SetParentOrigin(ParentOrigin::CENTER); - Stage::GetCurrent().Add(dummy); + dummy.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::CENTER); + application.GetScene().Add(dummy); application.SendNotification(); application.Render(); @@ -1045,6 +1104,38 @@ int UtcDaliNPatchVisualAuxiliaryImage(void) END_TEST; } +int UtcDaliNPatchVisualAuxiliaryImage02(void) +{ + ToolkitTestApplication application; + tet_infoline( "Multiple NPatchVisual with aux image coincidentally" ); + + const Property::Value NPATCH_TEST{ + {ImageVisual::Property::URL, TEST_9_PATCH_FILE_NAME}, + {DevelImageVisual::Property::AUXILIARY_IMAGE, TEST_AUX_IMAGE}}; + + ImageView imageView1 = ImageView::New(); + imageView1[ImageView::Property::IMAGE] = NPATCH_TEST; + application.GetScene().Add( imageView1 ); + + ImageView imageView2 = ImageView::New(); + imageView2[ImageView::Property::IMAGE] = NPATCH_TEST; + application.GetScene().Add( imageView2 ); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + Renderer renderer1 = imageView1.GetRendererAt( 0 ); + auto textureSet1 = renderer1.GetTextures(); + + Renderer renderer2 = imageView2.GetRendererAt( 0 ); + auto textureSet2 = renderer2.GetTextures(); + DALI_TEST_EQUALS( textureSet1 != textureSet2, true, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliVisualFactoryGetNPatchVisualN1(void) { @@ -1138,16 +1229,13 @@ int UtcDaliVisualFactoryGetSvgVisual(void) DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) ); + // Either application.SendNotification() or the trigger can now complete the task. application.SendNotification(); application.Render(); - - // renderer is not added to actor until the rasterization is completed. - DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); // renderer is added to actor @@ -1179,14 +1267,11 @@ int UtcDaliVisualFactoryGetSvgVisualLarge(void) DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); actor.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS ); // Only rasterizes when it knows control size. dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - Stage::GetCurrent().Add( actor ); + application.GetScene().Add( actor ); + // Either application.SendNotification() or the trigger can now complete the task. application.SendNotification(); application.Render(); - - // renderer is not added to actor until the rasterization is completed. - DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); // renderer is added to actor @@ -1223,16 +1308,14 @@ int UtcDaliVisualFactoryGetSvgVisualAtlas(void) DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); visual.SetTransformAndSize(DefaultTransform(), Vector2(200.f, 200.f) ); + // Either application.SendNotification() or the trigger can now complete the task. + DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); application.SendNotification(); application.Render(); - - // renderer is not added to actor until the rasterization is completed. - DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); - DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); // renderer is added to actor @@ -1262,8 +1345,8 @@ void MeshVisualLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplic DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) ); //Ensure set on stage. @@ -1305,8 +1388,8 @@ void MeshVisualDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTest DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) ); //Ensure set on stage. @@ -1612,8 +1695,8 @@ void TestPrimitiveVisualWithProperties( Property::Map& propertyMap, ToolkitTestA DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.f, 200.f ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); visual.SetTransformAndSize(DefaultTransform(), Vector2( 200.f, 200.f ) ); //Ensure set on stage. @@ -1717,7 +1800,7 @@ int UtcDaliVisualFactoryGetPrimitiveVisual4(void) //Set up visual properties. Property::Map propertyMap; propertyMap.Insert( Toolkit::Visual::Property::TYPE, Visual::PRIMITIVE ); - propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTRUM ); + propertyMap.Insert( PrimitiveVisual::Property::SHAPE, PrimitiveVisual::Shape::CONICAL_FRUSTUM ); propertyMap.Insert( PrimitiveVisual::Property::MIX_COLOR, Vector4( 0.5, 0.5, 0.5, 1.0 ) ); propertyMap.Insert( PrimitiveVisual::Property::SLICES, 10 ); propertyMap.Insert( PrimitiveVisual::Property::SCALE_TOP_RADIUS, 30.0f ); @@ -2053,8 +2136,13 @@ int UtcDaliVisualFactoryGetAnimatedImageVisual1(void) DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visual ); - actor.SetSize( 200.0f, 200.0f ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION ); application.SendNotification(); application.Render(); @@ -2072,14 +2160,23 @@ int UtcDaliVisualFactoryGetAnimatedImageVisual1(void) timer.MockEmitSignal(); application.SendNotification(); application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); textureTrace.Reset(); - // Force the timer used by the animatedImageVisual to tick, timer.MockEmitSignal(); application.SendNotification(); application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); textureTrace.Reset(); @@ -2087,10 +2184,15 @@ int UtcDaliVisualFactoryGetAnimatedImageVisual1(void) timer.MockEmitSignal(); application.SendNotification(); application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 1 ), true, TEST_LOCATION ); + + application.SendNotification(); + application.Render(); DALI_TEST_EQUALS( textureTrace.FindMethod("GenTextures"), true, TEST_LOCATION ); textureTrace.Reset(); - // Test SetOffStage(). + // Test SetOffScene(). actor.Unparent(); DALI_TEST_CHECK( actor.GetRendererCount() == 0u ); @@ -2122,8 +2224,13 @@ int UtcDaliVisualFactoryGetAnimatedImageVisual2(void) DummyControl actor = DummyControl::New(true); DummyControlImpl& dummyImpl = static_cast(actor.GetImplementation()); dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual ); - actor.SetSize( 200.0f, 200.0f ); - Stage::GetCurrent().Add( actor ); + actor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 200.f ) ); + application.GetScene().Add( actor ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( Test::WaitForEventThreadTrigger( 2 ), true, TEST_LOCATION ); application.SendNotification(); application.Render();