X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftest-trace-call-stack.h;h=8cb592286daf04b2b02c7f67d44d8aa182475755;hp=d32f6199aeddcf9eb80e22d06d56b020752cfcd7;hb=HEAD;hpb=e1d3366cda5ce5fabc3f5117b67409d748d6b03d diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h index d32f619..c2d0a49 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-trace-call-stack.h @@ -2,7 +2,7 @@ #define TEST_TRACE_CALL_STACK_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -18,14 +18,13 @@ * */ -#include -#include #include #include +#include +#include namespace Dali { - template std::string ToString(const T& x) { @@ -42,14 +41,126 @@ std::string ToString(float x); 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()); + } + + bool operator==(int match) const; + }; + + 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; + } + } + + const std::ostringstream& operator[](std::string name) const + { + static std::ostringstream empty; + auto iter = mParams.begin(); + for(; iter != mParams.end(); ++iter) + { + if(!iter->parameterName.compare(name)) + { + break; + } + } + + if(iter != mParams.end()) + { + return iter->value; + } + return empty; + } + + 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 mParams{}; + }; /** * Constructor */ - TraceCallStack(); + TraceCallStack(bool logging, std::string prefix); + + TraceCallStack(const TraceCallStack&) = delete; + TraceCallStack(TraceCallStack&&) = delete; /** * Destructor @@ -63,6 +174,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 @@ -91,7 +204,15 @@ public: * @param[out] params of the method * @return true if the method was in the stack */ - bool FindMethodAndGetParameters(std::string method, std::string& params ) const; + bool FindMethodAndGetParameters(std::string method, std::string& params) const; + + /** + * Search for a method in the stack and return its parameters if found + * @param[in] method The name of the method + * @param[out] params of the method + * @return true if the method was in the stack + */ + bool FindMethodAndGetParameters(std::string method, NamedParams& params) const; /** * Count how many times a method was called @@ -127,7 +248,7 @@ public: * calls can search for methods occuring after this one. * @return True if the method was in the stack */ - bool FindMethodAndParamsFromStartIndex( std::string method, std::string params, size_t& startIndex ) const; + bool FindMethodAndParamsFromStartIndex(std::string method, std::string params, size_t& startIndex) const; /** * Search for a method in the stack with the given parameter list @@ -146,6 +267,14 @@ public: int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const; /** + * Search for the most recent occurrence of the method with the given (partial) parameters. + * @param[in] method The name of the method + * @param[in] params A map of named parameter values to match + * @return The full named parameters of the matching call. + */ + const NamedParams* FindLastMatch(std::string method, const TraceCallStack::NamedParams& params) const; + + /** * Test if the given method and parameters are at a given index in the stack * @param[in] index Index in the call stack * @param[in] method Name of method to test @@ -165,37 +294,42 @@ public: std::string GetTraceString() { std::stringstream traceStream; - int functionCount = mCallStack.size(); - for( int i = 0; i < functionCount; ++i ) + std::size_t functionCount = mCallStack.size(); + for(std::size_t i = 0; i < functionCount; ++i) { - Dali::TraceCallStack::FunctionCall functionCall = mCallStack[ i ]; + Dali::TraceCallStack::FunctionCall functionCall = mCallStack[i]; traceStream << "StackTrace: Index:" << i << ", Function:" << functionCall.method << ", ParamList:" << functionCall.paramList << std::endl; } return traceStream.str(); } -private: - bool mTraceActive; ///< True if the trace is active +public: + 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 { std::string method; std::string paramList; NamedParams namedParams; - FunctionCall( const std::string& aMethod, const std::string& aParamList ) - : method( aMethod ), paramList( aParamList ) + FunctionCall(const std::string& aMethod, const std::string& aParamList) + : method(aMethod), + paramList(aParamList) { } - FunctionCall( const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams ) - : method( aMethod ), paramList( aParamList ), namedParams( altParams ) + FunctionCall(const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams) + : method(aMethod), + paramList(aParamList), + namedParams(altParams) { } }; - std::vector< FunctionCall > mCallStack; ///< The call stack + std::vector mCallStack; ///< The call stack }; -} // namespace dali +} // namespace Dali #endif // TEST_TRACE_CALL_STACK_H