Conversion to Apache 2.0 license
[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 /**
38  * Push a call onto the stack if the trace is active
39  * @param[in] method The name of the method
40  * @param[in] params A comma separated list of parameter values
41  */
42 void TraceCallStack::PushCall(std::string method, std::string params)
43 {
44   if(mTraceActive)
45   {
46     std::vector< std::string > functionCall;
47     functionCall.push_back(method);
48     functionCall.push_back(params);
49     mCallStack.push_back( functionCall );
50   }
51 }
52
53 /**
54  * Search for a method in the stack
55  * @param[in] method The name of the method
56  * @return true if the method was in the stack
57  */
58 bool TraceCallStack::FindMethod(std::string method) const
59 {
60   bool found = false;
61   for( size_t i=0; i < mCallStack.size(); i++ )
62   {
63     if( 0 == mCallStack[i][0].compare(method) )
64     {
65       found = true;
66       break;
67     }
68   }
69   return found;
70 }
71
72 /**
73  * Search for a method in the stack with the given parameter list
74  * @param[in] method The name of the method
75  * @param[in] params A comma separated list of parameter values
76  * @return true if the method was in the stack
77  */
78 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
79 {
80   bool found = false;
81   for( size_t i=0; i < mCallStack.size(); i++ )
82   {
83     if( 0 == mCallStack[i][0].compare(method) && 0 == mCallStack[i][1].compare(params) )
84     {
85       found = true;
86       break;
87     }
88   }
89   return found;
90 }
91
92 /**
93  * Test if the given method and parameters are at a given index in the stack
94  * @param[in] index Index in the call stack
95  * @param[in] method Name of method to test
96  * @param[in] params A comma separated list of parameter values to test
97  */
98 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
99 {
100   return ( 0 == mCallStack[index][0].compare(method) && 0 == mCallStack[index][1].compare(params) );
101 }
102
103 /**
104  * Reset the call stack
105  */
106 void TraceCallStack::Reset()
107 {
108   mCallStack.clear();
109 }
110
111
112 } // namespace Dali