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