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;
133 bool TraceCallStack::FindMethodAndParamsFromStartIndex( std::string method, std::string params, size_t& startIndex ) const
135 for( size_t i = startIndex; i < mCallStack.size(); ++i )
137 if( ( mCallStack[i].method.compare( method ) == 0 ) && ( mCallStack[i].paramList.compare( params ) == 0 ) )
147 * Search for a method in the stack with the given parameter list
148 * @param[in] method The name of the method
149 * @param[in] params A comma separated list of parameter values
150 * @return index in the stack where the method was found or -1 otherwise
152 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string params) const
155 for( size_t i=0; i < mCallStack.size(); i++ )
157 if( 0 == mCallStack[i].method.compare(method) && 0 == mCallStack[i].paramList.compare(params) )
166 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, const TraceCallStack::NamedParams& params) const
169 for( size_t i=0; i < mCallStack.size(); i++ )
171 if( 0 == mCallStack[i].method.compare(method) )
173 // Test each of the passed in parameters:
175 for( NamedParams::const_iterator iter = params.begin() ; iter != params.end() ; ++iter )
177 NamedParams::const_iterator paramIter = mCallStack[i].namedParams.find(iter->first);
178 if( paramIter == params.end() || paramIter->second.compare(iter->second) != 0 )
196 * Test if the given method and parameters are at a given index in the stack
197 * @param[in] index Index in the call stack
198 * @param[in] method Name of method to test
199 * @param[in] params A comma separated list of parameter values to test
201 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
203 return ( 0 == mCallStack[index].method.compare(method) && 0 == mCallStack[index].paramList.compare(params) );
207 * Reset the call stack
209 void TraceCallStack::Reset()