Merge remote-tracking branch 'origin/tizen' into new_text
[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
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::SetDpi()
140    */
141   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
142
143   /**
144    * @copydoc PlatformAbstraction::LoadFile()
145    */
146   virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const;
147
148   /**
149    * @copydoc PlatformAbstraction::SaveFile()
150    */
151   virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const;
152
153   virtual void JoinLoaderThreads();
154
155   virtual Integration::DynamicsFactory* GetDynamicsFactory();
156
157 public: // TEST FUNCTIONS
158
159   // Enumeration of Platform Abstraction methods
160   typedef enum
161   {
162     GetTimeMicrosecondsFunc,
163     SuspendFunc,
164     ResumeFunc,
165     LoadResourceFunc,
166     SaveResourceFunc,
167     SaveFileFunc,
168     LoadFileFunc,
169     CancelLoadFunc,
170     GetResourcesFunc,
171     IsLoadingFunc,
172     SetDpiFunc,
173     JoinLoaderThreadsFunc,
174     GetDynamicsFactoryFunc,
175   } TestFuncEnum;
176
177   /** Call this every test */
178   void Initialize();
179
180   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
181   inline void ResetTrace() { mTrace.Reset(); }
182   inline TraceCallStack& GetTrace() { return mTrace; }
183
184   bool WasCalled(TestFuncEnum func);
185
186   void SetGetTimeMicrosecondsResult(size_t sec, size_t usec);
187
188   void IncrementGetTimeResult(size_t milliseconds);
189
190   void SetIsLoadingResult(bool result);
191
192   void ClearReadyResources();
193
194   void SetResourceLoaded(Integration::ResourceId  loadedId,
195                          Integration::ResourceTypeId  loadedType,
196                          Integration::ResourcePointer loadedResource);
197
198   void SetResourceLoadFailed(Integration::ResourceId  id,
199                              Integration::ResourceFailure failure);
200
201   void SetResourceSaved(Integration::ResourceId      savedId,
202                         Integration::ResourceTypeId  savedType);
203
204   void SetResourceSaveFailed(Integration::ResourceId  id,
205                              Integration::ResourceFailure failure);
206
207   Integration::ResourceRequest* GetRequest();
208
209   void DiscardRequest();
210
211   void SetClosestImageSize(const Vector2& size);
212
213   void SetLoadFileResult( bool result, std::vector< unsigned char >& buffer );
214
215   void SetSaveFileResult( bool result );
216
217 private:
218   mutable TraceCallStack        mTrace;
219   size_t                        mSeconds;
220   size_t                        mMicroSeconds;
221   bool                          mIsLoadingResult;
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__ */