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