1 #ifndef __TEST_TRACE_CALL_STACK_H__
2 #define __TEST_TRACE_CALL_STACK_H__
5 * Copyright (c) 2014 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.
27 std::string ToString(int x);
28 std::string ToString(unsigned int x);
29 std::string ToString(float x);
32 * Helper class to track method calls in the abstraction and search for them in test cases
37 /// Typedef for passing and storing named parameters
38 typedef std::map< std::string, std::string > NamedParams;
51 * Turn on / off tracing
53 void Enable(bool enable);
58 * Push a call onto the stack if the trace is active
59 * @param[in] method The name of the method
60 * @param[in] params A comma separated list of parameter values
62 void PushCall(std::string method, std::string params);
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
68 * @param[in] altParams A map of named parameter values
70 void PushCall(std::string method, std::string params, const NamedParams& altParams);
73 * Search for a method in the stack
74 * @param[in] method The name of the method
75 * @return true if the method was in the stack
77 bool FindMethod(std::string method) const;
80 * Count how many times a method was called
81 * @param[in] method The name of the method
82 * @return The number of times it was called
84 int CountMethod(std::string method) const;
87 * Search for a method in the stack with the given parameter list
88 * @param[in] method The name of the method
89 * @param[in] params A comma separated list of parameter values
90 * @return true if the method was in the stack
92 bool FindMethodAndParams(std::string method, std::string params) const;
95 * Search for a method in the stack with the given parameter list
96 * @param[in] method The name of the method
97 * @param[in] params A map of named parameters to test for
98 * @return true if the method was in the stack
100 bool FindMethodAndParams(std::string method, const NamedParams& params) const;
103 * Search for a method in the stack with the given parameter list
104 * @param[in] method The name of the method
105 * @param[in] params A comma separated list of parameter values
106 * @return index in the stack where the method was found or -1 otherwise
108 int FindIndexFromMethodAndParams(std::string method, std::string params) const;
111 * Search for a method in the stack with the given parameter list
112 * @param[in] method The name of the method
113 * @param[in] params A map of named parameter values to match
114 * @return index in the stack where the method was found or -1 otherwise
116 int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const;
119 * Test if the given method and parameters are at a given index in the stack
120 * @param[in] index Index in the call stack
121 * @param[in] method Name of method to test
122 * @param[in] params A comma separated list of parameter values to test
124 bool TestMethodAndParams(int index, std::string method, std::string params) const;
127 * Reset the call stack
132 bool mTraceActive; ///< True if the trace is active
137 std::string paramList;
138 NamedParams namedParams;
139 FunctionCall( const std::string& aMethod, const std::string& aParamList )
140 : method( aMethod ), paramList( aParamList )
143 FunctionCall( const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams )
144 : method( aMethod ), paramList( aParamList ), namedParams( altParams )
149 std::vector< FunctionCall > mCallStack; ///< The call stack
154 #endif //__TEST_TRACE_CALL_STACK_H__