(Automated Tests) Use Default Scene signals in Window stub
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-adaptor.cpp
1 /*
2  * Copyright (c) 2019 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 <algorithm>
19
20 #include <toolkit-window.h>
21
22 // Don't want to include the actual window.h which otherwise will be indirectly included by adaptor.h.
23 #define DALI_WINDOW_H
24 #include <dali/integration-api/adaptors/adaptor.h>
25
26 #include <dali/integration-api/adaptors/scene-holder.h>
27
28 #include <toolkit-adaptor-impl.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/integration-api/scene.h>
31 #include <test-application.h>
32 #include <test-render-surface.h>
33
34 namespace Dali
35 {
36
37 namespace
38 {
39
40 ///////////////////////////////////////////////////////////////////////////////
41 //
42 // LogFactoryStub
43 //
44 ///////////////////////////////////////////////////////////////////////////////
45
46 class LogFactory : public LogFactoryInterface
47 {
48 public:
49   LogFactory() = default;
50   virtual ~LogFactory() = default;
51
52 private:
53   void InstallLogFunction() const override
54   {
55     Dali::Integration::Log::InstallLogFunction( &TestApplication::LogMessage );
56   }
57 };
58 LogFactory* gLogFactory = NULL; // For some reason, destroying this when the Adaptor is destroyed causes a crash in some test cases when running all of them.
59 } //unnamed namespace
60
61 namespace Internal
62 {
63 namespace Adaptor
64 {
65
66 ///////////////////////////////////////////////////////////////////////////////
67 //
68 // Dali::Internal::Adaptor::Adaptor Stub
69 //
70 ///////////////////////////////////////////////////////////////////////////////
71
72 Dali::Adaptor* gAdaptor = nullptr;
73
74 Dali::Adaptor& Adaptor::New()
75 {
76   DALI_ASSERT_ALWAYS( ! gAdaptor );
77   gAdaptor = new Dali::Adaptor;
78   return *gAdaptor;
79 }
80
81 Dali::Adaptor& Adaptor::Get()
82 {
83   DALI_ASSERT_ALWAYS( gAdaptor );
84   return *gAdaptor;
85 }
86
87 Adaptor::Adaptor()
88 {
89 }
90
91 Adaptor::~Adaptor()
92 {
93   gAdaptor = nullptr;
94 }
95
96 void Adaptor::Start( Dali::Window window )
97 {
98   if ( window )
99   {
100     mWindows.push_back( window );
101     mWindowCreatedSignal.Emit( window );
102   }
103 }
104
105 Integration::Scene Adaptor::GetScene( Dali::Window window )
106 {
107   return window.GetScene();
108 }
109
110 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
111 {
112   mCallbacks.PushBack( callback );
113   return true;
114 }
115
116 void Adaptor::RemoveIdle( CallbackBase* callback )
117 {
118   mCallbacks.Erase( std::find_if( mCallbacks.Begin(), mCallbacks.End(),
119                                   [ &callback ] ( CallbackBase* current ) { return callback == current; } ) );
120 }
121
122 void Adaptor::RunIdles()
123 {
124   for( auto& callback : mCallbacks )
125   {
126     CallbackBase::Execute( *callback );
127   }
128
129   mCallbacks.Clear();
130 }
131
132 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
133 {
134   DALI_ASSERT_ALWAYS( ! mWindows.empty() );
135
136   return reinterpret_cast < Dali::RenderSurfaceInterface& >( mWindows.front().GetRenderSurface() );
137 }
138
139 Dali::WindowContainer Adaptor::GetWindows()
140 {
141   return mWindows;
142 }
143
144 Dali::Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
145 {
146   return mResizedSignal;
147 }
148
149 Dali::Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
150 {
151   return mLanguageChangedSignal;
152 }
153
154 Dali::Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
155 {
156   return mWindowCreatedSignal;
157 }
158
159 } // namespace Adaptor
160 } // namespace Internal
161
162 ///////////////////////////////////////////////////////////////////////////////
163 //
164 // Dali::Adaptor Stub
165 //
166 ///////////////////////////////////////////////////////////////////////////////
167
168 Adaptor::Adaptor()
169 : mImpl( new Internal::Adaptor::Adaptor )
170 {
171 }
172
173 Adaptor::~Adaptor()
174 {
175   Internal::Adaptor::gAdaptor = nullptr;
176   delete mImpl;
177 }
178
179 void Adaptor::Start()
180 {
181 }
182
183 void Adaptor::Pause()
184 {
185 }
186
187 void Adaptor::Resume()
188 {
189 }
190
191 void Adaptor::Stop()
192 {
193 }
194
195 bool Adaptor::AddIdle( CallbackBase* callback, bool hasReturnValue )
196 {
197   return mImpl->AddIdle( callback, hasReturnValue );
198 }
199
200 void Adaptor::RemoveIdle( CallbackBase* callback )
201 {
202   mImpl->RemoveIdle( callback );
203 }
204
205 void Adaptor::ReplaceSurface( Window window, Dali::RenderSurfaceInterface& surface )
206 {
207 }
208
209 void Adaptor::ReplaceSurface( Dali::Integration::SceneHolder window, Dali::RenderSurfaceInterface& surface )
210 {
211 }
212
213 Adaptor::AdaptorSignalType& Adaptor::ResizedSignal()
214 {
215   return mImpl->ResizedSignal();
216 }
217
218 Adaptor::AdaptorSignalType& Adaptor::LanguageChangedSignal()
219 {
220   return mImpl->LanguageChangedSignal();
221 }
222
223 Adaptor::WindowCreatedSignalType& Adaptor::WindowCreatedSignal()
224 {
225   return mImpl->WindowCreatedSignal();
226 }
227
228 Dali::RenderSurfaceInterface& Adaptor::GetSurface()
229 {
230   return mImpl->GetSurface();
231 }
232
233 Dali::WindowContainer Adaptor::GetWindows() const
234 {
235   return mImpl->GetWindows();
236 }
237
238 Any Adaptor::GetNativeWindowHandle()
239 {
240   Any window;
241   return window;
242 }
243
244 void Adaptor::ReleaseSurfaceLock()
245 {
246 }
247
248 void Adaptor::SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender )
249 {
250 }
251
252 Adaptor& Adaptor::Get()
253 {
254   return Internal::Adaptor::Adaptor::Get();
255 }
256
257 bool Adaptor::IsAvailable()
258 {
259   return Internal::Adaptor::gAdaptor;
260 }
261
262 void Adaptor::NotifySceneCreated()
263 {
264 }
265
266 void Adaptor::NotifyLanguageChanged()
267 {
268 }
269
270 void Adaptor::FeedTouchPoint( TouchPoint& point, int timeStamp )
271 {
272 }
273
274 void Adaptor::FeedWheelEvent( WheelEvent& wheelEvent )
275 {
276 }
277
278 void Adaptor::FeedKeyEvent( KeyEvent& keyEvent )
279 {
280 }
281
282 void Adaptor::SceneCreated()
283 {
284 }
285
286 const LogFactoryInterface& Adaptor::GetLogFactory()
287 {
288   if( gLogFactory == NULL )
289   {
290     gLogFactory = new LogFactory;
291   }
292   return *gLogFactory;
293 }
294
295 } // namespace Dali