fc667015ab1c18a3d6a0c602e9486fd8d615b250
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / 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 <string>
25
26 // INTERNAL INCLUDES
27 #include <dali/integration-api/platform-abstraction.h>
28
29 #include "test-trace-call-stack.h"
30
31 namespace Dali
32 {
33
34 /**
35  * Concrete implementation of the platform abstraction class.
36  */
37 class DALI_IMPORT_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
38 {
39
40 public:
41
42   struct Resources
43   {
44     bool                         loaded;
45     Integration::ResourceId      loadedId;
46     Integration::ResourceTypeId  loadedType;
47     Integration::ResourcePointer loadedResource;
48
49     bool                         loadFailed;
50     Integration::ResourceId      loadFailedId;
51     Integration::ResourceFailure loadFailure;
52
53     bool                         saved;
54     Integration::ResourceId      savedId;
55     Integration::ResourceTypeId  savedType;
56
57     bool                         saveFailed;
58     Integration::ResourceId      saveFailedId;
59     Integration::ResourceFailure saveFailure;
60   };
61
62   struct LoadFileResult
63   {
64     inline LoadFileResult()
65     : loadResult(false)
66     {
67
68     }
69
70     bool loadResult;
71     Dali::Vector< unsigned char> buffer;
72   };
73
74   /**
75    * Constructor
76    */
77   TestPlatformAbstraction();
78
79   /**
80    * Destructor
81    */
82   virtual ~TestPlatformAbstraction();
83
84   /**
85    * @copydoc PlatformAbstraction::GetTimeMicroseconds()
86    */
87   virtual void GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds);
88
89   /**
90    * @copydoc PlatformAbstraction::Suspend()
91    */
92   virtual void Suspend();
93
94   /**
95    * @copydoc PlatformAbstraction::Resume()
96    */
97   virtual void Resume();
98
99   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
100                                                  ImageDimensions size,
101                                                  FittingMode::Type fittingMode,
102                                                  SamplingMode::Type samplingMode,
103                                                  bool orientationCorrection );
104
105   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
106                                                ImageDimensions size,
107                                                FittingMode::Type fittingMode,
108                                                SamplingMode::Type samplingMode,
109                                                bool orientationCorrection );
110
111   /**
112    * @copydoc PlatformAbstraction::LoadResource()
113    */
114   virtual void LoadResource(const Integration::ResourceRequest& request);
115
116   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
117
118   /**
119    * @copydoc PlatformAbstraction::SaveResource()
120    */
121   virtual void SaveResource(const Integration::ResourceRequest& request);
122
123   /**
124    * @copydoc PlatformAbstraction::CancelLoad()
125    */
126   virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
127
128   /**
129    * @copydoc PlatformAbstraction::GetResources()
130    */
131   virtual void GetResources(Integration::ResourceCache& cache);
132
133   /**
134    * @copydoc PlatformAbstraction::IsLoading()
135    */
136   virtual bool IsLoading();
137
138   /**
139    * @copydoc PlatformAbstraction::GetDefaultFontFamily()
140    */
141   virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const;
142
143   /**
144    * @copydoc PlatformAbstraction::GetDefaultFontSize()
145    */
146   virtual int GetDefaultFontSize() const;
147
148   /**
149    * @copydoc PlatformAbstraction::SetDpi()
150    */
151   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
152
153   /**
154    * @copydoc PlatformAbstraction::LoadFile()
155    */
156   virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
157
158   /**
159    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
160    */
161   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
162
163   /**
164    * @copydoc PlatformAbstraction::SaveFile()
165    */
166   virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
167
168  /**
169   * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
170   */
171   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return false; }
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     SaveResourceFunc,
185     SaveFileFunc,
186     LoadFileFunc,
187     CancelLoadFunc,
188     GetResourcesFunc,
189     IsLoadingFunc,
190     SetDpiFunc,
191     JoinLoaderThreadsFunc,
192   } TestFuncEnum;
193
194   /** Call this every test */
195   void Initialize();
196
197   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
198   inline void ResetTrace() { mTrace.Reset(); }
199   inline TraceCallStack& GetTrace() { return mTrace; }
200
201   bool WasCalled(TestFuncEnum func);
202
203   void SetGetTimeMicrosecondsResult(size_t sec, size_t usec);
204
205   void IncrementGetTimeResult(size_t milliseconds);
206
207   void SetIsLoadingResult(bool result);
208
209   void ClearReadyResources();
210
211   void SetResourceLoaded(Integration::ResourceId  loadedId,
212                          Integration::ResourceTypeId  loadedType,
213                          Integration::ResourcePointer loadedResource);
214
215   void SetResourceLoadFailed(Integration::ResourceId  id,
216                              Integration::ResourceFailure failure);
217
218   void SetResourceSaved(Integration::ResourceId      savedId,
219                         Integration::ResourceTypeId  savedType);
220
221   void SetResourceSaveFailed(Integration::ResourceId  id,
222                              Integration::ResourceFailure failure);
223
224   Integration::ResourceRequest* GetRequest();
225
226   void DiscardRequest();
227
228   void SetClosestImageSize(const Vector2& size);
229
230   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
231
232   void SetSaveFileResult( bool result );
233
234 private:
235   mutable TraceCallStack        mTrace;
236   size_t                        mSeconds;
237   size_t                        mMicroSeconds;
238   bool                          mIsLoadingResult;
239   std::string                   mGetDefaultFontFamilyResult;
240   std::string                   mGetDefaultFontStyleResult;
241   int                           mGetDefaultFontSizeResult;
242   Resources                     mResources;
243   Integration::ResourceRequest* mRequest;
244   Vector2                       mSize;
245   Vector2                       mClosestSize;
246
247   LoadFileResult                mLoadFileResult;
248   bool                          mSaveFileResult;
249 };
250
251 } // Dali
252
253 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */