[dali_1.1.5] Merge branch 'devel/master'
[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::GetDefaultFontSize()
142    */
143   virtual int GetDefaultFontSize() const;
144
145   /**
146    * @copydoc PlatformAbstraction::SetDpi()
147    */
148   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
149
150   /**
151    * @copydoc PlatformAbstraction::LoadFile()
152    */
153   virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
154
155   /**
156    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
157    */
158   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer
159 ) const;
160
161   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
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   virtual void JoinLoaderThreads();
169
170 public: // TEST FUNCTIONS
171
172   // Enumeration of Platform Abstraction methods
173   typedef enum
174   {
175     GetTimeMicrosecondsFunc,
176     SuspendFunc,
177     ResumeFunc,
178     LoadResourceFunc,
179     SaveFileFunc,
180     LoadFileFunc,
181     LoadShaderBinaryFileFunc,
182     SaveShaderBinaryFileFunc,
183     CancelLoadFunc,
184     GetResourcesFunc,
185     IsLoadingFunc,
186     SetDpiFunc,
187     JoinLoaderThreadsFunc,
188   } TestFuncEnum;
189
190   /** Call this every test */
191   void Initialize();
192
193   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
194   inline void ResetTrace() { mTrace.Reset(); }
195   inline TraceCallStack& GetTrace() { return mTrace; }
196
197   bool WasCalled(TestFuncEnum func);
198
199   void SetGetTimeMicrosecondsResult(size_t sec, size_t usec);
200
201   void IncrementGetTimeResult(size_t milliseconds);
202
203   void SetIsLoadingResult(bool result);
204
205   void SetGetDefaultFontFamilyResult(std::string result);
206
207   void SetGetDefaultFontSizeResult(float result);
208
209   void SetGetFontPathResult(std::string& result);
210
211   void ClearReadyResources();
212
213   void SetResourceLoaded(Integration::ResourceId  loadedId,
214                          Integration::ResourceTypeId  loadedType,
215                          Integration::ResourcePointer loadedResource);
216
217   void SetResourceLoadFailed(Integration::ResourceId  id,
218                              Integration::ResourceFailure failure);
219
220   Integration::ResourceRequest* GetRequest();
221
222   void DiscardRequest();
223
224   void SetClosestImageSize(const Vector2& size);
225
226   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
227
228   void SetSaveFileResult( bool result );
229
230 private:
231   mutable TraceCallStack        mTrace;
232   size_t                        mSeconds;
233   size_t                        mMicroSeconds;
234   bool                          mIsLoadingResult;
235   Resources                     mResources;
236   Integration::ResourceRequest* mRequest;
237   Vector2                       mSize;
238   Vector2                       mClosestSize;
239
240   LoadFileResult                mLoadFileResult;
241   bool                          mSaveFileResult;
242 };
243
244 } // Dali
245
246 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */