Add some properties into web view
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-trace-call-stack.h
1 #ifndef TEST_TRACE_CALL_STACK_H
2 #define TEST_TRACE_CALL_STACK_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 #include <map>
22 #include <sstream>
23 #include <string>
24 #include <vector>
25
26 namespace Dali
27 {
28 template<typename T>
29 std::string ToString(const T& x)
30 {
31   return "undefined";
32 }
33
34 std::string ToString(int x);
35 std::string ToString(unsigned int x);
36 std::string ToString(float x);
37
38 /**
39  * Helper class to track method calls in the abstraction and search for them in test cases
40  */
41 class TraceCallStack
42 {
43 public:
44   /// Typedef for passing and storing named parameters
45   typedef std::map<std::string, std::string> NamedParams;
46
47   /**
48    * Constructor
49    */
50   TraceCallStack();
51
52   /**
53    * Destructor
54    */
55   ~TraceCallStack();
56
57   /**
58    * Turn on / off tracing
59    */
60   void Enable(bool enable);
61
62   bool IsEnabled();
63
64   /**
65    * Push a call onto the stack if the trace is active
66    * @param[in] method The name of the method
67    * @param[in] params A comma separated list of parameter values
68    */
69   void PushCall(std::string method, std::string params);
70
71   /**
72    * Push a call onto the stack if the trace is active
73    * @param[in] method The name of the method
74    * @param[in] params A comma separated list of parameter values
75    * @param[in] altParams A map of named parameter values
76    */
77   void PushCall(std::string method, std::string params, const NamedParams& altParams);
78
79   /**
80    * Search for a method in the stack
81    * @param[in] method The name of the method
82    * @return true if the method was in the stack
83    */
84   bool FindMethod(std::string method) const;
85
86   /**
87    * Search for a method in the stack and return its parameters if found
88    * @param[in] method The name of the method
89    * @param[out] params of the method
90    * @return true if the method was in the stack
91    */
92   bool FindMethodAndGetParameters(std::string method, std::string& params) const;
93
94   /**
95    * Count how many times a method was called
96    * @param[in] method The name of the method
97    * @return The number of times it was called
98    */
99   int CountMethod(std::string method) const;
100
101   /**
102    * Search for a method in the stack with the given parameter list
103    * @param[in] method The name of the method
104    * @param[in] params A comma separated list of parameter values
105    * @return true if the method was in the stack
106    */
107   bool FindMethodAndParams(std::string method, std::string params) const;
108
109   /**
110    * Search for a method in the stack with the given parameter list
111    * @param[in] method The name of the method
112    * @param[in] params A map of named parameters to test for
113    * @return true if the method was in the stack
114    */
115   bool FindMethodAndParams(std::string method, const NamedParams& params) const;
116
117   /**
118    * Search for a method in the stack with the given parameter list.
119    * The search is done from a given index.
120    * This allows the order of methods and parameters to be checked.
121    * @param[in] method The name of the method
122    * @param[in] params A comma separated list of parameter values
123    * @param[in/out] startIndex The method index to start looking from.
124    *                This is updated if a method is found so subsequent
125    *                calls can search for methods occuring after this one.
126    * @return True if the method was in the stack
127    */
128   bool FindMethodAndParamsFromStartIndex(std::string method, std::string params, size_t& startIndex) const;
129
130   /**
131    * Search for a method in the stack with the given parameter list
132    * @param[in] method The name of the method
133    * @param[in] params A comma separated list of parameter values
134    * @return index in the stack where the method was found or -1 otherwise
135    */
136   int FindIndexFromMethodAndParams(std::string method, std::string params) const;
137
138   /**
139    * Search for a method in the stack with the given parameter list
140    * @param[in] method The name of the method
141    * @param[in] params A map of named parameter values to match
142    * @return index in the stack where the method was found or -1 otherwise
143    */
144   int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const;
145
146   /**
147    * Test if the given method and parameters are at a given index in the stack
148    * @param[in] index Index in the call stack
149    * @param[in] method Name of method to test
150    * @param[in] params A comma separated list of parameter values to test
151    */
152   bool TestMethodAndParams(int index, std::string method, std::string params) const;
153
154   /**
155    * Reset the call stack
156    */
157   void Reset();
158
159   /**
160    * Method to display contents of the TraceCallStack.
161    * @return A string containing a list of function calls and parameters (may contain newline characters)
162    */
163   std::string GetTraceString()
164   {
165     std::stringstream traceStream;
166     std::size_t       functionCount = mCallStack.size();
167     for(std::size_t i = 0; i < functionCount; ++i)
168     {
169       Dali::TraceCallStack::FunctionCall functionCall = mCallStack[i];
170       traceStream << "StackTrace: Index:" << i << ",  Function:" << functionCall.method << ",  ParamList:" << functionCall.paramList << std::endl;
171     }
172
173     return traceStream.str();
174   }
175
176 private:
177   bool mTraceActive; ///< True if the trace is active
178
179   struct FunctionCall
180   {
181     std::string method;
182     std::string paramList;
183     NamedParams namedParams;
184     FunctionCall(const std::string& aMethod, const std::string& aParamList)
185     : method(aMethod),
186       paramList(aParamList)
187     {
188     }
189     FunctionCall(const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams)
190     : method(aMethod),
191       paramList(aParamList),
192       namedParams(altParams)
193     {
194     }
195   };
196
197   std::vector<FunctionCall> mCallStack; ///< The call stack
198 };
199
200 } // namespace Dali
201
202 #endif // TEST_TRACE_CALL_STACK_H