Syncing Test harness updates for Native Image
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-trace-call-stack.h
index 8cb5922..b7d9e46 100644 (file)
@@ -2,7 +2,7 @@
 #define TEST_TRACE_CALL_STACK_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 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.
@@ -42,12 +42,104 @@ class TraceCallStack
 {
 public:
   /// Typedef for passing and storing named parameters
-  typedef std::map<std::string, std::string> NamedParams;
+  class NamedParams
+  {
+  public:
+    struct NameValue
+    {
+      std::string        parameterName;
+      std::ostringstream value;
+      NameValue(std::string pname, std::string aValue)
+      : parameterName(pname),
+        value(aValue)
+      {
+      }
+      NameValue(const NameValue& rhs)
+      : parameterName(rhs.parameterName),
+        value(rhs.value.str())
+      {
+      }
+      NameValue& operator=(const NameValue& rhs)
+      {
+        if(this != &rhs)
+        {
+          this->parameterName = rhs.parameterName;
+          this->value.str(rhs.value.str());
+        }
+        return *this;
+      }
+
+      bool operator==(const NameValue& rhs)
+      {
+        return !parameterName.compare(rhs.parameterName) && !value.str().compare(rhs.value.str());
+      }
+    };
+
+    auto find(const std::string& param) const
+    {
+      auto iter = mParams.begin();
+      for(; iter != mParams.end(); ++iter)
+      {
+        if(!iter->parameterName.compare(param))
+        {
+          break;
+        }
+      }
+      return iter;
+    }
+
+    auto begin() const
+    {
+      return mParams.begin();
+    }
+    auto end() const
+    {
+      return mParams.end();
+    }
+
+    std::ostringstream& operator[](std::string name)
+    {
+      auto iter = mParams.begin();
+      for(; iter != mParams.end(); ++iter)
+      {
+        if(!iter->parameterName.compare(name))
+        {
+          break;
+        }
+      }
+
+      if(iter != mParams.end())
+      {
+        return iter->value;
+      }
+      else
+      {
+        mParams.push_back(NameValue(name, ""));
+        return mParams.back().value;
+      }
+    }
+
+    std::string str() const
+    {
+      std::ostringstream out;
+      bool               first = true;
+      for(auto& elem : mParams)
+      {
+        out << (first ? "" : " ") << elem.parameterName << ": " << elem.value.str();
+        first = false;
+      }
+      return out.str();
+    }
+    std::vector<NameValue> mParams{};
+  };
 
   /**
    * Constructor
    */
-  TraceCallStack();
+  TraceCallStack(bool logging, std::string prefix);
+
+  TraceCallStack(const TraceCallStack&) = delete;
+  TraceCallStack(TraceCallStack&&)      = delete;
 
   /**
    * Destructor
@@ -61,6 +153,8 @@ public:
 
   bool IsEnabled();
 
+  void EnableLogging(bool enable);
+
   /**
    * Push a call onto the stack if the trace is active
    * @param[in] method The name of the method
@@ -174,7 +268,9 @@ public:
   }
 
 private:
-  bool mTraceActive; ///< True if the trace is active
+  bool        mTraceActive{false}; ///< True if the trace is active
+  bool        mLogging{false};     ///< True if the trace is logged to stdout
+  std::string mPrefix;
 
   struct FunctionCall
   {