Revert "License conversion from Flora to Apache 2.0"
[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 Flora License, Version 1.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://floralicense.org/license/
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 #include "test-trace-call-stack.h"
18
19 namespace Dali
20 {
21 /**
22  * Constructor
23  */
24 TraceCallStack::TraceCallStack() : mTraceActive(false) { }
25
26 /**
27  * Destructor
28  */
29 TraceCallStack::~TraceCallStack() { }
30
31 /**
32  * Turn on / off tracing
33  */
34 void TraceCallStack::Enable(bool enable) { mTraceActive = enable; }
35
36 /**
37  * Push a call onto the stack if the trace is active
38  * @param[in] method The name of the method
39  * @param[in] params A comma separated list of parameter values
40  */
41 void TraceCallStack::PushCall(std::string method, std::string params)
42 {
43   if(mTraceActive)
44   {
45     std::vector< std::string > functionCall;
46     functionCall.push_back(method);
47     functionCall.push_back(params);
48     mCallStack.push_back( functionCall );
49   }
50 }
51
52 /**
53  * Search for a method in the stack
54  * @param[in] method The name of the method
55  * @return true if the method was in the stack
56  */
57 bool TraceCallStack::FindMethod(std::string method) const
58 {
59   bool found = false;
60   for( size_t i=0; i < mCallStack.size(); i++ )
61   {
62     if( 0 == mCallStack[i][0].compare(method) )
63     {
64       found = true;
65       break;
66     }
67   }
68   return found;
69 }
70
71 /**
72  * Search for a method in the stack with the given parameter list
73  * @param[in] method The name of the method
74  * @param[in] params A comma separated list of parameter values
75  * @return true if the method was in the stack
76  */
77 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
78 {
79   bool found = false;
80   for( size_t i=0; i < mCallStack.size(); i++ )
81   {
82     if( 0 == mCallStack[i][0].compare(method) && 0 == mCallStack[i][1].compare(params) )
83     {
84       found = true;
85       break;
86     }
87   }
88   return found;
89 }
90
91 /**
92  * Test if the given method and parameters are at a given index in the stack
93  * @param[in] index Index in the call stack
94  * @param[in] method Name of method to test
95  * @param[in] params A comma separated list of parameter values to test
96  */
97 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
98 {
99   return ( 0 == mCallStack[index][0].compare(method) && 0 == mCallStack[index][1].compare(params) );
100 }
101
102 /**
103  * Reset the call stack
104  */
105 void TraceCallStack::Reset()
106 {
107   mCallStack.clear();
108 }
109
110
111 } // namespace Dali