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;
125 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
127 mTrace.PushCall("DecodeBuffer", "");
128 return Integration::BitmapPtr();
132 * @copydoc PlatformAbstraction::CancelLoad()
134 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
136 mTrace.PushCall("CancelLoad", "");
140 * @copydoc PlatformAbstraction::GetResources()
142 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
144 mTrace.PushCall("GetResources", "");
146 if(mResources.loaded)
148 cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
150 if(mResources.loadFailed)
152 cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
157 * @copydoc PlatformAbstraction::IsLoading()
159 bool TestPlatformAbstraction::IsLoading()
161 mTrace.PushCall("IsLoading", "");
162 return mIsLoadingResult;
166 * @copydoc PlatformAbstraction::GetDefaultFontSize()
168 int TestPlatformAbstraction::GetDefaultFontSize() const
170 mTrace.PushCall("GetDefaultFontSize", "");
171 return mGetDefaultFontSizeResult;
175 * @copydoc PlatformAbstraction::SetDpi()
177 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
179 mTrace.PushCall("SetDpi", "");
183 * @copydoc PlatformAbstraction::LoadFile()
185 bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
187 mTrace.PushCall("LoadFile", "");
188 if( mLoadFileResult.loadResult )
190 buffer = mLoadFileResult.buffer;
193 return mLoadFileResult.loadResult;
197 * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
199 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
201 mTrace.PushCall("LoadShaderBinaryFile", "");
202 if( mLoadFileResult.loadResult )
204 buffer = mLoadFileResult.buffer;
207 return mLoadFileResult.loadResult;
211 * @copydoc PlatformAbstraction::SaveFile()
213 bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
215 mTrace.PushCall("SaveFile", "");
219 void TestPlatformAbstraction::JoinLoaderThreads()
221 mTrace.PushCall("JoinLoaderThreads", "");
224 /** Call this every test */
225 void TestPlatformAbstraction::Initialize()
229 memset(&mResources, 0, sizeof(Resources));
232 mIsLoadingResult=false;
241 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
245 case GetTimeMicrosecondsFunc: return mTrace.FindMethod("GetTimeMicroseconds");
246 case SuspendFunc: return mTrace.FindMethod("Suspend");
247 case ResumeFunc: return mTrace.FindMethod("Resume");
248 case LoadResourceFunc: return mTrace.FindMethod("LoadResource");
249 case LoadFileFunc: return mTrace.FindMethod("LoadFile");
250 case SaveFileFunc: return mTrace.FindMethod("SaveFile");
251 case CancelLoadFunc: return mTrace.FindMethod("CancelLoad");
252 case GetResourcesFunc: return mTrace.FindMethod("GetResources");
253 case IsLoadingFunc: return mTrace.FindMethod("IsLoading");
254 case SetDpiFunc: return mTrace.FindMethod("SetDpi");
255 case JoinLoaderThreadsFunc: return mTrace.FindMethod("JoinLoaderThreads");
260 void TestPlatformAbstraction::SetGetTimeMicrosecondsResult(size_t sec, size_t usec)
263 mMicroSeconds = usec;
266 void TestPlatformAbstraction::IncrementGetTimeResult(size_t milliseconds)
268 mMicroSeconds += milliseconds * 1000u;
269 unsigned int additionalSeconds = mMicroSeconds / 1000000u;
271 mSeconds += additionalSeconds;
272 mMicroSeconds -= additionalSeconds * 1000000u;
275 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
277 mIsLoadingResult = result;
280 void TestPlatformAbstraction::ClearReadyResources()
282 memset(&mResources, 0, sizeof(Resources));
285 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId loadedId,
286 Integration::ResourceTypeId loadedType,
287 Integration::ResourcePointer loadedResource)
289 mResources.loaded = true;
290 mResources.loadedId = loadedId;
291 mResources.loadedType = loadedType;
292 mResources.loadedResource = loadedResource;
295 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId id,
296 Integration::ResourceFailure failure)
298 mResources.loadFailed = true;
299 mResources.loadFailedId = id;
300 mResources.loadFailure = failure;
303 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
308 void TestPlatformAbstraction::DiscardRequest()
314 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
319 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
321 mLoadFileResult.loadResult = result;
324 mLoadFileResult.buffer = buffer;
328 void TestPlatformAbstraction::SetSaveFileResult( bool result )
330 mSaveFileResult = result;