20d4697cedc8c35031b4b98f88191dd8ed8433ac
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.h
1 #ifndef __DALI_TOOLKIT_TOOLKIT_ADAPTOR_H__
2 #define __DALI_TOOLKIT_TOOLKIT_ADAPTOR_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // EXTERNAL INCLUDES
21 #include <boost/function.hpp>
22
23 // INTERNAL INCLUDES
24 #include "toolkit-style-monitor.h"
25 #include "toolkit-accessibility-manager.h"
26 #include "toolkit-timer.h"
27 #include "toolkit-imf-manager.h"
28 #include "toolkit-clipboard-event-notifier.h"
29
30 #include <dali/public-api/events/touch-point.h>
31 #include <dali/public-api/math/rect.h>
32
33 namespace Dali
34 {
35
36 class Adaptor;
37
38 typedef Dali::Rect<int> PositionSize;
39
40 /**
41  * This creates a stubbed Adaptor so that internal Toolkit Adaptor calls work.
42  * Furthermore, it provides an interface to see if certain methods were invoked.
43  */
44 class ToolkitAdaptor
45 {
46 public: // Construction & Destruction
47
48   ToolkitAdaptor();
49   ~ToolkitAdaptor();
50
51 public: // Getters
52
53   boost::function<void(void)> GetLastIdleAdded() const
54   {
55     return mLastIdleAdded;
56   }
57
58   TouchPoint GetLastTouchPointFed() const
59   {
60     return mLastTouchPointFed;
61   }
62
63   int GetLastTimeStampFed() const
64   {
65     return mLastTimeStampFed;
66   }
67
68   PositionSize GetLastSizeSet() const
69   {
70     return mLastSizeSet;
71   }
72
73   StyleMonitor& GetToolkitStyleMonitor()
74   {
75     return mStyleMonitor;
76   }
77
78   AccessibilityManager& GetAccessibilityManager()
79   {
80     return mAccessibilityManager;
81   }
82
83   ToolkitClipboardEventNotifier& GetClipboardEventNotifier()
84   {
85     return mClipboardEventNotifier;
86   }
87
88 public: // Signal Emissions
89
90   void EmitSignalResize();
91
92 public: // TEST FUNCTIONS
93
94   // Enumeration of Adaptor methods
95   enum TestFuncEnum
96   {
97     StartType,
98     PauseType,
99     ResumeType,
100     StopType,
101     AddIdleType,
102     FeedEventType,
103     MoveResizeType,
104     SurfaceResizedType,
105     ReplaceSurfaceType,
106     RenderSyncType,
107     GetSurfaceType,
108     GetType,
109     IsAvailableType,
110     RegisterSingletonType,
111     GetSingletonType,
112     SignalResizeType,
113   };
114
115   void Reset()
116   {
117     mFunctionsCalled.Reset();
118   }
119
120   bool WasCalled(TestFuncEnum func)
121   {
122     switch(func)
123     {
124       case StartType:                             return mFunctionsCalled.Start;
125       case PauseType:                             return mFunctionsCalled.Pause;
126       case ResumeType:                            return mFunctionsCalled.Resume;
127       case StopType:                              return mFunctionsCalled.Stop;
128       case AddIdleType:                           return mFunctionsCalled.AddIdle;
129       case FeedEventType:                         return mFunctionsCalled.FeedEvent;
130       case MoveResizeType:                        return mFunctionsCalled.MoveResize;
131       case SurfaceResizedType:                    return mFunctionsCalled.SurfaceResized;
132       case ReplaceSurfaceType:                    return mFunctionsCalled.ReplaceSurface;
133       case RenderSyncType:                        return mFunctionsCalled.RenderSync;
134       case GetSurfaceType:                        return mFunctionsCalled.GetSurface;
135       case GetType:                               return mFunctionsCalled.Get;
136       case IsAvailableType:                       return mFunctionsCalled.IsAvailable;
137       case RegisterSingletonType:                 return mFunctionsCalled.RegisterSingleton;
138       case GetSingletonType:                      return mFunctionsCalled.GetSingleton;
139       case SignalResizeType:                      return mFunctionsCalled.SignalResize;
140     }
141     return false;
142   }
143
144   void ResetCallStatistics(TestFuncEnum func)
145   {
146     switch(func)
147     {
148       case StartType:                             mFunctionsCalled.Start = false; break;
149       case PauseType:                             mFunctionsCalled.Pause = false; break;
150       case ResumeType:                            mFunctionsCalled.Resume = false; break;
151       case StopType:                              mFunctionsCalled.Stop = false; break;
152       case AddIdleType:                           mFunctionsCalled.AddIdle = false; break;
153       case FeedEventType:                         mFunctionsCalled.FeedEvent = false; break;
154       case MoveResizeType:                        mFunctionsCalled.MoveResize = false; break;
155       case SurfaceResizedType:                    mFunctionsCalled.SurfaceResized = false; break;
156       case ReplaceSurfaceType:                    mFunctionsCalled.ReplaceSurface = false; break;
157       case RenderSyncType:                        mFunctionsCalled.RenderSync = false; break;
158       case GetSurfaceType:                        mFunctionsCalled.GetSurface = false; break;
159       case GetType:                               mFunctionsCalled.Get = false; break;
160       case IsAvailableType:                       mFunctionsCalled.IsAvailable = false; break;
161       case RegisterSingletonType:                 mFunctionsCalled.RegisterSingleton = false; break;
162       case GetSingletonType:                      mFunctionsCalled.GetSingleton = false; break;
163       case SignalResizeType:                      mFunctionsCalled.SignalResize = false; break;
164     }
165   }
166
167 private:
168
169   struct TestFunctions
170   {
171     TestFunctions()
172     : Start(false),
173       Pause(false),
174       Resume(false),
175       Stop(false),
176       AddIdle(false),
177       FeedEvent(false),
178       MoveResize(false),
179       SurfaceResized(false),
180       ReplaceSurface(false),
181       RenderSync(false),
182       GetSurface(false),
183       Get(false),
184       IsAvailable(false),
185       RegisterSingleton(false),
186       GetSingleton(false),
187       SignalResize(false)
188     {
189     }
190
191     void Reset()
192     {
193       Start = false;
194       Pause = false;
195       Resume = false;
196       Stop = false;
197       AddIdle = false;
198       FeedEvent = false;
199       MoveResize = false;
200       SurfaceResized = false;
201       ReplaceSurface = false;
202       RenderSync = false;
203       GetSurface = false;
204       Get = false;
205       IsAvailable = false;
206       RegisterSingleton = false;
207       GetSingleton = false;
208       SignalResize = false;
209     }
210
211     bool Start;
212     bool Pause;
213     bool Resume;
214     bool Stop;
215     bool AddIdle;
216     bool FeedEvent;
217     bool MoveResize;
218     bool SurfaceResized;
219     bool ReplaceSurface;
220     bool RenderSync;
221     bool GetSurface;
222     bool Get;
223     bool IsAvailable;
224     bool RegisterSingleton;
225     bool GetSingleton;
226     bool SignalResize;
227   };
228
229   TestFunctions mFunctionsCalled;
230
231   // Last set information
232   boost::function<void(void)> mLastIdleAdded;
233   TouchPoint mLastTouchPointFed;
234   int mLastTimeStampFed;
235   PositionSize mLastSizeSet;
236
237   // Contains Test functions for the Style Monitor
238   StyleMonitor mStyleMonitor;
239
240   // Stub for AccessibilityManager
241   AccessibilityManager mAccessibilityManager;
242
243   // Stub for ClipboardEventNotifier
244   ToolkitClipboardEventNotifier mClipboardEventNotifier;
245
246   ImfManager mImfManager;
247
248   // The Adaptor Stub
249   Adaptor* mAdaptorStub;
250   friend class Adaptor;
251 };
252
253 } // namespace Dali
254
255 #endif // __DALI_TOOLKIT_TOOLKIT_ADAPTOR_H__