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>
25 TestPlatformAbstraction::TestPlatformAbstraction()
27 mIsLoadingResult( false ),
28 mGetDefaultFontSizeResult( 0 ),
29 mLoadedResourcesQueue(),
35 mSaveFileResult( false ),
36 mSynchronouslyLoadedResource()
41 TestPlatformAbstraction::~TestPlatformAbstraction()
45 void TestPlatformAbstraction::Suspend()
47 mTrace.PushCall("Suspend", "");
50 void TestPlatformAbstraction::Resume()
52 mTrace.PushCall("Resume", "");
55 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
57 FittingMode::Type fittingMode,
58 SamplingMode::Type samplingMode,
59 bool orientationCorrection )
61 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
62 mTrace.PushCall("GetClosestImageSize", "");
66 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
68 FittingMode::Type fittingMode,
69 SamplingMode::Type samplingMode,
70 bool orientationCorrection )
72 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
73 mTrace.PushCall("GetClosestImageSize", "");
77 void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
79 std::ostringstream out;
80 out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
82 mTrace.PushCall("LoadResource", out.str());
84 mResourceRequests.PushBack( new Integration::ResourceRequest(request) );
87 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
89 mTrace.PushCall("LoadResourceSynchronously", "");
90 return mSynchronouslyLoadedResource;
93 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
95 mTrace.PushCall("DecodeBuffer", "");
96 return mDecodedBitmap;
99 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
101 mTrace.PushCall("CancelLoad", "");
104 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
106 mTrace.PushCall("GetResources", "");
108 while( !mLoadedResourcesQueue.empty() )
110 LoadedResource loaded( *mLoadedResourcesQueue.begin() );
111 mLoadedResourcesQueue.erase( mLoadedResourcesQueue.begin() );
112 cache.LoadResponse( loaded.id, loaded.type, loaded.resource, Integration::RESOURCE_COMPLETELY_LOADED );
115 // iterate through the resources which failed to load
116 while( !mFailedLoadQueue.empty() )
118 FailedLoad failed( *mFailedLoadQueue.begin() );
119 mFailedLoadQueue.erase( mFailedLoadQueue.begin() );
120 cache.LoadFailed( failed.id, failed.failure );
124 bool TestPlatformAbstraction::IsLoading()
126 mTrace.PushCall("IsLoading", "");
127 return mIsLoadingResult;
130 int TestPlatformAbstraction::GetDefaultFontSize() const
132 mTrace.PushCall("GetDefaultFontSize", "");
133 return mGetDefaultFontSizeResult;
136 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
138 mTrace.PushCall("SetDpi", "");
141 bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
143 mTrace.PushCall("LoadFile", "");
144 if( mLoadFileResult.loadResult )
146 buffer = mLoadFileResult.buffer;
149 return mLoadFileResult.loadResult;
152 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
154 mTrace.PushCall("LoadShaderBinaryFile", "");
155 if( mLoadFileResult.loadResult )
157 buffer = mLoadFileResult.buffer;
160 return mLoadFileResult.loadResult;
163 bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
165 mTrace.PushCall("SaveFile", "");
169 void TestPlatformAbstraction::JoinLoaderThreads()
171 mTrace.PushCall("JoinLoaderThreads", "");
174 /** Call this every test */
175 void TestPlatformAbstraction::Initialize()
179 mLoadedResourcesQueue.clear();
180 mFailedLoadQueue.clear();
181 mResourceRequests.Clear();
182 mIsLoadingResult=false;
183 mSynchronouslyLoadedResource.Reset();
184 mDecodedBitmap.Reset();
187 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
191 case SuspendFunc: return mTrace.FindMethod("Suspend");
192 case ResumeFunc: return mTrace.FindMethod("Resume");
193 case LoadResourceFunc: return mTrace.FindMethod("LoadResource");
194 case LoadResourceSynchronouslyFunc: return mTrace.FindMethod("LoadResourceSynchronously");
195 case LoadFileFunc: return mTrace.FindMethod("LoadFile");
196 case LoadShaderBinaryFileFunc: return mTrace.FindMethod("LoadShaderBinaryFile");
197 case SaveShaderBinaryFileFunc: return mTrace.FindMethod("SaveShaderBinaryFile");
198 case SaveFileFunc: return mTrace.FindMethod("SaveFile");
199 case CancelLoadFunc: return mTrace.FindMethod("CancelLoad");
200 case GetResourcesFunc: return mTrace.FindMethod("GetResources");
201 case IsLoadingFunc: return mTrace.FindMethod("IsLoading");
202 case SetDpiFunc: return mTrace.FindMethod("SetDpi");
203 case JoinLoaderThreadsFunc: return mTrace.FindMethod("JoinLoaderThreads");
208 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
210 mIsLoadingResult = result;
213 void TestPlatformAbstraction::ClearReadyResources()
215 mLoadedResourcesQueue.clear();
216 mFailedLoadQueue.clear();
217 mSynchronouslyLoadedResource.Reset();
218 mDecodedBitmap.Reset();
221 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId loadedId,
222 Integration::ResourceTypeId loadedType,
223 Integration::ResourcePointer loadedResource)
225 LoadedResource loadedInfo;
226 loadedInfo.id = loadedId;
227 loadedInfo.type = loadedType;
228 loadedInfo.resource = loadedResource;
229 mLoadedResourcesQueue.push_back( loadedInfo );
232 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId id,
233 Integration::ResourceFailure failure)
235 FailedLoad failedInfo;
237 failedInfo.failure = failure;
238 mFailedLoadQueue.push_back( failedInfo );
241 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
243 Integration::ResourceRequest* request = NULL;
245 // Return last request
246 if( ! mResourceRequests.Empty() )
248 request = *( mResourceRequests.End() - 1 );
254 const TestPlatformAbstraction::ResourceRequestContainer& TestPlatformAbstraction::GetAllRequests() const
256 return mResourceRequests;
259 void TestPlatformAbstraction::SetAllResourceRequestsAsLoaded()
261 for( ResourceRequestContainer::Iterator iter = mResourceRequests.Begin(), endIter = mResourceRequests.End();
262 iter != endIter; ++iter )
264 Integration::ResourceRequest* request = *iter;
265 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
266 Integration::ResourcePointer resource(bitmap);
267 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
268 SetResourceLoaded( request->GetId(), request->GetType()->id, resource );
270 mResourceRequests.Clear();
273 void TestPlatformAbstraction::SetAllResourceRequestsAsFailed( Integration::ResourceFailure failure )
275 for( ResourceRequestContainer::Iterator iter = mResourceRequests.Begin(), endIter = mResourceRequests.End();
276 iter != endIter; ++iter )
278 SetResourceLoadFailed( (*iter)->GetId(), failure);
280 mResourceRequests.Clear();
283 void TestPlatformAbstraction::DiscardRequest()
285 mResourceRequests.Clear();
288 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
293 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
295 mLoadFileResult.loadResult = result;
298 mLoadFileResult.buffer = buffer;
302 void TestPlatformAbstraction::SetSaveFileResult( bool result )
304 mSaveFileResult = result;
307 void TestPlatformAbstraction::SetSynchronouslyLoadedResource( Integration::ResourcePointer resource )
309 mSynchronouslyLoadedResource = resource;
312 void TestPlatformAbstraction::SetDecodedBitmap( Integration::BitmapPtr bitmap )
314 mDecodedBitmap = bitmap;