[dali_1.1.31] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-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
54   struct LoadFileResult
55   {
56     inline LoadFileResult()
57     : loadResult(false)
58     {
59
60     }
61
62     bool loadResult;
63     Dali::Vector< unsigned char> buffer;
64   };
65
66   /**
67    * Constructor
68    */
69   TestPlatformAbstraction();
70
71   /**
72    * Destructor
73    */
74   virtual ~TestPlatformAbstraction();
75
76   /**
77    * @copydoc PlatformAbstraction::Suspend()
78    */
79   virtual void Suspend();
80
81   /**
82    * @copydoc PlatformAbstraction::Resume()
83    */
84   virtual void Resume();
85
86   /**
87    * @copydoc PlatformAbstraction::GetClosestImageSize()
88    */
89   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
90                                                  ImageDimensions size,
91                                                  FittingMode::Type fittingMode,
92                                                  SamplingMode::Type samplingMode,
93                                                  bool orientationCorrection );
94
95   /**
96    * @copydoc PlatformAbstraction::GetClosestImageSize()
97    */
98   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
99                                                ImageDimensions size,
100                                                FittingMode::Type fittingMode,
101                                                SamplingMode::Type samplingMode,
102                                                bool orientationCorrection );
103
104   /**
105    * @copydoc PlatformAbstraction::LoadResource()
106    */
107   virtual void LoadResource(const Integration::ResourceRequest& request);
108
109   /**
110    * @copydoc PlatformAbstraction::LoadResourceSynchronously()
111    */
112   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
113
114   /**
115    * @copydoc PlatformAbstraction::DecodeBuffer()
116    */
117   virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
118
119   /**
120    * @copydoc PlatformAbstraction::CancelLoad()
121    */
122   virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
123
124   /**
125    * @copydoc PlatformAbstraction::GetResources()
126    */
127   virtual void GetResources(Integration::ResourceCache& cache);
128
129   /**
130    * @copydoc PlatformAbstraction::IsLoading()
131    */
132   virtual bool IsLoading();
133
134   /**
135    * @copydoc PlatformAbstraction::GetDefaultFontSize()
136    */
137   virtual int GetDefaultFontSize() const;
138
139   /**
140    * @copydoc PlatformAbstraction::SetDpi()
141    */
142   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
143
144   /**
145    * @copydoc PlatformAbstraction::LoadFile()
146    */
147   virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
148
149   /**
150    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
151    */
152   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
153
154   /**
155    * @copydoc PlatformAbstraction::SaveFile()
156    */
157   virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
158
159  /**
160   * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
161   */
162   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
163
164   virtual void JoinLoaderThreads();
165
166 public: // TEST FUNCTIONS
167
168   // Enumeration of Platform Abstraction methods
169   typedef enum
170   {
171     SuspendFunc,
172     ResumeFunc,
173     LoadResourceFunc,
174     LoadResourceSynchronouslyFunc,
175     SaveFileFunc,
176     LoadFileFunc,
177     LoadShaderBinaryFileFunc,
178     SaveShaderBinaryFileFunc,
179     CancelLoadFunc,
180     GetResourcesFunc,
181     IsLoadingFunc,
182     SetDpiFunc,
183     JoinLoaderThreadsFunc,
184   } TestFuncEnum;
185
186   /** Call this every test */
187   void Initialize();
188
189   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
190   inline void ResetTrace() { mTrace.Reset(); }
191   inline TraceCallStack& GetTrace() { return mTrace; }
192
193   bool WasCalled(TestFuncEnum func);
194
195   void SetIsLoadingResult(bool result);
196
197   void SetGetDefaultFontSizeResult(float result);
198
199   void ClearReadyResources();
200
201   void SetResourceLoaded(Integration::ResourceId  loadedId,
202                          Integration::ResourceTypeId  loadedType,
203                          Integration::ResourcePointer loadedResource);
204
205   void SetResourceLoadFailed(Integration::ResourceId  id,
206                              Integration::ResourceFailure failure);
207
208   Integration::ResourceRequest* GetRequest();
209
210   void DiscardRequest();
211
212   void SetClosestImageSize(const Vector2& size);
213
214   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
215
216   void SetSaveFileResult( bool result );
217
218 private:
219   mutable TraceCallStack        mTrace;
220   bool                          mIsLoadingResult;
221   int                           mGetDefaultFontSizeResult;
222   Resources                     mResources;
223   Integration::ResourceRequest* mRequest;
224   Vector2                       mSize;
225   Vector2                       mClosestSize;
226
227   LoadFileResult                mLoadFileResult;
228   bool                          mSaveFileResult;
229 };
230
231 } // Dali
232
233 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */