2 * Copyright (c) 2017 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 bool TraceCallStack::FindMethodAndGetParameters(std::string method, std::string& params ) const
107 for( size_t i=0; i < mCallStack.size(); i++ )
109 if( 0 == mCallStack[i].method.compare(method) )
112 params = mCallStack[i].paramList;
119 int TraceCallStack::CountMethod(std::string method) const
122 for( size_t i=0; i < mCallStack.size(); i++ )
124 if( 0 == mCallStack[i].method.compare(method) )
133 * Search for a method in the stack with the given parameter list
134 * @param[in] method The name of the method
135 * @param[in] params A comma separated list of parameter values
136 * @return true if the method was in the stack
138 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
140 return FindIndexFromMethodAndParams( method, params ) > -1;
143 bool TraceCallStack::FindMethodAndParams(std::string method, const NamedParams& params) const
145 return FindIndexFromMethodAndParams( method, params ) > -1;
148 bool TraceCallStack::FindMethodAndParamsFromStartIndex( std::string method, std::string params, size_t& startIndex ) const
150 for( size_t i = startIndex; i < mCallStack.size(); ++i )
152 if( ( mCallStack[i].method.compare( method ) == 0 ) && ( mCallStack[i].paramList.compare( params ) == 0 ) )
162 * Search for a method in the stack with the given parameter list
163 * @param[in] method The name of the method
164 * @param[in] params A comma separated list of parameter values
165 * @return index in the stack where the method was found or -1 otherwise
167 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string params) const
170 for( size_t i=0; i < mCallStack.size(); i++ )
172 if( 0 == mCallStack[i].method.compare(method) && 0 == mCallStack[i].paramList.compare(params) )
181 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, const TraceCallStack::NamedParams& params) const
184 for( size_t i=0; i < mCallStack.size(); i++ )
186 if( 0 == mCallStack[i].method.compare(method) )
188 // Test each of the passed in parameters:
190 for( NamedParams::const_iterator iter = params.begin() ; iter != params.end() ; ++iter )
192 NamedParams::const_iterator paramIter = mCallStack[i].namedParams.find(iter->first);
193 if( paramIter == params.end() || paramIter->second.compare(iter->second) != 0 )
211 * Test if the given method and parameters are at a given index in the stack
212 * @param[in] index Index in the call stack
213 * @param[in] method Name of method to test
214 * @param[in] params A comma separated list of parameter values to test
216 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
218 return ( 0 == mCallStack[index].method.compare(method) && 0 == mCallStack[index].paramList.compare(params) );
222 * Reset the call stack
224 void TraceCallStack::Reset()