Initial removal of Text features
[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::SaveFile()
149    */
150   virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const;
151
152   virtual void JoinLoaderThreads();
153
154   virtual Integration::DynamicsFactory* GetDynamicsFactory();
155
156 public: // TEST FUNCTIONS
157
158   // Enumeration of Platform Abstraction methods
159   typedef enum
160   {
161     GetTimeMicrosecondsFunc,
162     SuspendFunc,
163     ResumeFunc,
164     LoadResourceFunc,
165     SaveResourceFunc,
166     SaveFileFunc,
167     LoadFileFunc,
168     CancelLoadFunc,
169     GetResourcesFunc,
170     IsLoadingFunc,
171     SetDpiFunc,
172     JoinLoaderThreadsFunc,
173     GetDynamicsFactoryFunc,
174   } TestFuncEnum;
175
176   /** Call this every test */
177   void Initialize();
178
179   inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
180   inline void ResetTrace() { mTrace.Reset(); }
181   inline TraceCallStack& GetTrace() { return mTrace; }
182
183   bool WasCalled(TestFuncEnum func);
184
185   void SetGetTimeMicrosecondsResult(size_t sec, size_t usec);
186
187   void IncrementGetTimeResult(size_t milliseconds);
188
189   void SetIsLoadingResult(bool result);
190
191   void SetGetDefaultFontFamilyResult(std::string result);
192
193   void SetGetDefaultFontSizeResult(float result);
194
195   void SetGetFontPathResult(std::string& result);
196
197   void ClearReadyResources();
198
199   void SetResourceLoaded(Integration::ResourceId  loadedId,
200                          Integration::ResourceTypeId  loadedType,
201                          Integration::ResourcePointer loadedResource);
202
203   void SetResourceLoadFailed(Integration::ResourceId  id,
204                              Integration::ResourceFailure failure);
205
206   void SetResourceSaved(Integration::ResourceId      savedId,
207                         Integration::ResourceTypeId  savedType);
208
209   void SetResourceSaveFailed(Integration::ResourceId  id,
210                              Integration::ResourceFailure failure);
211
212   Integration::ResourceRequest* GetRequest();
213
214   void DiscardRequest();
215
216   void SetClosestImageSize(const Vector2& size);
217
218   void SetLoadFileResult( bool result, std::vector< unsigned char >& buffer );
219
220   void SetSaveFileResult( bool result );
221
222 private:
223   mutable TraceCallStack        mTrace;
224   size_t                        mSeconds;
225   size_t                        mMicroSeconds;
226   bool                          mIsLoadingResult;
227   Resources                     mResources;
228   Integration::ResourceRequest* mRequest;
229   Vector2                       mSize;
230   Vector2                       mClosestSize;
231
232   LoadFileResult                mLoadFileResult;
233   bool                          mSaveFileResult;
234 };
235
236 } // Dali
237
238 #endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */