Merge branch 'new_text' into tizen
[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/public-api/common/set-wrapper.h>
28 #include <dali/integration-api/platform-abstraction.h>
29
30 #include "test-trace-call-stack.h"
31 #include "test-dynamics.h"
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   virtual void GetClosestImageSize( const std::string& filename,
102                                     const ImageAttributes& attributes,
103                                     Vector2& closestSize);
104
105   virtual void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
106                                     const ImageAttributes& attributes,
107                                     Vector2& closestSize);
108
109   /**
110    * @copydoc PlatformAbstraction::LoadResource()
111    */
112   virtual void LoadResource(const Integration::ResourceRequest& request);
113
114   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
115
116   /**
117    * @copydoc PlatformAbstraction::SaveResource()
118    */
119   virtual void SaveResource(const Integration::ResourceRequest& request);
120
121   /**
122    * @copydoc PlatformAbstraction::CancelLoad()
123    */
124   virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
125
126   /**
127    * @copydoc PlatformAbstraction::GetResources()
128    */
129   virtual void GetResources(Integration::ResourceCache& cache);
130
131   /**
132    * @copydoc PlatformAbstraction::IsLoading()
133    */
134   virtual bool IsLoading();
135
136   /**
137    * @copydoc PlatformAbstraction::GetDefaultFontFamily()
138    */
139   virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const;
140
141   /**
142    * @copydoc PlatformAbstraction::GetDefaultFontSize()
143    */
144   virtual int GetDefaultFontSize() const;
145
146   /**
147    * @copydoc PlatformAbstraction::SetDpi()
148    */
149   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
150
151   /**
152    * @copydoc PlatformAbstraction::LoadFile()
153    */
154   virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const;
155
156   /**
157    * @copydoc PlatformAbstraction::LoadShaderBinFile()
158    */
159   virtual bool LoadShaderBinFile( const std::string& filename, std::vector< unsigned char >& buffer ) const;
160
161   /**
162    * @copydoc PlatformAbstraction::SaveFile()
163    */
164   virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const;
165
166   virtual void JoinLoaderThreads();
167
168   virtual Integration::DynamicsFactory* GetDynamicsFactory();
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     SaveResourceFunc,
180     SaveFileFunc,
181     LoadFileFunc,
182     CancelLoadFunc,
183     GetResourcesFunc,
184     IsLoadingFunc,
185     SetDpiFunc,
186     JoinLoaderThreadsFunc,
187     GetDynamicsFactoryFunc,
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 ClearReadyResources();
206
207   void SetResourceLoaded(Integration::ResourceId  loadedId,
208                          Integration::ResourceTypeId  loadedType,
209                          Integration::ResourcePointer loadedResource);
210
211   void SetResourceLoadFailed(Integration::ResourceId  id,
212                              Integration::ResourceFailure failure);
213
214   void SetResourceSaved(Integration::ResourceId      savedId,
215                         Integration::ResourceTypeId  savedType);
216
217   void SetResourceSaveFailed(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, std::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   std::string                   mGetDefaultFontFamilyResult;
236   std::string                   mGetDefaultFontStyleResult;
237   int                           mGetDefaultFontSizeResult;
238   Resources                     mResources;
239   Integration::ResourceRequest* mRequest;
240   Vector2                       mSize;
241   Vector2                       mClosestSize;
242
243   LoadFileResult                mLoadFileResult;
244   bool                          mSaveFileResult;
245   TestDynamicsFactory*          mDynamicsFactory;
246 };
247
248 } // Dali
249
250 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */