Fix RemoteSVG UTC failed due to the proxy block (2)
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-vector-image-renderer.cpp
index d809e66..78252b8 100644 (file)
@@ -34,7 +34,38 @@ namespace Adaptor
 namespace
 {
 Dali::Internal::Adaptor::VectorImageRenderer* gVectorImageRenderer = nullptr;
+
+/**
+ * @brief Check whether the data contain keyword as substring or not.
+ * It can be used as Naive Check-up to determine vector image loaded successfully or not.
+ *
+ * @param[in] data Raw data
+ * @param[in] keyword Keyword to check data holded or not.
+ * @return True if data contain keyword.
+ */
+bool CheckKeywordExist(const Vector<uint8_t>& data, std::string keyword)
+{
+  std::string trimedString;
+
+  // Remove useless character in data.
+  for(const uint8_t& it : data)
+  {
+    if(keyword.find(it) != std::string::npos)
+    {
+      trimedString.push_back(it);
+    }
+  }
+
+  if(trimedString.length() >= keyword.length())
+  {
+    if(trimedString.find(keyword) != std::string::npos)
+    {
+      return true;
+    }
+  }
+  return false;
 }
+} // namespace
 
 class VectorImageRenderer : public Dali::BaseObject
 {
@@ -58,12 +89,18 @@ public:
     {
       mRasterizeSuccess = false;
     }
+    // Naive check-up whether data is valid format or not. Currently we only check svg and tvg file format.
+    else if(!CheckKeywordExist(data, "</svg>") && !CheckKeywordExist(data, "ThorVG"))
+    {
+      return false;
+    }
+    mLoadSuccess = true;
     return true;
   }
 
   bool IsLoaded() const
   {
-    return mLoadCount > 0 ? true : false;
+    return mLoadSuccess;
   }
 
   Dali::Devel::PixelBuffer Rasterize(uint32_t width, uint32_t height)
@@ -86,6 +123,7 @@ public:
   uint32_t mWidth{0};
   uint32_t mHeight{0};
   uint32_t mLoadCount{0};
+  bool     mLoadSuccess{false};
   bool     mRasterizeSuccess{true};
 };