2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "test-trace-call-stack.h"
24 std::string ToString(int x)
26 std::stringstream out;
31 std::string ToString(unsigned int x)
33 std::stringstream out;
38 std::string ToString(float x)
40 std::stringstream out;
48 TraceCallStack::TraceCallStack() : mTraceActive(false) { }
53 TraceCallStack::~TraceCallStack() { }
56 * Turn on / off tracing
58 void TraceCallStack::Enable(bool enable) { mTraceActive = enable; }
60 bool TraceCallStack::IsEnabled() { return mTraceActive; }
63 * Push a call onto the stack if the trace is active
64 * @param[in] method The name of the method
65 * @param[in] params A comma separated list of parameter values
67 void TraceCallStack::PushCall(std::string method, std::string params)
71 FunctionCall stackFrame(method, params);
72 mCallStack.push_back( stackFrame );
76 void TraceCallStack::PushCall(std::string method, std::string params, const TraceCallStack::NamedParams& altParams)
80 FunctionCall stackFrame(method, params, altParams);
81 mCallStack.push_back( stackFrame );
86 * Search for a method in the stack
87 * @param[in] method The name of the method
88 * @return true if the method was in the stack
90 bool TraceCallStack::FindMethod(std::string method) const
93 for( size_t i=0; i < mCallStack.size(); i++ )
95 if( 0 == mCallStack[i].method.compare(method) )
104 int TraceCallStack::CountMethod(std::string method) const
107 for( size_t i=0; i < mCallStack.size(); i++ )
109 if( 0 == mCallStack[i].method.compare(method) )
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 true if the method was in the stack
123 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
125 return FindIndexFromMethodAndParams( method, params ) > -1;
128 bool TraceCallStack::FindMethodAndParams(std::string method, const NamedParams& params) const
130 return FindIndexFromMethodAndParams( method, params ) > -1;
135 * Search for a method in the stack with the given parameter list
136 * @param[in] method The name of the method
137 * @param[in] params A comma separated list of parameter values
138 * @return index in the stack where the method was found or -1 otherwise
140 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string params) const
143 for( size_t i=0; i < mCallStack.size(); i++ )
145 if( 0 == mCallStack[i].method.compare(method) && 0 == mCallStack[i].paramList.compare(params) )
154 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, const TraceCallStack::NamedParams& params) const
157 for( size_t i=0; i < mCallStack.size(); i++ )
159 if( 0 == mCallStack[i].method.compare(method) )
161 // Test each of the passed in parameters:
163 for( NamedParams::const_iterator iter = params.begin() ; iter != params.end() ; ++iter )
165 NamedParams::const_iterator paramIter = mCallStack[i].namedParams.find(iter->first);
166 if( paramIter == params.end() || paramIter->second.compare(iter->second) != 0 )
184 * Test if the given method and parameters are at a given index in the stack
185 * @param[in] index Index in the call stack
186 * @param[in] method Name of method to test
187 * @param[in] params A comma separated list of parameter values to test
189 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
191 return ( 0 == mCallStack[index].method.compare(method) && 0 == mCallStack[index].paramList.compare(params) );
195 * Reset the call stack
197 void TraceCallStack::Reset()