Synchronised automated tests utils with dali-core & updated README
[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 /**
89  * Search for a method in the stack with the given parameter list
90  * @param[in] method The name of the method
91  * @param[in] params A comma separated list of parameter values
92  * @return true if the method was in the stack
93  */
94 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
95 {
96   bool found = false;
97   for( size_t i=0; i < mCallStack.size(); i++ )
98   {
99     if( 0 == mCallStack[i][0].compare(method) && 0 == mCallStack[i][1].compare(params) )
100     {
101       found = true;
102       break;
103     }
104   }
105   return found;
106 }
107
108 /**
109  * Test if the given method and parameters are at a given index in the stack
110  * @param[in] index Index in the call stack
111  * @param[in] method Name of method to test
112  * @param[in] params A comma separated list of parameter values to test
113  */
114 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
115 {
116   return ( 0 == mCallStack[index][0].compare(method) && 0 == mCallStack[index][1].compare(params) );
117 }
118
119 /**
120  * Reset the call stack
121  */
122 void TraceCallStack::Reset()
123 {
124   mCallStack.clear();
125 }
126
127
128 } // namespace Dali