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 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
69 FittingMode::Type fittingMode,
70 SamplingMode::Type samplingMode,
71 bool orientationCorrection )
73 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
74 mTrace.PushCall("GetClosestImageSize", "");
78 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
80 FittingMode::Type fittingMode,
81 SamplingMode::Type samplingMode,
82 bool orientationCorrection )
84 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
85 mTrace.PushCall("GetClosestImageSize", "");
90 * @copydoc PlatformAbstraction::LoadResource()
92 void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
94 std::ostringstream out;
95 out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
97 mTrace.PushCall("LoadResource", out.str());
101 tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
103 mRequest = new Integration::ResourceRequest(request);
106 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
108 mTrace.PushCall("LoadResourceSynchronously", "");
109 return mResources.loadedResource;
113 * @copydoc PlatformAbstraction::CancelLoad()
115 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
117 mTrace.PushCall("CancelLoad", "");
121 * @copydoc PlatformAbstraction::GetResources()
123 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
125 mTrace.PushCall("GetResources", "");
127 if(mResources.loaded)
129 cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
131 if(mResources.loadFailed)
133 cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
138 * @copydoc PlatformAbstraction::IsLoading()
140 bool TestPlatformAbstraction::IsLoading()
142 mTrace.PushCall("IsLoading", "");
143 return mIsLoadingResult;
147 * @copydoc PlatformAbstraction::GetDefaultFontDescription()
149 void TestPlatformAbstraction::GetDefaultFontDescription( std::string& family, std::string& style ) const
155 * @copydoc PlatformAbstraction::GetDefaultFontSize()
157 int TestPlatformAbstraction::GetDefaultFontSize() const
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, Dali::Vector< unsigned char >& buffer ) const
176 mTrace.PushCall("LoadFile", "");
177 if( mLoadFileResult.loadResult )
179 buffer = mLoadFileResult.buffer;
182 return mLoadFileResult.loadResult;
186 * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
188 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
190 mTrace.PushCall("LoadShaderBinaryFile", "");
191 if( mLoadFileResult.loadResult )
193 buffer = mLoadFileResult.buffer;
196 return mLoadFileResult.loadResult;
200 * @copydoc PlatformAbstraction::SaveFile()
202 bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes) const
204 mTrace.PushCall("SaveFile", "");
208 void TestPlatformAbstraction::JoinLoaderThreads()
210 mTrace.PushCall("JoinLoaderThreads", "");
213 /** Call this every test */
214 void TestPlatformAbstraction::Initialize()
218 memset(&mResources, 0, sizeof(Resources));
221 mIsLoadingResult=false;
231 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
235 case GetTimeMicrosecondsFunc: return mTrace.FindMethod("GetTimeMicroseconds");
236 case SuspendFunc: return mTrace.FindMethod("Suspend");
237 case ResumeFunc: return mTrace.FindMethod("Resume");
238 case LoadResourceFunc: return mTrace.FindMethod("LoadResource");
239 case LoadFileFunc: return mTrace.FindMethod("LoadFile");
240 case LoadShaderBinaryFileFunc: return mTrace.FindMethod("LoadShaderBinaryFile");
241 case SaveShaderBinaryFileFunc: return mTrace.FindMethod("SaveShaderBinaryFile");
242 case SaveFileFunc: return mTrace.FindMethod("SaveFile");
243 case CancelLoadFunc: return mTrace.FindMethod("CancelLoad");
244 case GetResourcesFunc: return mTrace.FindMethod("GetResources");
245 case IsLoadingFunc: return mTrace.FindMethod("IsLoading");
246 case SetDpiFunc: return mTrace.FindMethod("SetDpi");
247 case JoinLoaderThreadsFunc: return mTrace.FindMethod("JoinLoaderThreads");
252 void TestPlatformAbstraction::SetGetTimeMicrosecondsResult(size_t sec, size_t usec)
255 mMicroSeconds = usec;
258 void TestPlatformAbstraction::IncrementGetTimeResult(size_t milliseconds)
260 mMicroSeconds += milliseconds * 1000u;
261 unsigned int additionalSeconds = mMicroSeconds / 1000000u;
263 mSeconds += additionalSeconds;
264 mMicroSeconds -= additionalSeconds * 1000000u;
267 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
269 mIsLoadingResult = result;
272 void TestPlatformAbstraction::ClearReadyResources()
274 memset(&mResources, 0, sizeof(Resources));
277 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId loadedId,
278 Integration::ResourceTypeId loadedType,
279 Integration::ResourcePointer loadedResource)
281 mResources.loaded = true;
282 mResources.loadedId = loadedId;
283 mResources.loadedType = loadedType;
284 mResources.loadedResource = loadedResource;
287 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId id,
288 Integration::ResourceFailure failure)
290 mResources.loadFailed = true;
291 mResources.loadFailedId = id;
292 mResources.loadFailure = failure;
295 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
300 void TestPlatformAbstraction::DiscardRequest()
306 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
311 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
313 mLoadFileResult.loadResult = result;
316 mLoadFileResult.buffer = buffer;
320 void TestPlatformAbstraction::SetSaveFileResult( bool result )
322 mSaveFileResult = result;