[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Visual.cpp
index 30b0e1e..bb955c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 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.
@@ -141,7 +141,6 @@ bool DaliTestCheckMaps(const Property::Map& fontStyleMapGet, const Property::Map
 
   return true;
 }
-
 void TestShaderCodeContainSubstrings(Control control, std::vector<std::pair<std::string, bool>> substringCheckList, const char* location)
 {
   Renderer        renderer = control.GetRendererAt(0);
@@ -150,6 +149,17 @@ void TestShaderCodeContainSubstrings(Control control, std::vector<std::pair<std:
   Property::Map*  map      = value.GetMap();
   DALI_TEST_CHECK(map);
 
+  Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
+  std::string      vertexShader;
+  DALI_TEST_CHECK(vertex->Get(vertexShader));
+  for(const auto& checkPair : substringCheckList)
+  {
+    const auto& keyword = checkPair.first;
+    const auto& expect  = checkPair.second;
+    tet_printf("check [%s] %s exist in vertex shader\n", keyword.c_str(), expect ? "is" : "is not");
+    DALI_TEST_EQUALS((vertexShader.find(keyword.c_str()) != std::string::npos), expect, location);
+  }
+
   Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
   DALI_TEST_CHECK(fragment);
   std::string fragmentShader;
@@ -161,6 +171,15 @@ void TestShaderCodeContainSubstrings(Control control, std::vector<std::pair<std:
     tet_printf("check [%s] %s exist in fragment shader\n", keyword.c_str(), expect ? "is" : "is not");
     DALI_TEST_EQUALS((fragmentShader.find(keyword.c_str()) != std::string::npos), expect, location);
   }
+}
+
+void TestShaderCodeContainSubstringsForEachShader(Control control, std::vector<std::pair<std::string, std::pair<bool, bool>>> substringCheckList, const char* location)
+{
+  Renderer        renderer = control.GetRendererAt(0);
+  Shader          shader   = renderer.GetShader();
+  Property::Value value    = shader.GetProperty(Shader::Property::PROGRAM);
+  Property::Map*  map      = value.GetMap();
+  DALI_TEST_CHECK(map);
 
   Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp
   std::string      vertexShader;
@@ -168,10 +187,22 @@ void TestShaderCodeContainSubstrings(Control control, std::vector<std::pair<std:
   for(const auto& checkPair : substringCheckList)
   {
     const auto& keyword = checkPair.first;
-    const auto& expect  = checkPair.second;
+    const auto& expect  = checkPair.second.first;
     tet_printf("check [%s] %s exist in vertex shader\n", keyword.c_str(), expect ? "is" : "is not");
     DALI_TEST_EQUALS((vertexShader.find(keyword.c_str()) != std::string::npos), expect, location);
   }
+
+  Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp
+  DALI_TEST_CHECK(fragment);
+  std::string fragmentShader;
+  DALI_TEST_CHECK(fragment->Get(fragmentShader));
+  for(const auto& checkPair : substringCheckList)
+  {
+    const auto& keyword = checkPair.first;
+    const auto& expect  = checkPair.second.second;
+    tet_printf("check [%s] %s exist in fragment shader\n", keyword.c_str(), expect ? "is" : "is not");
+    DALI_TEST_EQUALS((fragmentShader.find(keyword.c_str()) != std::string::npos), expect, location);
+  }
 }
 
 } //namespace
@@ -1259,7 +1290,7 @@ int UtcDaliVisualGetPropertyMap10(void)
   propertyMap.Insert("underline", underlineMapSet.Add("enable", true).Add("color", Color::GREEN).Add("height", 1).Add("type", Text::Underline::Type::SOLID).Add("dashWidth", 2).Add("dashGap", 1));
 
   Property::Map outlineMapSet;
-  propertyMap.Insert("outline", outlineMapSet.Add("color", Color::YELLOW).Add("width", 1));
+  propertyMap.Insert("outline", outlineMapSet.Add("color", Color::YELLOW).Add("width", 1).Add("offset", Vector2(2.0f, 2.0f)));
 
   Property::Map backgroundMapSet;
   propertyMap.Insert("textBackground", backgroundMapSet.Add("enable", true).Add("color", Color::CYAN));
@@ -5250,6 +5281,7 @@ int UtcDaliVisualGetVisualProperty03(void)
 
   static std::vector<UniformData> customUniforms =
     {
+      UniformData("pixelArea", Property::Type::VECTOR4),
       UniformData("cornerRadius", Property::Type::VECTOR4),
       UniformData("borderlineWidth", Property::Type::FLOAT),
       UniformData("borderlineColor", Property::Type::VECTOR4),
@@ -5279,6 +5311,7 @@ int UtcDaliVisualGetVisualProperty03(void)
   application.Render();
 
   float   targetOpacity = 0.5f;
+  Vector4 targetPixelArea(0.0f, 1.0f, 2.0f, -0.5f);
   Vector4 targetCornerRadius(20.0f, 20.0f, 0.0f, 0.0f);
   float   targetBorderlineWidth = 10.0f;
   Vector4 targetBorderlineColor(1.0f, 0.0f, 1.0f, 0.5f);
@@ -5286,6 +5319,7 @@ int UtcDaliVisualGetVisualProperty03(void)
 
   Animation animation = Animation::New(1.0f);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, Visual::Property::OPACITY), targetOpacity);
+  animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, ImageVisual::Property::PIXEL_AREA), targetPixelArea);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::CORNER_RADIUS), targetCornerRadius);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::BORDERLINE_WIDTH), targetBorderlineWidth);
   animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Property::BORDERLINE_COLOR), targetBorderlineColor);
@@ -5304,6 +5338,10 @@ int UtcDaliVisualGetVisualProperty03(void)
   DALI_TEST_CHECK(colorValue);
   DALI_TEST_EQUALS(colorValue->Get<Vector4>(), Vector4(1.0f, 1.0f, 1.0f, targetOpacity), TEST_LOCATION);
 
+  Property::Value* pixelAreaValue = resultMap.Find(ImageVisual::Property::PIXEL_AREA, Property::VECTOR4);
+  DALI_TEST_CHECK(pixelAreaValue);
+  DALI_TEST_EQUALS(pixelAreaValue->Get<Vector4>(), targetPixelArea, TEST_LOCATION);
+
   Property::Value* cornerRadiusValue = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
   DALI_TEST_CHECK(cornerRadiusValue);
   DALI_TEST_EQUALS(cornerRadiusValue->Get<Vector4>(), targetCornerRadius, TEST_LOCATION);
@@ -5321,11 +5359,15 @@ int UtcDaliVisualGetVisualProperty03(void)
   DALI_TEST_EQUALS(borderlineOffsetValue->Get<float>(), targetBorderlineOffset, TEST_LOCATION);
 
   // Test uniform value
+  DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("pixelArea", targetPixelArea), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("cornerRadius", targetCornerRadius), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<float>("borderlineWidth", targetBorderlineWidth), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<Vector4>("borderlineColor", targetBorderlineColor), true, TEST_LOCATION);
   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue<float>("borderlineOffset", targetBorderlineOffset), true, TEST_LOCATION);
 
+  // Test non-animatable index, for coverage.
+  DALI_TEST_EQUALS(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, ImageVisual::Property::URL).propertyIndex, Property::INVALID_INDEX, TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -6464,3 +6506,143 @@ int UtcDaliVisualUpdatePropertyChangeShader04(void)
 
   END_TEST;
 }
+
+int UtcDaliVisualUpdatePropertyChangeShader05(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliVisualUpdatePropertyChangeShader05: Test update property under glsl version is under 300");
+
+  auto originalShaderVersion = application.GetGlAbstraction().GetShaderLanguageVersion();
+
+  // Change the shader language version forcely!
+  application.GetGlAbstraction().mShaderLanguageVersion = 200;
+
+  try
+  {
+    TraceCallStack& callStack = application.GetGraphicsController().mCallStack;
+
+    VisualFactory factory = VisualFactory::Get();
+    Property::Map propertyMap;
+    // Case ImageVisual
+    propertyMap[Visual::Property::TYPE]           = Visual::Type::COLOR;
+    propertyMap[ColorVisual::Property::MIX_COLOR] = Color::BLUE;
+
+    Visual::Base imageVisual = factory.CreateVisual(propertyMap);
+
+    DummyControl        dummyControl = DummyControl::New(true);
+    Impl::DummyControl& dummyImpl    = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
+    dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, imageVisual);
+    dummyControl[Actor::Property::SIZE] = Vector2(200.f, 200.f);
+    application.GetScene().Add(dummyControl);
+
+    application.SendNotification();
+    application.Render();
+
+    application.SendNotification();
+    application.Render();
+
+    TestShaderCodeContainSubstrings(
+      dummyControl,
+      {
+        {"#define IS_REQUIRED_BLUR", false},
+        {"#define IS_REQUIRED_BORDERLINE", false},
+        {"#define IS_REQUIRED_ROUNDED_CORNER", false},
+      },
+      TEST_LOCATION);
+
+    float   targetBlurRadius   = 15.0f;
+    Vector4 targetCornerRadius = Vector4(1.0f, 0.1f, 1.1f, 0.0f);
+
+    Property::Map targetPropertyMap;
+    targetPropertyMap[DevelColorVisual::Property::BLUR_RADIUS] = targetBlurRadius;
+    targetPropertyMap[DevelVisual::Property::CORNER_RADIUS]    = targetCornerRadius;
+    targetPropertyMap[DevelVisual::Property::BORDERLINE_WIDTH] = 10.0f; // Don't care. just dummy
+
+    callStack.Reset();
+    callStack.Enable(true);
+
+    // Update Properties with CornerRadius
+    DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Action::UPDATE_PROPERTY, targetPropertyMap);
+
+    Property::Map resultMap;
+    imageVisual.CreatePropertyMap(resultMap);
+
+    // Test property values: they should be updated
+    Property::Value* blurRadiusValue = resultMap.Find(DevelColorVisual::Property::BLUR_RADIUS, Property::FLOAT);
+    DALI_TEST_CHECK(blurRadiusValue);
+    DALI_TEST_EQUALS(blurRadiusValue->Get<float>(), targetBlurRadius, TEST_LOCATION);
+
+    Property::Value* cornerRadiusValue = resultMap.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
+    DALI_TEST_CHECK(cornerRadiusValue);
+    DALI_TEST_EQUALS(cornerRadiusValue->Get<Vector4>(), targetCornerRadius, TEST_LOCATION);
+
+    TestShaderCodeContainSubstringsForEachShader(
+      dummyControl,
+      {
+        {"#define IS_REQUIRED_BLUR", {true, true}},
+        {"#define IS_REQUIRED_BORDERLINE", {false, false}}, // Note : We ignore borderline when blur radius occured
+        {"#define IS_REQUIRED_ROUNDED_CORNER", {true, true}},
+        {"#define SL_VERSION_LOW", {false, true}},
+      },
+      TEST_LOCATION);
+
+    // Send shader compile signal
+    application.SendNotification();
+    application.Render();
+
+    callStack.Enable(false);
+
+    // Shader changed
+    DALI_TEST_CHECK((callStack.FindMethod("CreateShader")));
+    callStack.Reset();
+    callStack.Enable(true);
+
+    Property::Map targetPropertyMap2;
+    targetPropertyMap2[DevelColorVisual::Property::BLUR_RADIUS] = 0.0f;
+    targetPropertyMap2[DevelVisual::Property::CORNER_RADIUS]    = Vector4::ZERO;
+    targetPropertyMap2[DevelVisual::Property::BORDERLINE_WIDTH] = 15.0f; // Don't care. just dummy
+
+    // Update Properties with CornerRadius
+    DevelControl::DoAction(dummyControl, DummyControl::Property::TEST_VISUAL, DevelVisual::Action::UPDATE_PROPERTY, targetPropertyMap2);
+
+    Property::Map resultMap2;
+    imageVisual.CreatePropertyMap(resultMap2);
+
+    // Test property values: they should be updated
+    blurRadiusValue = resultMap2.Find(DevelColorVisual::Property::BLUR_RADIUS, Property::FLOAT);
+    DALI_TEST_CHECK(blurRadiusValue);
+    DALI_TEST_EQUALS(blurRadiusValue->Get<float>(), 0.0f, TEST_LOCATION);
+
+    cornerRadiusValue = resultMap2.Find(DevelVisual::Property::CORNER_RADIUS, Property::VECTOR4);
+    DALI_TEST_CHECK(cornerRadiusValue);
+    DALI_TEST_EQUALS(cornerRadiusValue->Get<Vector4>(), Vector4::ZERO, TEST_LOCATION);
+
+    TestShaderCodeContainSubstringsForEachShader(
+      dummyControl,
+      {
+        {"#define IS_REQUIRED_BLUR", {true, true}},           // Note : mAlwaysUsingBlurRadius is true.
+        {"#define IS_REQUIRED_BORDERLINE", {false, false}},   // Note : We ignore borderline when blur radius occured
+        {"#define IS_REQUIRED_ROUNDED_CORNER", {true, true}}, // Note : mAlwaysUsingCornerRadius is true.
+        {"#define SL_VERSION_LOW", {false, true}},
+      },
+      TEST_LOCATION);
+
+    // Send shader compile signal
+    application.SendNotification();
+    application.Render();
+
+    callStack.Enable(false);
+
+    // Shader not changed
+    DALI_TEST_CHECK(!(callStack.FindMethod("CreateShader")));
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(false);
+  }
+
+  // Revert shader version. We should revert it even if UTC failed.
+  application.GetGlAbstraction().mShaderLanguageVersion = originalShaderVersion;
+
+  END_TEST;
+}
\ No newline at end of file