1 #ifndef __DALI_TEST_PLATFORM_ABSTRACTION_H__
2 #define __DALI_TEST_PLATFORM_ABSTRACTION_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
28 #include <dali/integration-api/platform-abstraction.h>
30 #include "test-trace-call-stack.h"
36 * Concrete implementation of the platform abstraction class.
38 class DALI_IMPORT_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
43 typedef Vector< Integration::ResourceRequest* > ResourceRequestContainer;
48 TestPlatformAbstraction();
53 virtual ~TestPlatformAbstraction();
56 * @copydoc PlatformAbstraction::Suspend()
58 virtual void Suspend();
61 * @copydoc PlatformAbstraction::Resume()
63 virtual void Resume();
66 * @copydoc PlatformAbstraction::GetClosestImageSize()
68 virtual ImageDimensions GetClosestImageSize( const std::string& filename,
70 FittingMode::Type fittingMode,
71 SamplingMode::Type samplingMode,
72 bool orientationCorrection );
75 * @copydoc PlatformAbstraction::GetClosestImageSize()
77 virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
79 FittingMode::Type fittingMode,
80 SamplingMode::Type samplingMode,
81 bool orientationCorrection );
84 * @copydoc PlatformAbstraction::LoadResource()
86 virtual void LoadResource(const Integration::ResourceRequest& request);
89 * @copydoc PlatformAbstraction::LoadResourceSynchronously()
91 virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
94 * @copydoc PlatformAbstraction::DecodeBuffer()
96 virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
99 * @copydoc PlatformAbstraction::CancelLoad()
101 virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
104 * @copydoc PlatformAbstraction::GetResources()
106 virtual void GetResources(Integration::ResourceCache& cache);
109 * @copydoc PlatformAbstraction::IsLoading()
111 virtual bool IsLoading();
114 * @copydoc PlatformAbstraction::GetDefaultFontSize()
116 virtual int GetDefaultFontSize() const;
119 * @copydoc PlatformAbstraction::SetDpi()
121 virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
124 * @copydoc PlatformAbstraction::LoadFile()
126 virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
129 * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
131 virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
134 * @copydoc PlatformAbstraction::SaveFile()
136 virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
139 * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
141 virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
143 virtual void JoinLoaderThreads();
145 public: // TEST FUNCTIONS
147 // Enumeration of Platform Abstraction methods
153 LoadResourceSynchronouslyFunc,
156 LoadShaderBinaryFileFunc,
157 SaveShaderBinaryFileFunc,
162 JoinLoaderThreadsFunc,
165 /** Call this every test */
168 inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
169 inline void ResetTrace() { mTrace.Reset(); }
170 inline TraceCallStack& GetTrace() { return mTrace; }
173 * @brief Checks if a platform function was called
174 * @param[in] func The function to check
175 * @return true if the function was called
177 bool WasCalled(TestFuncEnum func);
180 * @brief Sets the result to return when IsLoading is called by Core.
181 * @param[in] result The result to set.
183 void SetIsLoadingResult(bool result);
186 * @brief Sets the value returned by GetDefaultFontSize
187 * @param[in] result The value to return
189 void SetGetDefaultFontSizeResult(float result);
192 * @brief Clears all resource queues
194 void ClearReadyResources();
197 * @brief Sets a particular resource request as loaded.
198 * @param[in] loadedId The ResourceID of the resource that has been loaded.
199 * @param[in] loadedType The type of resource that has been loaded.
200 * @param[in] loadedResource A pointer to the resource that has been loaded.
202 void SetResourceLoaded(Integration::ResourceId loadedId,
203 Integration::ResourceTypeId loadedType,
204 Integration::ResourcePointer loadedResource);
207 * @brief Sets a particular resource request as load failure.
208 * @param[in] id The ID of the failed resource request.
209 * @param[in] failure The type of failure.
211 void SetResourceLoadFailed(Integration::ResourceId id,
212 Integration::ResourceFailure failure);
215 * @brief Retrieves the latest resource request
216 * @return A pointer to the latest resource request.
218 Integration::ResourceRequest* GetRequest();
221 * @brief Retrieves a reference to a container of all the resource requests.
222 * @return A reference to a container of all the resource requests.
224 const ResourceRequestContainer& GetAllRequests() const;
227 * @brief Sets all resource requests as loaded.
229 void SetAllResourceRequestsAsLoaded();
232 * @brief Sets all resource requests as loaded.
233 * @param[in] failure The failure type
235 void SetAllResourceRequestsAsFailed( Integration::ResourceFailure failure );
238 * @brief Discards all current resource requests.
240 void DiscardRequest();
243 * @brief Sets the value returned by GetClosestImageSize.
244 * @param[in] size The size that should be returned.
246 void SetClosestImageSize(const Vector2& size);
249 * @brief Sets the result return by LoadFile.
250 * @param[in] result The value that LoadFile should return.
251 * @param[in] buffer The buffer of the loaded file.
253 void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
256 * @brief Sets the SaveFile result
257 * @param[in] result The value that SaveFile should return
259 void SetSaveFileResult( bool result );
262 * @brief Sets the resource loaded by LoadResourceSynchronously
263 * @param[in] resource The loaded resource
265 void SetSynchronouslyLoadedResource( Integration::ResourcePointer resource );
269 struct LoadedResource
271 Integration::ResourceId id;
272 Integration::ResourceTypeId type;
273 Integration::ResourcePointer resource;
278 Integration::ResourceId id;
279 Integration::ResourceFailure failure;
282 struct LoadFileResult
284 inline LoadFileResult()
291 Dali::Vector< unsigned char> buffer;
294 typedef std::vector< LoadedResource > LoadedResourceContainer;
295 typedef std::vector< FailedLoad > FailedLoadContainer;
297 mutable TraceCallStack mTrace;
298 bool mIsLoadingResult;
299 int mGetDefaultFontSizeResult;
300 LoadedResourceContainer mLoadedResourcesQueue;
301 FailedLoadContainer mFailedLoadQueue;
302 ResourceRequestContainer mResourceRequests;
304 Vector2 mClosestSize;
306 LoadFileResult mLoadFileResult;
307 bool mSaveFileResult;
309 Integration::ResourcePointer mSynchronouslyLoadedResource;
314 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */