1 #ifndef TEST_TRACE_CALL_STACK_H
2 #define TEST_TRACE_CALL_STACK_H
5 * Copyright (c) 2016 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.
28 std::string ToString(int x);
29 std::string ToString(unsigned int x);
30 std::string ToString(float x);
33 * Helper class to track method calls in the abstraction and search for them in test cases
39 /// Typedef for passing and storing named parameters
40 typedef std::map< std::string, std::string > NamedParams;
53 * Turn on / off tracing
55 void Enable(bool enable);
60 * Push a call onto the stack if the trace is active
61 * @param[in] method The name of the method
62 * @param[in] params A comma separated list of parameter values
64 void PushCall(std::string method, std::string params);
67 * Push a call onto the stack if the trace is active
68 * @param[in] method The name of the method
69 * @param[in] params A comma separated list of parameter values
70 * @param[in] altParams A map of named parameter values
72 void PushCall(std::string method, std::string params, const NamedParams& altParams);
75 * Search for a method in the stack
76 * @param[in] method The name of the method
77 * @return true if the method was in the stack
79 bool FindMethod(std::string method) const;
82 * Count how many times a method was called
83 * @param[in] method The name of the method
84 * @return The number of times it was called
86 int CountMethod(std::string method) const;
89 * Search for a method in the stack with the given parameter list
90 * @param[in] method The name of the method
91 * @param[in] params A comma separated list of parameter values
92 * @return true if the method was in the stack
94 bool FindMethodAndParams(std::string method, std::string params) const;
97 * Search for a method in the stack with the given parameter list
98 * @param[in] method The name of the method
99 * @param[in] params A map of named parameters to test for
100 * @return true if the method was in the stack
102 bool FindMethodAndParams(std::string method, const NamedParams& params) const;
105 * Search for a method in the stack with the given parameter list
106 * @param[in] method The name of the method
107 * @param[in] params A comma separated list of parameter values
108 * @return index in the stack where the method was found or -1 otherwise
110 int FindIndexFromMethodAndParams(std::string method, std::string params) const;
113 * Search for a method in the stack with the given parameter list
114 * @param[in] method The name of the method
115 * @param[in] params A map of named parameter values to match
116 * @return index in the stack where the method was found or -1 otherwise
118 int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const;
121 * Test if the given method and parameters are at a given index in the stack
122 * @param[in] index Index in the call stack
123 * @param[in] method Name of method to test
124 * @param[in] params A comma separated list of parameter values to test
126 bool TestMethodAndParams(int index, std::string method, std::string params) const;
129 * Reset the call stack
134 * Method to display contents of the TraceCallStack.
135 * @return A string containing a list of function calls and parameters (may contain newline characters)
137 std::string GetTraceString()
139 std::stringstream traceStream;
140 int functionCount = mCallStack.size();
141 for( int i = 0; i < functionCount; ++i )
143 Dali::TraceCallStack::FunctionCall functionCall = mCallStack[ i ];
144 traceStream << "StackTrace: Index:" << i << ", Function:" << functionCall.method << ", ParamList:" << functionCall.paramList << std::endl;
147 return traceStream.str();
151 bool mTraceActive; ///< True if the trace is active
156 std::string paramList;
157 NamedParams namedParams;
158 FunctionCall( const std::string& aMethod, const std::string& aParamList )
159 : method( aMethod ), paramList( aParamList )
162 FunctionCall( const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams )
163 : method( aMethod ), paramList( aParamList ), namedParams( altParams )
168 std::vector< FunctionCall > mCallStack; ///< The call stack
173 #endif // TEST_TRACE_CALL_STACK_H