2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "test-platform-abstraction.h"
19 #include "dali-test-suite-utils.h"
20 #include <dali/integration-api/bitmap.h>
28 TestPlatformAbstraction::TestPlatformAbstraction()
32 mIsLoadingResult( false ),
33 mGetDefaultFontFamilyResult(),
34 mGetDefaultFontStyleResult(),
35 mGetDefaultFontSizeResult( 0 ),
41 mSaveFileResult( false )
49 TestPlatformAbstraction::~TestPlatformAbstraction()
54 * @copydoc PlatformAbstraction::GetTimeMicroseconds()
56 void TestPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds)
59 microSeconds = mMicroSeconds;
60 mTrace.PushCall("GetTimeMicroseconds", "");
64 * @copydoc PlatformAbstraction::Suspend()
66 void TestPlatformAbstraction::Suspend()
68 mTrace.PushCall("Suspend", "");
72 * @copydoc PlatformAbstraction::Resume()
74 void TestPlatformAbstraction::Resume()
76 mTrace.PushCall("Resume", "");
79 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
81 FittingMode::Type fittingMode,
82 SamplingMode::Type samplingMode,
83 bool orientationCorrection )
85 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
86 mTrace.PushCall("GetClosestImageSize", "");
90 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
92 FittingMode::Type fittingMode,
93 SamplingMode::Type samplingMode,
94 bool orientationCorrection )
96 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
97 mTrace.PushCall("GetClosestImageSize", "");
103 * @copydoc PlatformAbstraction::LoadResource()
105 void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
107 std::ostringstream out;
108 out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
110 mTrace.PushCall("LoadResource", out.str());
114 tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
116 mRequest = new Integration::ResourceRequest(request);
119 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
121 mTrace.PushCall("LoadResourceSynchronously", "");
122 return mResources.loadedResource;
126 * @copydoc PlatformAbstraction::SaveResource()
128 void TestPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request)
130 mTrace.PushCall("SaveResource", "");
134 tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
136 mRequest = new Integration::ResourceRequest(request);
140 * @copydoc PlatformAbstraction::CancelLoad()
142 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
144 mTrace.PushCall("CancelLoad", "");
148 * @copydoc PlatformAbstraction::GetResources()
150 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
152 mTrace.PushCall("GetResources", "");
154 if(mResources.loaded)
156 cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
158 if(mResources.loadFailed)
160 cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
164 cache.SaveComplete( mResources.savedId, mResources.savedType );
166 if(mResources.saveFailed)
168 cache.SaveFailed( mResources.saveFailedId, mResources.saveFailure );
173 * @copydoc PlatformAbstraction::IsLoading()
175 bool TestPlatformAbstraction::IsLoading()
177 mTrace.PushCall("IsLoading", "");
178 return mIsLoadingResult;
182 * @copydoc PlatformAbstraction::GetDefaultFontDescription()
184 void TestPlatformAbstraction::GetDefaultFontDescription( std::string& family, std::string& style ) const
186 mTrace.PushCall("GetDefaultFontFamily", "");
187 family = mGetDefaultFontFamilyResult;
188 style = mGetDefaultFontStyleResult;
192 * @copydoc PlatformAbstraction::GetDefaultFontSize()
194 int TestPlatformAbstraction::GetDefaultFontSize() const
196 mTrace.PushCall("GetDefaultFontSize", "");
197 return mGetDefaultFontSizeResult;
201 * @copydoc PlatformAbstraction::SetDpi()
203 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
205 mTrace.PushCall("SetDpi", "");
209 * @copydoc PlatformAbstraction::LoadFile()
211 bool TestPlatformAbstraction::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
213 mTrace.PushCall("LoadFile", "");
214 if( mLoadFileResult.loadResult )
216 buffer = mLoadFileResult.buffer;
219 return mLoadFileResult.loadResult;
223 * @copydoc PlatformAbstraction::LoadShaderBinFile()
225 bool TestPlatformAbstraction::LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
227 mTrace.PushCall("LoadShaderBinFile", "");
228 if( mLoadFileResult.loadResult )
230 buffer = mLoadFileResult.buffer;
233 return mLoadFileResult.loadResult;
237 * @copydoc PlatformAbstraction::SaveFile()
239 bool TestPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const
241 mTrace.PushCall("SaveFile", "");
245 void TestPlatformAbstraction::JoinLoaderThreads()
247 mTrace.PushCall("JoinLoaderThreads", "");
250 /** Call this every test */
251 void TestPlatformAbstraction::Initialize()
255 memset(&mResources, 0, sizeof(Resources));
258 mIsLoadingResult=false;
267 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
271 case GetTimeMicrosecondsFunc: return mTrace.FindMethod("GetTimeMicroseconds");
272 case SuspendFunc: return mTrace.FindMethod("Suspend");
273 case ResumeFunc: return mTrace.FindMethod("Resume");
274 case LoadResourceFunc: return mTrace.FindMethod("LoadResource");
275 case SaveResourceFunc: return mTrace.FindMethod("SaveResource");
276 case LoadFileFunc: return mTrace.FindMethod("LoadFile");
277 case SaveFileFunc: return mTrace.FindMethod("SaveFile");
278 case CancelLoadFunc: return mTrace.FindMethod("CancelLoad");
279 case GetResourcesFunc: return mTrace.FindMethod("GetResources");
280 case IsLoadingFunc: return mTrace.FindMethod("IsLoading");
281 case SetDpiFunc: return mTrace.FindMethod("SetDpi");
282 case JoinLoaderThreadsFunc: return mTrace.FindMethod("JoinLoaderThreads");
287 void TestPlatformAbstraction::SetGetTimeMicrosecondsResult(size_t sec, size_t usec)
290 mMicroSeconds = usec;
293 void TestPlatformAbstraction::IncrementGetTimeResult(size_t milliseconds)
295 mMicroSeconds += milliseconds * 1000u;
296 unsigned int additionalSeconds = mMicroSeconds / 1000000u;
298 mSeconds += additionalSeconds;
299 mMicroSeconds -= additionalSeconds * 1000000u;
302 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
304 mIsLoadingResult = result;
307 void TestPlatformAbstraction::ClearReadyResources()
309 memset(&mResources, 0, sizeof(Resources));
312 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId loadedId,
313 Integration::ResourceTypeId loadedType,
314 Integration::ResourcePointer loadedResource)
316 mResources.loaded = true;
317 mResources.loadedId = loadedId;
318 mResources.loadedType = loadedType;
319 mResources.loadedResource = loadedResource;
322 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId id,
323 Integration::ResourceFailure failure)
325 mResources.loadFailed = true;
326 mResources.loadFailedId = id;
327 mResources.loadFailure = failure;
330 void TestPlatformAbstraction::SetResourceSaved(Integration::ResourceId savedId,
331 Integration::ResourceTypeId savedType)
333 mResources.saved = true;
334 mResources.savedId = savedId;
335 mResources.savedType = savedType;
338 void TestPlatformAbstraction::SetResourceSaveFailed(Integration::ResourceId id,
339 Integration::ResourceFailure failure)
341 mResources.saveFailed = true;
342 mResources.saveFailedId = id;
343 mResources.saveFailure = failure;
346 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
351 void TestPlatformAbstraction::DiscardRequest()
357 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
362 void TestPlatformAbstraction::SetLoadFileResult( bool result, std::vector< unsigned char >& buffer )
364 mLoadFileResult.loadResult = result;
367 mLoadFileResult.buffer = buffer;
371 void TestPlatformAbstraction::SetSaveFileResult( bool result )
373 mSaveFileResult = result;