bda38d337cfffee1fdf187b30db7a9cee6ab8c99
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-trace-call-stack.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include "test-trace-call-stack.h"
19
20 namespace Dali
21 {
22 /**
23  * Constructor
24  */
25 TraceCallStack::TraceCallStack() : mTraceActive(false) { }
26
27 /**
28  * Destructor
29  */
30 TraceCallStack::~TraceCallStack() { }
31
32 /**
33  * Turn on / off tracing
34  */
35 void TraceCallStack::Enable(bool enable) { mTraceActive = enable; }
36
37 bool TraceCallStack::IsEnabled() { return mTraceActive; }
38
39 /**
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
43  */
44 void TraceCallStack::PushCall(std::string method, std::string params)
45 {
46   if(mTraceActive)
47   {
48     std::vector< std::string > functionCall;
49     functionCall.push_back(method);
50     functionCall.push_back(params);
51     mCallStack.push_back( functionCall );
52   }
53 }
54
55 /**
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
59  */
60 bool TraceCallStack::FindMethod(std::string method) const
61 {
62   bool found = false;
63   for( size_t i=0; i < mCallStack.size(); i++ )
64   {
65     if( 0 == mCallStack[i][0].compare(method) )
66     {
67       found = true;
68       break;
69     }
70   }
71   return found;
72 }
73
74 int TraceCallStack::CountMethod(std::string method) const
75 {
76   int numCalls = 0;
77   for( size_t i=0; i < mCallStack.size(); i++ )
78   {
79     if( 0 == mCallStack[i][0].compare(method) )
80     {
81       numCalls++;
82     }
83   }
84   return numCalls;
85 }
86
87 /**
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
92  */
93 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
94 {
95   return FindIndexFromMethodAndParams( method, params ) > -1;
96 }
97
98 /**
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
103  */
104 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string params) const
105 {
106   int index = -1;
107   for( size_t i=0; i < mCallStack.size(); i++ )
108   {
109     if( 0 == mCallStack[i][0].compare(method) && 0 == mCallStack[i][1].compare(params) )
110     {
111       index = i;
112       break;
113     }
114   }
115   return index;
116 }
117
118 /**
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
123  */
124 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
125 {
126   return ( 0 == mCallStack[index][0].compare(method) && 0 == mCallStack[index][1].compare(params) );
127 }
128
129 /**
130  * Reset the call stack
131  */
132 void TraceCallStack::Reset()
133 {
134   mCallStack.clear();
135 }
136
137
138 } // namespace Dali