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"
25 TraceCallStack::TraceCallStack() : mTraceActive(false) { }
30 TraceCallStack::~TraceCallStack() { }
33 * Turn on / off tracing
35 void TraceCallStack::Enable(bool enable) { mTraceActive = enable; }
37 bool TraceCallStack::IsEnabled() { return mTraceActive; }
40 * Push a call onto the stack if the trace is active
41 * @param[in] method The name of the method
42 * @param[in] params A comma separated list of parameter values
44 void TraceCallStack::PushCall(std::string method, std::string params)
48 std::vector< std::string > functionCall;
49 functionCall.push_back(method);
50 functionCall.push_back(params);
51 mCallStack.push_back( functionCall );
56 * Search for a method in the stack
57 * @param[in] method The name of the method
58 * @return true if the method was in the stack
60 bool TraceCallStack::FindMethod(std::string method) const
63 for( size_t i=0; i < mCallStack.size(); i++ )
65 if( 0 == mCallStack[i][0].compare(method) )
74 int TraceCallStack::CountMethod(std::string method) const
77 for( size_t i=0; i < mCallStack.size(); i++ )
79 if( 0 == mCallStack[i][0].compare(method) )
88 * Search for a method in the stack with the given parameter list
89 * @param[in] method The name of the method
90 * @param[in] params A comma separated list of parameter values
91 * @return true if the method was in the stack
93 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
95 return FindIndexFromMethodAndParams( method, params ) > -1;
99 * Search for a method in the stack with the given parameter list
100 * @param[in] method The name of the method
101 * @param[in] params A comma separated list of parameter values
102 * @return index in the stack where the method was found or -1 otherwise
104 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string params) const
107 for( size_t i=0; i < mCallStack.size(); i++ )
109 if( 0 == mCallStack[i][0].compare(method) && 0 == mCallStack[i][1].compare(params) )
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 TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
126 return ( 0 == mCallStack[index][0].compare(method) && 0 == mCallStack[index][1].compare(params) );
130 * Reset the call stack
132 void TraceCallStack::Reset()