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 ),
34 mSaveFileResult( false )
39 TestPlatformAbstraction::~TestPlatformAbstraction()
43 void TestPlatformAbstraction::Suspend()
45 mTrace.PushCall("Suspend", "");
48 void TestPlatformAbstraction::Resume()
50 mTrace.PushCall("Resume", "");
53 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
55 FittingMode::Type fittingMode,
56 SamplingMode::Type samplingMode,
57 bool orientationCorrection )
59 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
60 mTrace.PushCall("GetClosestImageSize", "");
64 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
66 FittingMode::Type fittingMode,
67 SamplingMode::Type samplingMode,
68 bool orientationCorrection )
70 ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
71 mTrace.PushCall("GetClosestImageSize", "");
75 void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
77 std::ostringstream out;
78 out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
80 mTrace.PushCall("LoadResource", out.str());
84 tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
86 mRequest = new Integration::ResourceRequest(request);
89 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
91 mTrace.PushCall("LoadResourceSynchronously", "");
92 return mResources.loadedResource;
95 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
97 mTrace.PushCall("DecodeBuffer", "");
98 return Integration::BitmapPtr();
101 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
103 mTrace.PushCall("CancelLoad", "");
106 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
108 mTrace.PushCall("GetResources", "");
110 if(mResources.loaded)
112 cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
114 if(mResources.loadFailed)
116 cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
120 bool TestPlatformAbstraction::IsLoading()
122 mTrace.PushCall("IsLoading", "");
123 return mIsLoadingResult;
126 int TestPlatformAbstraction::GetDefaultFontSize() const
128 mTrace.PushCall("GetDefaultFontSize", "");
129 return mGetDefaultFontSizeResult;
132 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
134 mTrace.PushCall("SetDpi", "");
137 bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
139 mTrace.PushCall("LoadFile", "");
140 if( mLoadFileResult.loadResult )
142 buffer = mLoadFileResult.buffer;
145 return mLoadFileResult.loadResult;
148 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
150 mTrace.PushCall("LoadShaderBinaryFile", "");
151 if( mLoadFileResult.loadResult )
153 buffer = mLoadFileResult.buffer;
156 return mLoadFileResult.loadResult;
159 bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
161 mTrace.PushCall("SaveFile", "");
165 void TestPlatformAbstraction::JoinLoaderThreads()
167 mTrace.PushCall("JoinLoaderThreads", "");
170 /** Call this every test */
171 void TestPlatformAbstraction::Initialize()
175 memset(&mResources, 0, sizeof(Resources));
176 mIsLoadingResult=false;
185 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
189 case SuspendFunc: return mTrace.FindMethod("Suspend");
190 case ResumeFunc: return mTrace.FindMethod("Resume");
191 case LoadResourceFunc: return mTrace.FindMethod("LoadResource");
192 case LoadFileFunc: return mTrace.FindMethod("LoadFile");
193 case LoadShaderBinaryFileFunc: return mTrace.FindMethod("LoadShaderBinaryFile");
194 case SaveShaderBinaryFileFunc: return mTrace.FindMethod("SaveShaderBinaryFile");
195 case SaveFileFunc: return mTrace.FindMethod("SaveFile");
196 case CancelLoadFunc: return mTrace.FindMethod("CancelLoad");
197 case GetResourcesFunc: return mTrace.FindMethod("GetResources");
198 case IsLoadingFunc: return mTrace.FindMethod("IsLoading");
199 case SetDpiFunc: return mTrace.FindMethod("SetDpi");
200 case JoinLoaderThreadsFunc: return mTrace.FindMethod("JoinLoaderThreads");
205 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
207 mIsLoadingResult = result;
210 void TestPlatformAbstraction::ClearReadyResources()
212 memset(&mResources, 0, sizeof(Resources));
215 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId loadedId,
216 Integration::ResourceTypeId loadedType,
217 Integration::ResourcePointer loadedResource)
219 mResources.loaded = true;
220 mResources.loadedId = loadedId;
221 mResources.loadedType = loadedType;
222 mResources.loadedResource = loadedResource;
225 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId id,
226 Integration::ResourceFailure failure)
228 mResources.loadFailed = true;
229 mResources.loadFailedId = id;
230 mResources.loadFailure = failure;
233 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
238 void TestPlatformAbstraction::DiscardRequest()
244 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
249 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
251 mLoadFileResult.loadResult = result;
254 mLoadFileResult.buffer = buffer;
258 void TestPlatformAbstraction::SetSaveFileResult( bool result )
260 mSaveFileResult = result;