Re-added test files to build and fixed failing tests
[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 #include <sstream>
20
21 namespace Dali
22 {
23
24 std::string ToString(int x)
25 {
26   std::stringstream out;
27   out << x;
28   return out.str();
29 }
30
31 std::string ToString(unsigned int x)
32 {
33   std::stringstream out;
34   out << x;
35   return out.str();
36 }
37
38 std::string ToString(float x)
39 {
40   std::stringstream out;
41   out << x;
42   return out.str();
43 }
44
45 /**
46  * Constructor
47  */
48 TraceCallStack::TraceCallStack() : mTraceActive(false) { }
49
50 /**
51  * Destructor
52  */
53 TraceCallStack::~TraceCallStack() { }
54
55 /**
56  * Turn on / off tracing
57  */
58 void TraceCallStack::Enable(bool enable) { mTraceActive = enable; }
59
60 bool TraceCallStack::IsEnabled() { return mTraceActive; }
61
62 /**
63  * Push a call onto the stack if the trace is active
64  * @param[in] method The name of the method
65  * @param[in] params A comma separated list of parameter values
66  */
67 void TraceCallStack::PushCall(std::string method, std::string params)
68 {
69   if(mTraceActive)
70   {
71     FunctionCall stackFrame(method, params);
72     mCallStack.push_back( stackFrame );
73   }
74 }
75
76 void TraceCallStack::PushCall(std::string method, std::string params, const TraceCallStack::NamedParams& altParams)
77 {
78   if(mTraceActive)
79   {
80     FunctionCall stackFrame(method, params, altParams);
81     mCallStack.push_back( stackFrame );
82   }
83 }
84
85 /**
86  * Search for a method in the stack
87  * @param[in] method The name of the method
88  * @return true if the method was in the stack
89  */
90 bool TraceCallStack::FindMethod(std::string method) const
91 {
92   bool found = false;
93   for( size_t i=0; i < mCallStack.size(); i++ )
94   {
95     if( 0 == mCallStack[i].method.compare(method) )
96     {
97       found = true;
98       break;
99     }
100   }
101   return found;
102 }
103
104 int TraceCallStack::CountMethod(std::string method) const
105 {
106   int numCalls = 0;
107   for( size_t i=0; i < mCallStack.size(); i++ )
108   {
109     if( 0 == mCallStack[i].method.compare(method) )
110     {
111       numCalls++;
112     }
113   }
114   return numCalls;
115 }
116
117 /**
118  * Search for a method in the stack with the given parameter list
119  * @param[in] method The name of the method
120  * @param[in] params A comma separated list of parameter values
121  * @return true if the method was in the stack
122  */
123 bool TraceCallStack::FindMethodAndParams(std::string method, std::string params) const
124 {
125   return FindIndexFromMethodAndParams( method, params ) > -1;
126 }
127
128 bool TraceCallStack::FindMethodAndParams(std::string method, const NamedParams& params) const
129 {
130   return FindIndexFromMethodAndParams( method, params ) > -1;
131 }
132
133
134 /**
135  * Search for a method in the stack with the given parameter list
136  * @param[in] method The name of the method
137  * @param[in] params A comma separated list of parameter values
138  * @return index in the stack where the method was found or -1 otherwise
139  */
140 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, std::string params) const
141 {
142   int index = -1;
143   for( size_t i=0; i < mCallStack.size(); i++ )
144   {
145     if( 0 == mCallStack[i].method.compare(method) && 0 == mCallStack[i].paramList.compare(params) )
146     {
147       index = i;
148       break;
149     }
150   }
151   return index;
152 }
153
154 int TraceCallStack::FindIndexFromMethodAndParams(std::string method, const TraceCallStack::NamedParams& params) const
155 {
156   int index = -1;
157   for( size_t i=0; i < mCallStack.size(); i++ )
158   {
159     if( 0 == mCallStack[i].method.compare(method) )
160     {
161       // Test each of the passed in parameters:
162       bool match = true;
163       for( NamedParams::const_iterator iter = params.begin() ; iter != params.end() ; ++iter )
164       {
165         NamedParams::const_iterator paramIter = mCallStack[i].namedParams.find(iter->first);
166         if( paramIter == params.end() || paramIter->second.compare(iter->second) != 0 )
167         {
168           match = false;
169           break;
170         }
171       }
172       if( match == true )
173       {
174         index = i;
175         break;
176       }
177     }
178   }
179   return index;
180 }
181
182
183 /**
184  * Test if the given method and parameters are at a given index in the stack
185  * @param[in] index Index in the call stack
186  * @param[in] method Name of method to test
187  * @param[in] params A comma separated list of parameter values to test
188  */
189 bool TraceCallStack::TestMethodAndParams(int index, std::string method, std::string params) const
190 {
191   return ( 0 == mCallStack[index].method.compare(method) && 0 == mCallStack[index].paramList.compare(params) );
192 }
193
194 /**
195  * Reset the call stack
196  */
197 void TraceCallStack::Reset()
198 {
199   mCallStack.clear();
200 }
201
202
203 } // namespace Dali