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