Remove unnecessary timeDelta parameter from PostRender
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / dali-test-suite-utils / test-platform-abstraction.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-platform-abstraction.h"
19 #include "dali-test-suite-utils.h"
20 #include <dali/integration-api/bitmap.h>
21
22 namespace Dali
23 {
24
25 /**
26  * Constructor
27  */
28 TestPlatformAbstraction::TestPlatformAbstraction()
29 : mTrace(),
30   mSeconds( 0u ),
31   mMicroSeconds( 0u ),
32   mIsLoadingResult( false ),
33   mGetDefaultFontFamilyResult(),
34   mGetDefaultFontStyleResult(),
35   mGetDefaultFontSizeResult( 0 ),
36   mResources(),
37   mRequest( NULL ),
38   mSize(),
39   mClosestSize(),
40   mLoadFileResult(),
41   mSaveFileResult( false )
42 {
43   Initialize();
44 }
45
46 /**
47  * Destructor
48  */
49 TestPlatformAbstraction::~TestPlatformAbstraction()
50 {
51 }
52
53 /**
54  * @copydoc PlatformAbstraction::GetTimeMicroseconds()
55  */
56 void TestPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds)
57 {
58   seconds = mSeconds;
59   microSeconds = mMicroSeconds;
60   mTrace.PushCall("GetTimeMicroseconds", "");
61 }
62
63 /**
64  * @copydoc PlatformAbstraction::Suspend()
65  */
66 void TestPlatformAbstraction::Suspend()
67 {
68   mTrace.PushCall("Suspend", "");
69 }
70
71 /**
72  * @copydoc PlatformAbstraction::Resume()
73  */
74 void TestPlatformAbstraction::Resume()
75 {
76   mTrace.PushCall("Resume", "");
77 }
78
79 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
80                                                               ImageDimensions size,
81                                                               FittingMode::Type fittingMode,
82                                                               SamplingMode::Type samplingMode,
83                                                               bool orientationCorrection )
84 {
85   ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
86   mTrace.PushCall("GetClosestImageSize", "");
87   return closestSize;
88 }
89
90 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
91                                                    ImageDimensions size,
92                                                    FittingMode::Type fittingMode,
93                                                    SamplingMode::Type samplingMode,
94                                                    bool orientationCorrection )
95 {
96   ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
97   mTrace.PushCall("GetClosestImageSize", "");
98   return closestSize;
99 }
100
101
102 /**
103  * @copydoc PlatformAbstraction::LoadResource()
104  */
105 void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
106 {
107   std::ostringstream out;
108   out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
109
110   mTrace.PushCall("LoadResource", out.str());
111   if(mRequest != NULL)
112   {
113     delete mRequest;
114     tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
115   }
116   mRequest = new Integration::ResourceRequest(request);
117 }
118
119 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
120 {
121   mTrace.PushCall("LoadResourceSynchronously", "");
122   return mResources.loadedResource;
123 }
124
125 /**
126  * @copydoc PlatformAbstraction::CancelLoad()
127  */
128 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
129 {
130   mTrace.PushCall("CancelLoad", "");
131 }
132
133 /**
134  * @copydoc PlatformAbstraction::GetResources()
135  */
136 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
137 {
138   mTrace.PushCall("GetResources", "");
139
140   if(mResources.loaded)
141   {
142     cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
143   }
144   if(mResources.loadFailed)
145   {
146     cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
147   }
148 }
149
150 /**
151  * @copydoc PlatformAbstraction::IsLoading()
152  */
153 bool TestPlatformAbstraction::IsLoading()
154 {
155   mTrace.PushCall("IsLoading", "");
156   return mIsLoadingResult;
157 }
158
159 /**
160  * @copydoc PlatformAbstraction::GetDefaultFontDescription()
161  */
162 void TestPlatformAbstraction::GetDefaultFontDescription( std::string& family, std::string& style ) const
163 {
164   mTrace.PushCall("GetDefaultFontFamily", "");
165   family = mGetDefaultFontFamilyResult;
166   style = mGetDefaultFontStyleResult;
167 }
168
169 /**
170  * @copydoc PlatformAbstraction::GetDefaultFontSize()
171  */
172 int TestPlatformAbstraction::GetDefaultFontSize() const
173 {
174   mTrace.PushCall("GetDefaultFontSize", "");
175   return mGetDefaultFontSizeResult;
176 }
177
178 /**
179  * @copydoc PlatformAbstraction::SetDpi()
180  */
181 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
182 {
183   mTrace.PushCall("SetDpi", "");
184 }
185
186 /**
187  * @copydoc PlatformAbstraction::LoadFile()
188  */
189 bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
190 {
191   mTrace.PushCall("LoadFile", "");
192   if( mLoadFileResult.loadResult )
193   {
194     buffer = mLoadFileResult.buffer;
195   }
196
197   return mLoadFileResult.loadResult;
198 }
199
200 /**
201  * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
202  */
203 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
204 {
205   mTrace.PushCall("LoadShaderBinaryFile", "");
206   if( mLoadFileResult.loadResult )
207   {
208     buffer = mLoadFileResult.buffer;
209   }
210
211   return mLoadFileResult.loadResult;
212 }
213
214 /**
215  * @copydoc PlatformAbstraction::SaveFile()
216  */
217 bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
218 {
219   mTrace.PushCall("SaveFile", "");
220   return false;
221 }
222
223 void TestPlatformAbstraction::JoinLoaderThreads()
224 {
225   mTrace.PushCall("JoinLoaderThreads", "");
226 }
227
228 /** Call this every test */
229 void TestPlatformAbstraction::Initialize()
230 {
231   mTrace.Reset();
232   mTrace.Enable(true);
233   memset(&mResources, 0, sizeof(Resources));
234   mSeconds=0;
235   mMicroSeconds=0;
236   mIsLoadingResult=false;
237
238   if(mRequest)
239   {
240     delete mRequest;
241     mRequest = 0;
242   }
243 }
244
245 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
246 {
247   switch(func)
248   {
249     case GetTimeMicrosecondsFunc:             return mTrace.FindMethod("GetTimeMicroseconds");
250     case SuspendFunc:                         return mTrace.FindMethod("Suspend");
251     case ResumeFunc:                          return mTrace.FindMethod("Resume");
252     case LoadResourceFunc:                    return mTrace.FindMethod("LoadResource");
253     case LoadFileFunc:                        return mTrace.FindMethod("LoadFile");
254     case SaveFileFunc:                        return mTrace.FindMethod("SaveFile");
255     case CancelLoadFunc:                      return mTrace.FindMethod("CancelLoad");
256     case GetResourcesFunc:                    return mTrace.FindMethod("GetResources");
257     case IsLoadingFunc:                       return mTrace.FindMethod("IsLoading");
258     case SetDpiFunc:                          return mTrace.FindMethod("SetDpi");
259     case JoinLoaderThreadsFunc:               return mTrace.FindMethod("JoinLoaderThreads");
260   }
261   return false;
262 }
263
264 void TestPlatformAbstraction::SetGetTimeMicrosecondsResult(size_t sec, size_t usec)
265 {
266   mSeconds = sec;
267   mMicroSeconds = usec;
268 }
269
270 void TestPlatformAbstraction::IncrementGetTimeResult(size_t milliseconds)
271 {
272   mMicroSeconds += milliseconds * 1000u;
273   unsigned int additionalSeconds = mMicroSeconds / 1000000u;
274
275   mSeconds += additionalSeconds;
276   mMicroSeconds -= additionalSeconds * 1000000u;
277 }
278
279 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
280 {
281   mIsLoadingResult = result;
282 }
283
284 void TestPlatformAbstraction::ClearReadyResources()
285 {
286   memset(&mResources, 0, sizeof(Resources));
287 }
288
289 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId  loadedId,
290                                                 Integration::ResourceTypeId  loadedType,
291                                                 Integration::ResourcePointer loadedResource)
292 {
293   mResources.loaded = true;
294   mResources.loadedId = loadedId;
295   mResources.loadedType = loadedType;
296   mResources.loadedResource = loadedResource;
297 }
298
299 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId  id,
300                                                     Integration::ResourceFailure failure)
301 {
302   mResources.loadFailed = true;
303   mResources.loadFailedId = id;
304   mResources.loadFailure = failure;
305 }
306
307 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
308 {
309   return mRequest;
310 }
311
312 void TestPlatformAbstraction::DiscardRequest()
313 {
314   delete mRequest;
315   mRequest = NULL;
316 }
317
318 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
319 {
320   mClosestSize = size;
321 }
322
323 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
324 {
325   mLoadFileResult.loadResult = result;
326   if( result )
327   {
328     mLoadFileResult.buffer = buffer;
329   }
330 }
331
332 void TestPlatformAbstraction::SetSaveFileResult( bool result )
333 {
334   mSaveFileResult = result;
335 }
336
337 } // namespace Dali