Decode buffer from memory synchronously
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / dali-test-suite-utils / test-platform-abstraction.h
1 #ifndef __DALI_TEST_PLATFORM_ABSTRACTION_H__
2 #define __DALI_TEST_PLATFORM_ABSTRACTION_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <stdint.h>
23 #include <cstring>
24 #include <dali/public-api/images/image-operations.h>
25
26 // INTERNAL INCLUDES
27 #include <dali/devel-api/common/set-wrapper.h>
28 #include <dali/integration-api/platform-abstraction.h>
29
30 #include "test-trace-call-stack.h"
31
32
33 namespace Dali
34 {
35
36 /**
37  * Concrete implementation of the platform abstraction class.
38  */
39 class DALI_IMPORT_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
40 {
41
42 public:
43
44   struct Resources
45   {
46     bool                         loaded;
47     Integration::ResourceId      loadedId;
48     Integration::ResourceTypeId  loadedType;
49     Integration::ResourcePointer loadedResource;
50
51     bool                         loadFailed;
52     Integration::ResourceId      loadFailedId;
53     Integration::ResourceFailure loadFailure;
54   };
55
56   struct LoadFileResult
57   {
58     inline LoadFileResult()
59     : loadResult(false)
60     {
61
62     }
63
64     bool loadResult;
65     Dali::Vector< unsigned char> buffer;
66   };
67
68   /**
69    * Constructor
70    */
71   TestPlatformAbstraction();
72
73   /**
74    * Destructor
75    */
76   virtual ~TestPlatformAbstraction();
77
78   /**
79    * @copydoc PlatformAbstraction::GetTimeMicroseconds()
80    */
81   virtual void GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds);
82
83   /**
84    * @copydoc PlatformAbstraction::Suspend()
85    */
86   virtual void Suspend();
87
88   /**
89    * @copydoc PlatformAbstraction::Resume()
90    */
91   virtual void Resume();
92
93   /**
94    * @copydoc PlatformAbstraction::GetClosestImageSize()
95    */
96   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
97                                                  ImageDimensions size,
98                                                  FittingMode::Type fittingMode,
99                                                  SamplingMode::Type samplingMode,
100                                                  bool orientationCorrection );
101
102   /**
103    * @copydoc PlatformAbstraction::GetClosestImageSize()
104    */
105   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
106                                                ImageDimensions size,
107                                                FittingMode::Type fittingMode,
108                                                SamplingMode::Type samplingMode,
109                                                bool orientationCorrection );
110   /**
111    * @copydoc PlatformAbstraction::LoadResource()
112    */
113   virtual void LoadResource(const Integration::ResourceRequest& request);
114
115   /**
116    * @copydoc PlatformAbstraction::LoadResourceSynchronously()
117    */
118   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
119
120   /**
121    * @copydoc PlatformAbstraction::DecodeBuffer()
122    */
123   virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
124
125   /**
126    * @copydoc PlatformAbstraction::CancelLoad()
127    */
128   virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
129
130   /**
131    * @copydoc PlatformAbstraction::GetResources()
132    */
133   virtual void GetResources(Integration::ResourceCache& cache);
134
135   /**
136    * @copydoc PlatformAbstraction::IsLoading()
137    */
138   virtual bool IsLoading();
139
140   /**
141    * @copydoc PlatformAbstraction::GetDefaultFontDescription()
142    */
143   virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const;
144
145   /**
146    * @copydoc PlatformAbstraction::GetDefaultFontSize()
147    */
148   virtual int GetDefaultFontSize() const;
149
150   /**
151    * @copydoc PlatformAbstraction::SetDpi()
152    */
153   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
154
155   /**
156    * @copydoc PlatformAbstraction::LoadFile()
157    */
158   virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
159
160   /**
161    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
162    */
163   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer
164 ) const;
165
166   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
167
168   /**
169    * @copydoc PlatformAbstraction::SaveFile()
170    */
171   virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes) const;
172
173   virtual void JoinLoaderThreads();
174
175 public: // TEST FUNCTIONS
176
177   // Enumeration of Platform Abstraction methods
178   typedef enum
179   {
180     GetTimeMicrosecondsFunc,
181     SuspendFunc,
182     ResumeFunc,
183     LoadResourceFunc,
184     SaveFileFunc,
185     LoadFileFunc,
186     LoadShaderBinaryFileFunc,
187     SaveShaderBinaryFileFunc,
188     CancelLoadFunc,
189     GetResourcesFunc,
190     IsLoadingFunc,
191     SetDpiFunc,
192     JoinLoaderThreadsFunc,
193   } TestFuncEnum;
194
195   /** Call this every test */
196   void Initialize();
197
198   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
199   inline void ResetTrace() { mTrace.Reset(); }
200   inline TraceCallStack& GetTrace() { return mTrace; }
201
202   bool WasCalled(TestFuncEnum func);
203
204   void SetGetTimeMicrosecondsResult(size_t sec, size_t usec);
205
206   void IncrementGetTimeResult(size_t milliseconds);
207
208   void SetIsLoadingResult(bool result);
209
210   void SetGetDefaultFontFamilyResult(std::string result);
211
212   void SetGetDefaultFontSizeResult(float result);
213
214   void SetGetFontPathResult(std::string& result);
215
216   void ClearReadyResources();
217
218   void SetResourceLoaded(Integration::ResourceId  loadedId,
219                          Integration::ResourceTypeId  loadedType,
220                          Integration::ResourcePointer loadedResource);
221
222   void SetResourceLoadFailed(Integration::ResourceId  id,
223                              Integration::ResourceFailure failure);
224
225   Integration::ResourceRequest* GetRequest();
226
227   void DiscardRequest();
228
229   void SetClosestImageSize(const Vector2& size);
230
231   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
232
233   void SetSaveFileResult( bool result );
234
235 private:
236   mutable TraceCallStack        mTrace;
237   size_t                        mSeconds;
238   size_t                        mMicroSeconds;
239   bool                          mIsLoadingResult;
240   Resources                     mResources;
241   Integration::ResourceRequest* mRequest;
242   Vector2                       mSize;
243   Vector2                       mClosestSize;
244
245   LoadFileResult                mLoadFileResult;
246   bool                          mSaveFileResult;
247 };
248
249 } // Dali
250
251 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */