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