Merge "Changed RendererAttachment to use blend flag from RenderDataProvider rather...
[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 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
126 {
127   mTrace.PushCall("DecodeBuffer", "");
128   return Integration::BitmapPtr();
129 }
130
131 /**
132  * @copydoc PlatformAbstraction::CancelLoad()
133  */
134 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
135 {
136   mTrace.PushCall("CancelLoad", "");
137 }
138
139 /**
140  * @copydoc PlatformAbstraction::GetResources()
141  */
142 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
143 {
144   mTrace.PushCall("GetResources", "");
145
146   if(mResources.loaded)
147   {
148     cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
149   }
150   if(mResources.loadFailed)
151   {
152     cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
153   }
154 }
155
156 /**
157  * @copydoc PlatformAbstraction::IsLoading()
158  */
159 bool TestPlatformAbstraction::IsLoading()
160 {
161   mTrace.PushCall("IsLoading", "");
162   return mIsLoadingResult;
163 }
164
165 /**
166  * @copydoc PlatformAbstraction::GetDefaultFontDescription()
167  */
168 void TestPlatformAbstraction::GetDefaultFontDescription( std::string& family, std::string& style ) const
169 {
170   mTrace.PushCall("GetDefaultFontFamily", "");
171   family = mGetDefaultFontFamilyResult;
172   style = mGetDefaultFontStyleResult;
173 }
174
175 /**
176  * @copydoc PlatformAbstraction::GetDefaultFontSize()
177  */
178 int TestPlatformAbstraction::GetDefaultFontSize() const
179 {
180   mTrace.PushCall("GetDefaultFontSize", "");
181   return mGetDefaultFontSizeResult;
182 }
183
184 /**
185  * @copydoc PlatformAbstraction::SetDpi()
186  */
187 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
188 {
189   mTrace.PushCall("SetDpi", "");
190 }
191
192 /**
193  * @copydoc PlatformAbstraction::LoadFile()
194  */
195 bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
196 {
197   mTrace.PushCall("LoadFile", "");
198   if( mLoadFileResult.loadResult )
199   {
200     buffer = mLoadFileResult.buffer;
201   }
202
203   return mLoadFileResult.loadResult;
204 }
205
206 /**
207  * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
208  */
209 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
210 {
211   mTrace.PushCall("LoadShaderBinaryFile", "");
212   if( mLoadFileResult.loadResult )
213   {
214     buffer = mLoadFileResult.buffer;
215   }
216
217   return mLoadFileResult.loadResult;
218 }
219
220 /**
221  * @copydoc PlatformAbstraction::SaveFile()
222  */
223 bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
224 {
225   mTrace.PushCall("SaveFile", "");
226   return false;
227 }
228
229 void TestPlatformAbstraction::JoinLoaderThreads()
230 {
231   mTrace.PushCall("JoinLoaderThreads", "");
232 }
233
234 /** Call this every test */
235 void TestPlatformAbstraction::Initialize()
236 {
237   mTrace.Reset();
238   mTrace.Enable(true);
239   memset(&mResources, 0, sizeof(Resources));
240   mSeconds=0;
241   mMicroSeconds=0;
242   mIsLoadingResult=false;
243
244   if(mRequest)
245   {
246     delete mRequest;
247     mRequest = 0;
248   }
249 }
250
251 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
252 {
253   switch(func)
254   {
255     case GetTimeMicrosecondsFunc:             return mTrace.FindMethod("GetTimeMicroseconds");
256     case SuspendFunc:                         return mTrace.FindMethod("Suspend");
257     case ResumeFunc:                          return mTrace.FindMethod("Resume");
258     case LoadResourceFunc:                    return mTrace.FindMethod("LoadResource");
259     case LoadFileFunc:                        return mTrace.FindMethod("LoadFile");
260     case SaveFileFunc:                        return mTrace.FindMethod("SaveFile");
261     case CancelLoadFunc:                      return mTrace.FindMethod("CancelLoad");
262     case GetResourcesFunc:                    return mTrace.FindMethod("GetResources");
263     case IsLoadingFunc:                       return mTrace.FindMethod("IsLoading");
264     case SetDpiFunc:                          return mTrace.FindMethod("SetDpi");
265     case JoinLoaderThreadsFunc:               return mTrace.FindMethod("JoinLoaderThreads");
266   }
267   return false;
268 }
269
270 void TestPlatformAbstraction::SetGetTimeMicrosecondsResult(size_t sec, size_t usec)
271 {
272   mSeconds = sec;
273   mMicroSeconds = usec;
274 }
275
276 void TestPlatformAbstraction::IncrementGetTimeResult(size_t milliseconds)
277 {
278   mMicroSeconds += milliseconds * 1000u;
279   unsigned int additionalSeconds = mMicroSeconds / 1000000u;
280
281   mSeconds += additionalSeconds;
282   mMicroSeconds -= additionalSeconds * 1000000u;
283 }
284
285 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
286 {
287   mIsLoadingResult = result;
288 }
289
290 void TestPlatformAbstraction::ClearReadyResources()
291 {
292   memset(&mResources, 0, sizeof(Resources));
293 }
294
295 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId  loadedId,
296                                                 Integration::ResourceTypeId  loadedType,
297                                                 Integration::ResourcePointer loadedResource)
298 {
299   mResources.loaded = true;
300   mResources.loadedId = loadedId;
301   mResources.loadedType = loadedType;
302   mResources.loadedResource = loadedResource;
303 }
304
305 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId  id,
306                                                     Integration::ResourceFailure failure)
307 {
308   mResources.loadFailed = true;
309   mResources.loadFailedId = id;
310   mResources.loadFailure = failure;
311 }
312
313 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
314 {
315   return mRequest;
316 }
317
318 void TestPlatformAbstraction::DiscardRequest()
319 {
320   delete mRequest;
321   mRequest = NULL;
322 }
323
324 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
325 {
326   mClosestSize = size;
327 }
328
329 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
330 {
331   mLoadFileResult.loadResult = result;
332   if( result )
333   {
334     mLoadFileResult.buffer = buffer;
335   }
336 }
337
338 void TestPlatformAbstraction::SetSaveFileResult( bool result )
339 {
340   mSaveFileResult = result;
341 }
342
343 } // namespace Dali