[dali_1.1.40] Merge branch 'devel/master'
[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) 2014 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 <string>
22 #include <vector>
23 #include <map>
24
25 namespace Dali
26 {
27 std::string ToString(int x);
28 std::string ToString(unsigned int x);
29 std::string ToString(float x);
30
31 /**
32  * Helper class to track method calls in the abstraction and search for them in test cases
33  */
34 class TraceCallStack
35 {
36 public:
37   /// Typedef for passing and storing named parameters
38   typedef std::map< std::string, std::string > NamedParams;
39
40   /**
41    * Constructor
42    */
43   TraceCallStack();
44
45   /**
46    * Destructor
47    */
48   ~TraceCallStack();
49
50   /**
51    * Turn on / off tracing
52    */
53   void Enable(bool enable);
54
55   bool IsEnabled();
56
57   /**
58    * Push a call onto the stack if the trace is active
59    * @param[in] method The name of the method
60    * @param[in] params A comma separated list of parameter values
61    */
62   void PushCall(std::string method, std::string params);
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    * @param[in] altParams A map of named parameter values
69    */
70   void PushCall(std::string method, std::string params, const NamedParams& altParams);
71
72   /**
73    * Search for a method in the stack
74    * @param[in] method The name of the method
75    * @return true if the method was in the stack
76    */
77   bool FindMethod(std::string method) const;
78
79   /**
80    * Count how many times a method was called
81    * @param[in] method The name of the method
82    * @return The number of times it was called
83    */
84   int CountMethod(std::string method) const;
85
86   /**
87    * Search for a method in the stack with the given parameter list
88    * @param[in] method The name of the method
89    * @param[in] params A comma separated list of parameter values
90    * @return true if the method was in the stack
91    */
92   bool FindMethodAndParams(std::string method, std::string params) const;
93
94   /**
95    * Search for a method in the stack with the given parameter list
96    * @param[in] method The name of the method
97    * @param[in] params A map of named parameters to test for
98    * @return true if the method was in the stack
99    */
100   bool FindMethodAndParams(std::string method, const NamedParams& params) const;
101
102   /**
103    * Search for a method in the stack with the given parameter list
104    * @param[in] method The name of the method
105    * @param[in] params A comma separated list of parameter values
106    * @return index in the stack where the method was found or -1 otherwise
107    */
108   int FindIndexFromMethodAndParams(std::string method, std::string params) const;
109
110   /**
111    * Search for a method in the stack with the given parameter list
112    * @param[in] method The name of the method
113    * @param[in] params A map of named parameter values to match
114    * @return index in the stack where the method was found or -1 otherwise
115    */
116   int FindIndexFromMethodAndParams(std::string method, const NamedParams& params) const;
117
118   /**
119    * Test if the given method and parameters are at a given index in the stack
120    * @param[in] index Index in the call stack
121    * @param[in] method Name of method to test
122    * @param[in] params A comma separated list of parameter values to test
123    */
124   bool TestMethodAndParams(int index, std::string method, std::string params) const;
125
126   /**
127    * Reset the call stack
128    */
129   void Reset();
130
131 private:
132   bool mTraceActive; ///< True if the trace is active
133
134   struct FunctionCall
135   {
136     std::string method;
137     std::string paramList;
138     NamedParams namedParams;
139     FunctionCall( const std::string& aMethod, const std::string& aParamList )
140     : method( aMethod ), paramList( aParamList )
141     {
142     }
143     FunctionCall( const std::string& aMethod, const std::string& aParamList, const NamedParams& altParams )
144     : method( aMethod ), paramList( aParamList ), namedParams( altParams )
145     {
146     }
147   };
148
149   std::vector< FunctionCall > mCallStack; ///< The call stack
150 };
151
152 } // namespace dali
153
154 #endif //__TEST_TRACE_CALL_STACK_H__