X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-ImageView.cpp;h=3ca8543ef8d275303dc033c19adf5740cbb109cb;hb=HEAD;hp=7448eba3f88766ea4b3095e239540a59cb505f2a;hpb=aeacc55f3d6c3acbe5a8bcb95f6c45d26e8300a1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp index 7448eba..ea8a7ca 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,6 +85,8 @@ const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg" const char* TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insta_camera.json"; const char* TEST_WEBP_FILE_NAME = TEST_RESOURCE_DIR "/dali-logo.webp"; +const char* TEST_OVERWRITABLE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/overwritable-image.jpg"; + void TestUrl(ImageView imageView, const std::string url) { Property::Value value = imageView.GetProperty(imageView.GetPropertyIndex("image")); @@ -94,6 +96,38 @@ void TestUrl(ImageView imageView, const std::string url) DALI_TEST_EQUALS(urlActual, url, TEST_LOCATION); } +void OverwriteImage(const char* sourceFilename) +{ + FILE* fpOut = fopen(TEST_OVERWRITABLE_IMAGE_FILE_NAME, "wb"); + DALI_TEST_CHECK(fpOut); + if(fpOut) + { + FILE* fpIn = fopen(sourceFilename, "rb"); + if(fpIn) + { + fseek(fpIn, 0, SEEK_END); + size_t size = ftell(fpIn); + + tet_printf("Open %s success! file size : %zu byte\n", sourceFilename, size); + Dali::Vector data; + data.Resize(size); + fseek(fpIn, 0, SEEK_SET); + size_t realSize = fread(data.Begin(), sizeof(uint8_t), size, fpIn); + fclose(fpIn); + data.Resize(realSize); + + // Overwrite + fwrite(data.Begin(), sizeof(uint8_t), size, fpOut); + } + else + { + tet_printf("Open %s failed! write invalid\n", sourceFilename); + fprintf(fpOut, "invalid\n"); + } + fclose(fpOut); + } +} + } // namespace int UtcDaliImageViewNewP(void) @@ -879,6 +913,126 @@ int UtcDaliImageViewSyncLoadingEncodedBuffer(void) END_TEST; } +int UtcDaliImageViewEncodedBufferWithSvg(void) +{ + ToolkitTestApplication application; + TestGlAbstraction& gl = application.GetGlAbstraction(); + const std::vector& textures = gl.GetBoundTextures(); + size_t numTextures = textures.size(); + + // Get encoded raw-buffer svg image and generate url + EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(TEST_SVG_FILE_NAME, EncodedImageBuffer::ImageType::VECTOR_IMAGE); + ImageUrl url = Toolkit::Image::GenerateUrl(buffer); + + // Async loading, no atlasing for big size image + ImageView imageView = ImageView::New(url.GetUrl()); + + // By default, Aysnc loading is used + application.GetScene().Add(imageView); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100)); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + + application.SendNotification(); + application.Render(16); + + // Load svg image + rasterize. + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + application.SendNotification(); + + const std::vector& textures2 = gl.GetBoundTextures(); + DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION); + + // Remove visual, for line coverage. + imageView.Unparent(); + application.SendNotification(); + application.Render(16); + + END_TEST; +} + +int UtcDaliImageViewEncodedBufferWithAnimatedVectorImage(void) +{ + ToolkitTestApplication application; + TestGlAbstraction& gl = application.GetGlAbstraction(); + const std::vector& textures = gl.GetBoundTextures(); + size_t numTextures = textures.size(); + + // Get encoded raw-buffer lottie image and generate url + EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(TEST_ANIMATED_VECTOR_IMAGE_FILE_NAME, EncodedImageBuffer::ImageType::ANIMATED_VECTOR_IMAGE); + ImageUrl url = Toolkit::Image::GenerateUrl(buffer); + + // Async loading, no atlasing for big size image + ImageView imageView = ImageView::New(url.GetUrl()); + + // By default, Aysnc loading is used + application.GetScene().Add(imageView); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100)); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + + application.SendNotification(); + application.Render(16); + + // Load lottie image is sync. Only wait rasterize. + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + application.SendNotification(); + + const std::vector& textures2 = gl.GetBoundTextures(); + DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION); + + // Remove visual, for line coverage. + imageView.Unparent(); + application.SendNotification(); + application.Render(16); + + END_TEST; +} + +int UtcDaliImageViewEncodedBufferWithInvalidImageType(void) +{ + ToolkitTestApplication application; + TestGlAbstraction& gl = application.GetGlAbstraction(); + const std::vector& textures = gl.GetBoundTextures(); + size_t numTextures = textures.size(); + + // Get encoded raw-buffer jpg image with invalid image type, and generate url + EncodedImageBuffer buffer = ConvertFileToEncodedImageBuffer(gImage_34_RGBA, static_cast(-1)); + ImageUrl url = Toolkit::Image::GenerateUrl(buffer); + + // Async loading, no atlasing for big size image + ImageView imageView = ImageView::New(url.GetUrl()); + + // By default, Aysnc loading is used + application.GetScene().Add(imageView); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100, 100)); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + + application.SendNotification(); + application.Render(16); + + // Load image + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + application.SendNotification(); + application.Render(16); + application.SendNotification(); + + const std::vector& textures2 = gl.GetBoundTextures(); + DALI_TEST_GREATER(textures2.size(), numTextures, TEST_LOCATION); + + // Remove visual, for line coverage. + imageView.Unparent(); + application.SendNotification(); + application.Render(16); + + END_TEST; +} + int UtcDaliImageViewAddedTexture(void) { ToolkitTestApplication application; @@ -1040,7 +1194,7 @@ void ResourceReadySignal(Control control) void OnResourceReadySignalSVG(Control control) { - // Check whether Image Visual transforms on ImageVieiw::OnRelayout() + // Check whether Image Visual transforms on ImageView::OnRelayout() Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(control); Toolkit::Visual::Base imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE); Property::Map resultMap; @@ -1051,8 +1205,8 @@ void OnResourceReadySignalSVG(Control control) Property::Map* retMap = transformValue->GetMap(); DALI_TEST_CHECK(retMap); - // Fitting mode should not be applied at this point - DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get(), Vector2::ZERO, TEST_LOCATION); + // Fitting mode is applied at this point. because we do FittingMode in control + DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get(), Vector2::ONE, TEST_LOCATION); } int UtcDaliImageViewCheckResourceReady(void) @@ -2066,6 +2220,10 @@ int UtcDaliImageViewFittingModesFitHeight01(void) DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), Vector2(0, 0), TEST_LOCATION); // OFFSET is zero + value = returnedMap.Find(DevelVisual::Property::VISUAL_FITTING_MODE); + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), "FIT_HEIGHT", TEST_LOCATION); // OFFSET is zero + END_TEST; } @@ -2156,6 +2314,10 @@ int UtcDaliImageViewFittingModesFitWidth01(void) DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), Vector2(0, 50), TEST_LOCATION); + value = returnedMap.Find(DevelVisual::Property::VISUAL_FITTING_MODE); + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), "FIT_WIDTH", TEST_LOCATION); // OFFSET is zero + END_TEST; } @@ -2734,10 +2896,12 @@ int UtcDaliImageViewLoadRemoteSVG(void) ToolkitTestApplication application; + const std::string svgImageUrl("https://dalihub.github.io/images/check.svg"); + { Toolkit::ImageView imageView; imageView = Toolkit::ImageView::New(); - imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg"); + imageView.SetImage(svgImageUrl); imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300)); @@ -2764,7 +2928,7 @@ int UtcDaliImageViewLoadRemoteSVG(void) { Toolkit::ImageView imageView; imageView = Toolkit::ImageView::New(); - imageView.SetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/check.svg"); + imageView.SetImage(svgImageUrl); imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f)); @@ -2789,6 +2953,34 @@ int UtcDaliImageViewLoadRemoteSVG(void) END_TEST; } +int UtcDaliImageViewLoadRemoteLottie(void) +{ + tet_infoline("Test load from a remote server. (Note we don't support real download now. Just for line coverage)"); + + ToolkitTestApplication application; + + { + Toolkit::ImageView imageView; + imageView = Toolkit::ImageView::New(); + imageView.SetImage("https://lottie.json"); + imageView.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + imageView.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + imageView.SetProperty(Actor::Property::SIZE, Vector2(300, 300)); + imageView.SetProperty(Actor::Property::POSITION, Vector3(150.0f, 150.0f, 0.0f)); + + application.GetScene().Add(imageView); + + DALI_TEST_CHECK(imageView); + + application.SendNotification(); + application.Render(); + + // Do not check anything for here. + } + + END_TEST; +} + int UtcDaliImageViewSyncSVGLoading(void) { ToolkitTestApplication application; @@ -4281,7 +4473,13 @@ int UtcDaliImageViewSetImageOnResourceReadySignal06(void) DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); DALI_TEST_EQUALS(gResourceReadySignalCounter, 2, TEST_LOCATION); - tet_infoline("load done"); + tet_infoline("Note that resource ready should not come now."); + tet_infoline("Try to load remained 2 valid image + apply masking"); + + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(4), true, TEST_LOCATION); + DALI_TEST_EQUALS(gResourceReadySignalCounter, 4, TEST_LOCATION); + + tet_infoline("Check all resource ready comes now."); } END_TEST; } @@ -4645,6 +4843,86 @@ int UtcDaliImageViewSetImageOnResourceReadySignal10(void) END_TEST; } +int UtcDaliImageViewSetImageOnResourceReadySignal10WhenAddIdleFailed(void) +{ + tet_infoline("Test ResourceReady signal comes more than 2 times, but do not call again if AddIdle failed"); + + ToolkitTestApplication application; + + gResourceReadySignalCounter = 0; + + // Clear image view for clear test + + if(gImageView1) + { + gImageView1.Reset(); + } + + // Dummy view to cache image. + ImageView dummyView = ImageView::New(gImage_34_RGBA); + application.GetScene().Add(dummyView); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + // Make AddIdle failed. + ToolkitApplication::ADD_IDLE_SUCCESS = false; + + try + { + gImageView1 = ImageView::New(); + gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, gImage_34_RGBA); + gImageView1.ResourceReadySignal().Connect(&OnResourceReadySignal10); + application.GetScene().Add(gImageView1); // It will call resourceReady signal 1 time. + + tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter); + + DALI_TEST_GREATER(gResourceReadySignal10MaxCounter, gResourceReadySignalCounter, TEST_LOCATION); // Check whether resource ready call too much. + + for(int i = 0; i < gResourceReadySignal10MaxCounter; ++i) + { + tet_printf("RunIdles\n"); + // Executes the idle callbacks. + application.RunIdles(); + application.SendNotification(); + application.Render(); + tet_printf("RunIdles done\n"); + } + tet_printf("ResourceReady called %d times\n", gResourceReadySignalCounter); + + DALI_TEST_GREATER(gResourceReadySignal10MaxCounter, gResourceReadySignalCounter, TEST_LOCATION); // Check whether resource ready not called multiple times. + + DALI_TEST_CHECK(true); + } + catch(...) + { + // Exception should not happened + DALI_TEST_CHECK(false); + } + + ToolkitApplication::ADD_IDLE_SUCCESS = true; + + // Clear cache. + application.SendNotification(); + application.Render(); + + gResourceReadySignalCounter = 0; + + gResourceReadySignalCounter = 0; + + // Clear image view for clear test + + if(gImageView1) + { + gImageView1.Reset(); + } + + END_TEST; +} + int UtcDaliImageViewSetImageOnResourceReadySignal11(void) { tet_infoline("Test ResourceReady Add AnimatedImageVisual and then Remove immediately."); @@ -5241,3 +5519,308 @@ int UtcDaliImageViewTransitionEffect03(void) END_TEST; } + +int UtcDaliImageViewTransitionEffect04(void) +{ + tet_infoline("Test transitoin effect operation when image is changed quickly "); + + ToolkitTestApplication application; + Property::Map map; + + ImageView imageView = ImageView::New(); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f)); + imageView.SetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT, true); + imageView.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA); + imageView.SetImage(""); + application.GetScene().Add(imageView); + + ImageView imageView2 = ImageView::New(); + imageView2.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f)); + imageView2.SetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT, true); + imageView2.SetProperty(Toolkit::ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA); + imageView2.SetImage(""); + application.GetScene().Add(imageView2); + application.SendNotification(); + application.Render(); + + //PLACEHOLDER_IMAGE is not call WaitForEventThreadTrigger because it is not shown url is null. + //DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION); + + imageView.SetImage(gImage_600_RGB); + imageView.SetProperty(ImageView::Property::PLACEHOLDER_IMAGE, gImage_34_RGBA); + imageView2.SetImage(TEST_IMAGE_1); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION); + + imageView.SetImage(TEST_IMAGE_1); + imageView2.SetImage(gImage_600_RGB); + application.SendNotification(); + application.Render(3000); + + imageView.SetImage(""); + application.SendNotification(); + application.Render(); + + imageView.SetImage(TEST_IMAGE_2); + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + Property::Value value; + value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT); + bool transition; + DALI_TEST_CHECK(value.Get(transition)); + DALI_TEST_CHECK(transition == true); + + // Clear all cached + imageView.Unparent(); + imageView.Reset(); + + END_TEST; +} + +int UtcDaliImageViewTransitionEffect05(void) +{ + tet_printf("Testing user's transition effect in ImageView \n"); + ToolkitTestApplication application; + + Property::Map map; + map["target"] = "image"; + map["property"] = "opacity"; + map["initialValue"] = 0.2f; + map["targetValue"] = 1.0f; + map["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT") + .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 2.0f)) + .Add("animationType", "BETWEEN"); + + ImageView imageView = ImageView::New(); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f)); + imageView.SetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT, true); + imageView.SetProperty(ImageView::Property::TRANSITION_EFFECT_OPTION, map); + imageView.SetImage(gImage_600_RGB); + application.GetScene().Add(imageView); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + Property::Value value; + value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT); + bool transition; + DALI_TEST_CHECK(value.Get(transition)); + DALI_TEST_CHECK(transition == true); + + // Clear all cached + imageView.Unparent(); + imageView.Reset(); + + END_TEST; +} + +int UtcDaliImageViewTransitionEffect06(void) +{ + tet_printf("Testing user's transition effect in ImageView \n"); + ToolkitTestApplication application; + + Property::Map map; + map["target"] = "image"; + map["property"] = "opacity"; + map["initialValue"] = 0.2f; + map["targetValue"] = 1.0f; + map["animator"] = Property::Map() + .Add("alphaFunction", "EASE_IN_OUT") + .Add("timePeriod", Property::Map().Add("delay", 0.0f).Add("duration", 2.0f)) + .Add("animationType", "TO"); + + ImageView imageView = ImageView::New(); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 200.0f)); + imageView.SetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT, true); + imageView.SetProperty(ImageView::Property::TRANSITION_EFFECT_OPTION, map); + imageView.SetImage(gImage_600_RGB); + application.GetScene().Add(imageView); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + Property::Value value; + value = imageView.GetProperty(ImageView::Property::ENABLE_TRANSITION_EFFECT); + bool transition; + DALI_TEST_CHECK(value.Get(transition)); + DALI_TEST_CHECK(transition == true); + + // Clear all cached + imageView.Unparent(); + imageView.Reset(); + + END_TEST; +} + + + +int UtcDaliImageViewImageLoadFailureAndReload01(void) +{ + tet_infoline("Try to load invalid image first, and then reload after that image valid."); + ToolkitTestApplication application; + + gResourceReadySignalFired = false; + + // Make overwritable image invalid first. + OverwriteImage(""); + + ImageView imageView = ImageView::New(TEST_OVERWRITABLE_IMAGE_FILE_NAME); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f)); + imageView.ResourceReadySignal().Connect(&ResourceReadySignal); + + application.GetScene().Add(imageView); + application.SendNotification(); + application.Render(16); + + // loading started, this waits for the loader thread + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION); + + gResourceReadySignalFired = false; + + // Make overwritable image valid now. + OverwriteImage(gImage_34_RGBA); + + // Reload the image + Property::Map attributes; + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes); + application.SendNotification(); + application.Render(16); + + // loading started, this waits for the loader thread + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::READY, TEST_LOCATION); + + // Make overwritable image invalid end of test (for clean). + OverwriteImage(""); + + gResourceReadySignalFired = false; + + END_TEST; +} + +int UtcDaliImageViewImageLoadFailureAndReload02(void) +{ + tet_infoline("Try to load invalid image first, and then reload after that image valid."); + tet_infoline("This case, broken image was n-patch. So we should check whether Geometry / Shader changed after reload"); + ToolkitTestApplication application; + + Toolkit::StyleManager styleManager = Toolkit::StyleManager::Get(); + DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::SMALL, TEST_BROKEN_IMAGE_S); + DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::NORMAL, TEST_BROKEN_IMAGE_M); + DevelStyleManager::SetBrokenImageUrl(styleManager, DevelStyleManager::BrokenImageType::LARGE, TEST_BROKEN_IMAGE_L); + + gResourceReadySignalFired = false; + + // Make overwritable image invalid first. + OverwriteImage(""); + + ImageView imageView = ImageView::New(TEST_OVERWRITABLE_IMAGE_FILE_NAME); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f)); + imageView.ResourceReadySignal().Connect(&ResourceReadySignal); + + application.GetScene().Add(imageView); + application.SendNotification(); + application.Render(16); + + // loading started, this waits for the loader thread + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::FAILED, TEST_LOCATION); + + DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION); + Geometry brokenGeometry = imageView.GetRendererAt(0u).GetGeometry(); + Shader brokenShader = imageView.GetRendererAt(0u).GetShader(); + DALI_TEST_CHECK(brokenGeometry); + DALI_TEST_CHECK(brokenShader); + + gResourceReadySignalFired = false; + + // Make overwritable image valid now. + OverwriteImage(gImage_34_RGBA); + + // Reload the image + Property::Map attributes; + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes); + application.SendNotification(); + application.Render(16); + + // loading started, this waits for the loader thread + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::READY, TEST_LOCATION); + + // Check whether we don't use n-patch shader and geometry in this case. + DALI_TEST_EQUALS(imageView.GetRendererCount(), 1u, TEST_LOCATION); + DALI_TEST_CHECK(brokenGeometry != imageView.GetRendererAt(0u).GetGeometry()); + DALI_TEST_CHECK(brokenShader != imageView.GetRendererAt(0u).GetShader()); + + // Make overwritable image invalid end of test (for clean). + OverwriteImage(""); + + gResourceReadySignalFired = false; + + END_TEST; +} + +int UtcDaliImageViewImageLoadSuccessAndReload01(void) +{ + tet_infoline("Try to load valid image first, and then reload again. Check whether ResourceReady signal comes well"); + ToolkitTestApplication application; + + gResourceReadySignalFired = false; + + ImageView imageView = ImageView::New(gImage_34_RGBA); + imageView.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f)); + imageView.ResourceReadySignal().Connect(&ResourceReadySignal); + + application.GetScene().Add(imageView); + application.SendNotification(); + application.Render(16); + + // loading started, this waits for the loader thread + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::READY, TEST_LOCATION); + + gResourceReadySignalFired = false; + + // Reload the image + Property::Map attributes; + DevelControl::DoAction(imageView, ImageView::Property::IMAGE, DevelImageVisual::Action::RELOAD, attributes); + application.SendNotification(); + application.Render(16); + + DALI_TEST_EQUALS(gResourceReadySignalFired, false, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.IsResourceReady(), false, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::PREPARING, TEST_LOCATION); + + // loading started, this waits for the loader thread + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + + DALI_TEST_EQUALS(gResourceReadySignalFired, true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.IsResourceReady(), true, TEST_LOCATION); + DALI_TEST_EQUALS(imageView.GetVisualResourceStatus(ImageView::Property::IMAGE), Visual::ResourceStatus::READY, TEST_LOCATION); + + gResourceReadySignalFired = false; + + END_TEST; +} \ No newline at end of file