(Automated Tests) Update test suite after changes to PlatformAbstraction
[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::GetTimeNanoseconds()
78    */
79   virtual void GetTimeNanoseconds( uint64_t& seconds, uint64_t& nanoseconds );
80
81   /**
82    * @copydoc PlatformAbstraction::Suspend()
83    */
84   virtual void Suspend();
85
86   /**
87    * @copydoc PlatformAbstraction::Resume()
88    */
89   virtual void Resume();
90
91   /**
92    * @copydoc PlatformAbstraction::GetClosestImageSize()
93    */
94   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
95                                                  ImageDimensions size,
96                                                  FittingMode::Type fittingMode,
97                                                  SamplingMode::Type samplingMode,
98                                                  bool orientationCorrection );
99
100   /**
101    * @copydoc PlatformAbstraction::GetClosestImageSize()
102    */
103   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
104                                                ImageDimensions size,
105                                                FittingMode::Type fittingMode,
106                                                SamplingMode::Type samplingMode,
107                                                bool orientationCorrection );
108
109   /**
110    * @copydoc PlatformAbstraction::LoadResource()
111    */
112   virtual void LoadResource(const Integration::ResourceRequest& request);
113
114   /**
115    * @copydoc PlatformAbstraction::LoadResourceSynchronously()
116    */
117   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
118
119   /**
120    * @copydoc PlatformAbstraction::DecodeBuffer()
121    */
122   virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
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::GetDefaultFontSize()
141    */
142   virtual int GetDefaultFontSize() const;
143
144   /**
145    * @copydoc PlatformAbstraction::SetDpi()
146    */
147   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
148
149   /**
150    * @copydoc PlatformAbstraction::LoadFile()
151    */
152   virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
153
154   /**
155    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
156    */
157   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
158
159   /**
160    * @copydoc PlatformAbstraction::SaveFile()
161    */
162   virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
163
164  /**
165   * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
166   */
167   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
168
169   virtual void JoinLoaderThreads();
170
171 public: // TEST FUNCTIONS
172
173   // Enumeration of Platform Abstraction methods
174   typedef enum
175   {
176     GetTimeNanosecondsFunc,
177     SuspendFunc,
178     ResumeFunc,
179     LoadResourceFunc,
180     SaveFileFunc,
181     LoadFileFunc,
182     LoadShaderBinaryFileFunc,
183     SaveShaderBinaryFileFunc,
184     CancelLoadFunc,
185     GetResourcesFunc,
186     IsLoadingFunc,
187     SetDpiFunc,
188     JoinLoaderThreadsFunc,
189   } TestFuncEnum;
190
191   /** Call this every test */
192   void Initialize();
193
194   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
195   inline void ResetTrace() { mTrace.Reset(); }
196   inline TraceCallStack& GetTrace() { return mTrace; }
197
198   bool WasCalled(TestFuncEnum func);
199
200   void SetGetTimeNanosecondsResult(size_t sec, size_t nsec);
201
202   void IncrementGetTimeResult(size_t milliseconds);
203
204   void SetIsLoadingResult(bool result);
205
206   void SetGetDefaultFontSizeResult(float 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   Integration::ResourceRequest* GetRequest();
218
219   void DiscardRequest();
220
221   void SetClosestImageSize(const Vector2& size);
222
223   void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
224
225   void SetSaveFileResult( bool result );
226
227 private:
228   mutable TraceCallStack        mTrace;
229   uint64_t                      mSeconds;
230   uint64_t                      mNanoSeconds;
231   bool                          mIsLoadingResult;
232   int                           mGetDefaultFontSizeResult;
233   Resources                     mResources;
234   Integration::ResourceRequest* mRequest;
235   Vector2                       mSize;
236   Vector2                       mClosestSize;
237
238   LoadFileResult                mLoadFileResult;
239   bool                          mSaveFileResult;
240 };
241
242 } // Dali
243
244 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */