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()
37 TestPlatformAbstraction::~TestPlatformAbstraction()
42 * @copydoc PlatformAbstraction::GetTimeMicroseconds()
44 void TestPlatformAbstraction::GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds)
47 microSeconds = mMicroSeconds;
48 mTrace.PushCall("GetTimeMicroseconds", "");
52 * @copydoc PlatformAbstraction::Suspend()
54 void TestPlatformAbstraction::Suspend()
56 mTrace.PushCall("Suspend", "");
60 * @copydoc PlatformAbstraction::Resume()
62 void TestPlatformAbstraction::Resume()
64 mTrace.PushCall("Resume", "");
67 void TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
68 const ImageAttributes& attributes,
71 closestSize = mClosestSize;
72 mTrace.PushCall("GetClosestImageSize", "");
75 void TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
76 const ImageAttributes& attributes,
79 closestSize = mClosestSize;
80 mTrace.PushCall("GetClosestImageSize", "");
85 * @copydoc PlatformAbstraction::LoadResource()
87 void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
89 std::ostringstream out;
90 out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
92 mTrace.PushCall("LoadResource", out.str());
96 tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
98 mRequest = new Integration::ResourceRequest(request);
101 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
103 mTrace.PushCall("LoadResourceSynchronously", "");
104 return mResources.loadedResource;
108 * @copydoc PlatformAbstraction::SaveResource()
110 void TestPlatformAbstraction::SaveResource(const Integration::ResourceRequest& request)
112 mTrace.PushCall("SaveResource", "");
116 tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
118 mRequest = new Integration::ResourceRequest(request);
122 * @copydoc PlatformAbstraction::CancelLoad()
124 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
126 mTrace.PushCall("CancelLoad", "");
130 * @copydoc PlatformAbstraction::GetResources()
132 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
134 mTrace.PushCall("GetResources", "");
136 if(mResources.loaded)
138 cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
140 if(mResources.loadFailed)
142 cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
146 cache.SaveComplete( mResources.savedId, mResources.savedType );
148 if(mResources.saveFailed)
150 cache.SaveFailed( mResources.saveFailedId, mResources.saveFailure );
155 * @copydoc PlatformAbstraction::IsLoading()
157 bool TestPlatformAbstraction::IsLoading()
159 mTrace.PushCall("IsLoading", "");
160 return mIsLoadingResult;
164 * @copydoc PlatformAbstraction::SetDpi()
166 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
168 mTrace.PushCall("SetDpi", "");
172 * @copydoc PlatformAbstraction::LoadFile()
174 bool TestPlatformAbstraction::LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const
176 mTrace.PushCall("LoadFile", "");
177 if( mLoadFileResult.loadResult )
179 buffer = mLoadFileResult.buffer;
182 return mLoadFileResult.loadResult;
186 * @copydoc PlatformAbstraction::SaveFile()
188 bool TestPlatformAbstraction::SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const
190 mTrace.PushCall("SaveFile", "");
194 void TestPlatformAbstraction::JoinLoaderThreads()
196 mTrace.PushCall("JoinLoaderThreads", "");
199 Integration::DynamicsFactory* TestPlatformAbstraction::GetDynamicsFactory()
201 mTrace.PushCall("GetDynamicsFactory", "");
205 /** Call this every test */
206 void TestPlatformAbstraction::Initialize()
210 memset(&mResources, 0, sizeof(Resources));
213 mIsLoadingResult=false;
222 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
226 case GetTimeMicrosecondsFunc: return mTrace.FindMethod("GetTimeMicroseconds");
227 case SuspendFunc: return mTrace.FindMethod("Suspend");
228 case ResumeFunc: return mTrace.FindMethod("Resume");
229 case LoadResourceFunc: return mTrace.FindMethod("LoadResource");
230 case SaveResourceFunc: return mTrace.FindMethod("SaveResource");
231 case LoadFileFunc: return mTrace.FindMethod("LoadFile");
232 case SaveFileFunc: return mTrace.FindMethod("SaveFile");
233 case CancelLoadFunc: return mTrace.FindMethod("CancelLoad");
234 case GetResourcesFunc: return mTrace.FindMethod("GetResources");
235 case IsLoadingFunc: return mTrace.FindMethod("IsLoading");
236 case SetDpiFunc: return mTrace.FindMethod("SetDpi");
237 case JoinLoaderThreadsFunc: return mTrace.FindMethod("JoinLoaderThreads");
238 case GetDynamicsFactoryFunc: return mTrace.FindMethod("GetDynamicsFactory");
243 void TestPlatformAbstraction::SetGetTimeMicrosecondsResult(size_t sec, size_t usec)
246 mMicroSeconds = usec;
249 void TestPlatformAbstraction::IncrementGetTimeResult(size_t milliseconds)
251 mMicroSeconds += milliseconds * 1000u;
252 unsigned int additionalSeconds = mMicroSeconds / 1000000u;
254 mSeconds += additionalSeconds;
255 mMicroSeconds -= additionalSeconds * 1000000u;
258 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
260 mIsLoadingResult = result;
263 void TestPlatformAbstraction::ClearReadyResources()
265 memset(&mResources, 0, sizeof(Resources));
268 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId loadedId,
269 Integration::ResourceTypeId loadedType,
270 Integration::ResourcePointer loadedResource)
272 mResources.loaded = true;
273 mResources.loadedId = loadedId;
274 mResources.loadedType = loadedType;
275 mResources.loadedResource = loadedResource;
278 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId id,
279 Integration::ResourceFailure failure)
281 mResources.loadFailed = true;
282 mResources.loadFailedId = id;
283 mResources.loadFailure = failure;
286 void TestPlatformAbstraction::SetResourceSaved(Integration::ResourceId savedId,
287 Integration::ResourceTypeId savedType)
289 mResources.saved = true;
290 mResources.savedId = savedId;
291 mResources.savedType = savedType;
294 void TestPlatformAbstraction::SetResourceSaveFailed(Integration::ResourceId id,
295 Integration::ResourceFailure failure)
297 mResources.saveFailed = true;
298 mResources.saveFailedId = id;
299 mResources.saveFailure = failure;
302 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
307 void TestPlatformAbstraction::DiscardRequest()
313 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
318 void TestPlatformAbstraction::SetLoadFileResult( bool result, std::vector< unsigned char >& buffer )
320 mLoadFileResult.loadResult = result;
323 mLoadFileResult.buffer = buffer;
327 void TestPlatformAbstraction::SetSaveFileResult( bool result )
329 mSaveFileResult = result;