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 * The search is done from a given index.
107 * This allows the order of methods and parameters to be checked.
108 * @param[in] method The name of the method
109 * @param[in] params A comma separated list of parameter values
110 * @param[in/out] startIndex The method index to start looking from.
111 * This is updated if a method is found so subsequent
112 * calls can search for methods occuring after this one.
113 * @return True if the method was in the stack
115 bool FindMethodAndParamsFromStartIndex( std::string method, std::string params, size_t& startIndex ) const;
118 * Search for a method in the stack with the given parameter list
119 * @param[in] method The name of the method
120 * @param[in] params A comma separated list of parameter values
121 * @return index in the stack where the method was found or -1 otherwise
123 int FindIndexFromMethodAndParams(std::string method, std::string params) const;
126 * Search for a method in the stack with the given parameter list
127 * @param[in] method The name of the method
128 * @param[in] params A map of named parameter values to match
129 * @return index in the stack where the method was found or -1 otherwise
131 int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const;
134 * Test if the given method and parameters are at a given index in the stack
135 * @param[in] index Index in the call stack
136 * @param[in] method Name of method to test
137 * @param[in] params A comma separated list of parameter values to test
139 bool TestMethodAndParams(int index, std::string method, std::string params) const;
142 * Reset the call stack
147 * Method to display contents of the TraceCallStack.
148 * @return A string containing a list of function calls and parameters (may contain newline characters)
150 std::string GetTraceString()
152 std::stringstream traceStream;
153 int functionCount = mCallStack.size();
154 for( int i = 0; i < functionCount; ++i )
156 Dali::TraceCallStack::FunctionCall functionCall = mCallStack[ i ];
157 traceStream << "StackTrace: Index:" << i << ", Function:" << functionCall.method << ", ParamList:" << functionCall.paramList << std::endl;
160 return traceStream.str();
164 bool mTraceActive; ///< True if the trace is active
169 std::string paramList;
170 NamedParams namedParams;
171 FunctionCall( const std::string& aMethod, const std::string& aParamList )
172 : method( aMethod ), paramList( aParamList )
175 FunctionCall( const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams )
176 : method( aMethod ), paramList( aParamList ), namedParams( altParams )
181 std::vector< FunctionCall > mCallStack; ///< The call stack
186 #endif // TEST_TRACE_CALL_STACK_H