1 #ifndef TEST_TRACE_CALL_STACK_H
2 #define TEST_TRACE_CALL_STACK_H
5 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
29 std::string ToString(const T& x)
34 std::string ToString(int x);
35 std::string ToString(unsigned int x);
36 std::string ToString(float x);
39 * Helper class to track method calls in the abstraction and search for them in test cases
44 /// Typedef for passing and storing named parameters
45 typedef std::map<std::string, std::string> NamedParams;
58 * Turn on / off tracing
60 void Enable(bool enable);
65 * Push a call onto the stack if the trace is active
66 * @param[in] method The name of the method
67 * @param[in] params A comma separated list of parameter values
69 void PushCall(std::string method, std::string params);
72 * Push a call onto the stack if the trace is active
73 * @param[in] method The name of the method
74 * @param[in] params A comma separated list of parameter values
75 * @param[in] altParams A map of named parameter values
77 void PushCall(std::string method, std::string params, const NamedParams& altParams);
80 * Search for a method in the stack
81 * @param[in] method The name of the method
82 * @return true if the method was in the stack
84 bool FindMethod(std::string method) const;
87 * Search for a method in the stack and return its parameters if found
88 * @param[in] method The name of the method
89 * @param[out] params of the method
90 * @return true if the method was in the stack
92 bool FindMethodAndGetParameters(std::string method, std::string& params) const;
95 * Count how many times a method was called
96 * @param[in] method The name of the method
97 * @return The number of times it was called
99 int CountMethod(std::string method) const;
102 * Search for a method in the stack with the given parameter list
103 * @param[in] method The name of the method
104 * @param[in] params A comma separated list of parameter values
105 * @return true if the method was in the stack
107 bool FindMethodAndParams(std::string method, std::string params) const;
110 * Search for a method in the stack with the given parameter list
111 * @param[in] method The name of the method
112 * @param[in] params A map of named parameters to test for
113 * @return true if the method was in the stack
115 bool FindMethodAndParams(std::string method, const NamedParams& params) const;
118 * Search for a method in the stack with the given parameter list.
119 * The search is done from a given index.
120 * This allows the order of methods and parameters to be checked.
121 * @param[in] method The name of the method
122 * @param[in] params A comma separated list of parameter values
123 * @param[in/out] startIndex The method index to start looking from.
124 * This is updated if a method is found so subsequent
125 * calls can search for methods occuring after this one.
126 * @return True if the method was in the stack
128 bool FindMethodAndParamsFromStartIndex(std::string method, std::string params, size_t& startIndex) const;
131 * Search for a method in the stack with the given parameter list
132 * @param[in] method The name of the method
133 * @param[in] params A comma separated list of parameter values
134 * @return index in the stack where the method was found or -1 otherwise
136 int FindIndexFromMethodAndParams(std::string method, std::string params) const;
139 * Search for a method in the stack with the given parameter list
140 * @param[in] method The name of the method
141 * @param[in] params A map of named parameter values to match
142 * @return index in the stack where the method was found or -1 otherwise
144 int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const;
147 * Test if the given method and parameters are at a given index in the stack
148 * @param[in] index Index in the call stack
149 * @param[in] method Name of method to test
150 * @param[in] params A comma separated list of parameter values to test
152 bool TestMethodAndParams(int index, std::string method, std::string params) const;
155 * Reset the call stack
160 * Method to display contents of the TraceCallStack.
161 * @return A string containing a list of function calls and parameters (may contain newline characters)
163 std::string GetTraceString()
165 std::stringstream traceStream;
166 std::size_t functionCount = mCallStack.size();
167 for(std::size_t i = 0; i < functionCount; ++i)
169 Dali::TraceCallStack::FunctionCall functionCall = mCallStack[i];
170 traceStream << "StackTrace: Index:" << i << ", Function:" << functionCall.method << ", ParamList:" << functionCall.paramList << std::endl;
173 return traceStream.str();
177 bool mTraceActive; ///< True if the trace is active
182 std::string paramList;
183 NamedParams namedParams;
184 FunctionCall(const std::string& aMethod, const std::string& aParamList)
186 paramList(aParamList)
189 FunctionCall(const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams)
191 paramList(aParamList),
192 namedParams(altParams)
197 std::vector<FunctionCall> mCallStack; ///< The call stack
202 #endif // TEST_TRACE_CALL_STACK_H