Fix randomly failed UTC (2)
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
index 6fb05ab..2f2901f 100644 (file)
@@ -576,16 +576,8 @@ int UtcDaliImageViewAsyncLoadingWithAtlasing(void)
   // loading is not started if the actor is offScene
 
   application.GetScene().Add(imageView);
-  application.SendNotification();
-  application.Render(16);
-  application.Render(16);
-  application.SendNotification();
 
   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
-  application.SendNotification();
-  application.Render(16);
-  application.Render(16);
-  application.SendNotification();
 
   // loading started, this waits for the loader thread for max 30 seconds
   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
@@ -623,10 +615,6 @@ int UtcDaliImageViewAsyncLoadingWithAtlasing02(void)
   imageView.SetProperty(ImageView::Property::IMAGE, asyncLoadingMap);
 
   application.GetScene().Add(imageView);
-  application.SendNotification();
-  application.Render(16);
-  application.Render(16);
-  application.SendNotification();
 
   // loading started, this waits for the loader thread for max 30 seconds
   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
@@ -831,10 +819,6 @@ int UtcDaliImageViewAsyncLoadingEncodedBufferWithAtlasing(void)
   imageView.SetProperty(ImageView::Property::IMAGE, imageMap);
 
   imageView.SetProperty(Dali::Actor::Property::LAYOUT_DIRECTION, Dali::LayoutDirection::RIGHT_TO_LEFT);
-  application.SendNotification();
-  application.Render(16);
-  application.Render(16);
-  application.SendNotification();
 
   // loading started, this waits for the loader thread for max 30 seconds
   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
@@ -1054,6 +1038,23 @@ void ResourceReadySignal(Control control)
   gResourceReadySignalFired = true;
 }
 
+void OnResourceReadySignalSVG(Control control)
+{
+  // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
+  Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(control);
+  Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
+  Property::Map               resultMap;
+  imageVisual.CreatePropertyMap(resultMap);
+
+  Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
+  DALI_TEST_CHECK(transformValue);
+  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>(), Vector2::ZERO, TEST_LOCATION);
+}
+
 int UtcDaliImageViewCheckResourceReady(void)
 {
   ToolkitTestApplication application;
@@ -2816,6 +2817,51 @@ int UtcDaliImageViewSyncSVGLoading(void)
   END_TEST;
 }
 
+int UtcDaliImageViewSyncSVGLoading02(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline("ImageView Testing SVG image sync loading");
+
+  {
+    ImageView imageView = ImageView::New();
+
+    // Sync loading is used
+    Property::Map syncLoadingMap;
+    syncLoadingMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
+    syncLoadingMap.Insert(Toolkit::ImageVisual::Property::URL, TEST_RESOURCE_DIR "/svg1.svg");
+    syncLoadingMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
+    syncLoadingMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FIT_KEEP_ASPECT_RATIO);
+    imageView.SetProperty(ImageView::Property::IMAGE, syncLoadingMap);
+    imageView.ResourceReadySignal().Connect(&OnResourceReadySignalSVG);
+
+    application.GetScene().Add(imageView);
+    DALI_TEST_CHECK(imageView);
+
+    application.SendNotification();
+    application.Render();
+
+    // Check whether Image Visual transforms on ImageVieiw::OnRelayout()
+    Toolkit::Internal::Control& controlImpl = Toolkit::Internal::GetImplementation(imageView);
+    Toolkit::Visual::Base       imageVisual = DevelControl::GetVisual(controlImpl, ImageView::Property::IMAGE);
+    Property::Map               resultMap;
+    imageVisual.CreatePropertyMap(resultMap);
+
+    Property::Value* transformValue = resultMap.Find(Visual::Property::TRANSFORM);
+    DALI_TEST_CHECK(transformValue);
+    Property::Map* retMap = transformValue->GetMap();
+    DALI_TEST_CHECK(retMap);
+
+    // Image Visual should be positioned depending on ImageView's padding
+    DALI_TEST_EQUALS(retMap->Find(Visual::Transform::Property::SIZE)->Get<Vector2>(), Vector2(100, 100), TEST_LOCATION);
+
+    Vector3 naturalSize = imageView.GetNaturalSize();
+    DALI_TEST_EQUALS(naturalSize.width, 100.0f, TEST_LOCATION);
+    DALI_TEST_EQUALS(naturalSize.height, 100.0f, TEST_LOCATION);
+  }
+  END_TEST;
+}
+
 int UtcDaliImageViewAsyncSVGLoading(void)
 {
   ToolkitTestApplication application;
@@ -3712,6 +3758,20 @@ void OnResourceReadySignal09(Control control)
     gImageView2.Reset();
   }
 }
+constexpr int gResourceReadySignal10MaxCounter = 5;
+
+void OnResourceReadySignal10(Control control)
+{
+  gResourceReadySignalCounter++;
+
+  tet_printf("OnResourceReadySignal10 comes!\n");
+  if(gResourceReadySignalCounter < gResourceReadySignal10MaxCounter)
+  {
+    tet_printf("OnResourceReadySignal10 Set image\n");
+    gImageView1.SetProperty(Toolkit::ImageView::Property::IMAGE, gImage_34_RGBA);
+    tet_printf("OnResourceReadySignal10 Set image done\n");
+  }
+}
 
 } // namespace
 
@@ -4482,6 +4542,81 @@ int UtcDaliImageViewSetImageOnResourceReadySignal09(void)
   END_TEST;
 }
 
+int UtcDaliImageViewSetImageOnResourceReadySignal10(void)
+{
+  tet_infoline("Test ResourceReady signal comes more than 2 times.");
+
+  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();
+
+  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_EQUALS(gResourceReadySignalCounter, gResourceReadySignal10MaxCounter, TEST_LOCATION);
+
+    DALI_TEST_CHECK(true);
+  }
+  catch(...)
+  {
+    // Exception should not happened
+    DALI_TEST_CHECK(false);
+  }
+
+  // Clear cache.
+  application.SendNotification();
+  application.Render();
+
+  gResourceReadySignalCounter = 0;
+
+  gResourceReadySignalCounter = 0;
+
+  // Clear image view for clear test
+
+  if(gImageView1)
+  {
+    gImageView1.Reset();
+  }
+
+  END_TEST;
+}
+
 int UtcDaliImageViewUseSameUrlWithAnimatedImageVisual(void)
 {
   tet_infoline("Test multiple views with same image in animated image visual");