(Automated Tests) Changes required after removal of time getters from PlatformAbstraction
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-platform-abstraction.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "test-platform-abstraction.h"
19 #include "dali-test-suite-utils.h"
20 #include <dali/integration-api/bitmap.h>
21
22 namespace Dali
23 {
24
25 TestPlatformAbstraction::TestPlatformAbstraction()
26 : mTrace(),
27   mIsLoadingResult( false ),
28   mGetDefaultFontSizeResult( 0 ),
29   mResources(),
30   mRequest( NULL ),
31   mSize(),
32   mClosestSize(),
33   mLoadFileResult(),
34   mSaveFileResult( false )
35 {
36   Initialize();
37 }
38
39 TestPlatformAbstraction::~TestPlatformAbstraction()
40 {
41 }
42
43 void TestPlatformAbstraction::Suspend()
44 {
45   mTrace.PushCall("Suspend", "");
46 }
47
48 void TestPlatformAbstraction::Resume()
49 {
50   mTrace.PushCall("Resume", "");
51 }
52
53 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
54                                                               ImageDimensions size,
55                                                               FittingMode::Type fittingMode,
56                                                               SamplingMode::Type samplingMode,
57                                                               bool orientationCorrection )
58 {
59   ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
60   mTrace.PushCall("GetClosestImageSize", "");
61   return closestSize;
62 }
63
64 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
65                                                    ImageDimensions size,
66                                                    FittingMode::Type fittingMode,
67                                                    SamplingMode::Type samplingMode,
68                                                    bool orientationCorrection )
69 {
70   ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
71   mTrace.PushCall("GetClosestImageSize", "");
72   return closestSize;
73 }
74
75 void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& request)
76 {
77   std::ostringstream out;
78   out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
79
80   mTrace.PushCall("LoadResource", out.str());
81   if(mRequest != NULL)
82   {
83     delete mRequest;
84     tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
85   }
86   mRequest = new Integration::ResourceRequest(request);
87 }
88
89 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
90 {
91   mTrace.PushCall("LoadResourceSynchronously", "");
92   return mResources.loadedResource;
93 }
94
95 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
96 {
97   mTrace.PushCall("DecodeBuffer", "");
98   return Integration::BitmapPtr();
99 }
100
101 void TestPlatformAbstraction::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
102 {
103   mTrace.PushCall("CancelLoad", "");
104 }
105
106 void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
107 {
108   mTrace.PushCall("GetResources", "");
109
110   if(mResources.loaded)
111   {
112     cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
113   }
114   if(mResources.loadFailed)
115   {
116     cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
117   }
118 }
119
120 bool TestPlatformAbstraction::IsLoading()
121 {
122   mTrace.PushCall("IsLoading", "");
123   return mIsLoadingResult;
124 }
125
126 int TestPlatformAbstraction::GetDefaultFontSize() const
127 {
128   mTrace.PushCall("GetDefaultFontSize", "");
129   return mGetDefaultFontSizeResult;
130 }
131
132 void TestPlatformAbstraction::SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical)
133 {
134   mTrace.PushCall("SetDpi", "");
135 }
136
137 bool TestPlatformAbstraction::LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
138 {
139   mTrace.PushCall("LoadFile", "");
140   if( mLoadFileResult.loadResult )
141   {
142     buffer = mLoadFileResult.buffer;
143   }
144
145   return mLoadFileResult.loadResult;
146 }
147
148 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
149 {
150   mTrace.PushCall("LoadShaderBinaryFile", "");
151   if( mLoadFileResult.loadResult )
152   {
153     buffer = mLoadFileResult.buffer;
154   }
155
156   return mLoadFileResult.loadResult;
157 }
158
159 bool TestPlatformAbstraction::SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const
160 {
161   mTrace.PushCall("SaveFile", "");
162   return false;
163 }
164
165 void TestPlatformAbstraction::JoinLoaderThreads()
166 {
167   mTrace.PushCall("JoinLoaderThreads", "");
168 }
169
170 /** Call this every test */
171 void TestPlatformAbstraction::Initialize()
172 {
173   mTrace.Reset();
174   mTrace.Enable(true);
175   memset(&mResources, 0, sizeof(Resources));
176   mIsLoadingResult=false;
177
178   if(mRequest)
179   {
180     delete mRequest;
181     mRequest = 0;
182   }
183 }
184
185 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
186 {
187   switch(func)
188   {
189     case SuspendFunc:                         return mTrace.FindMethod("Suspend");
190     case ResumeFunc:                          return mTrace.FindMethod("Resume");
191     case LoadResourceFunc:                    return mTrace.FindMethod("LoadResource");
192     case LoadFileFunc:                        return mTrace.FindMethod("LoadFile");
193     case LoadShaderBinaryFileFunc:            return mTrace.FindMethod("LoadShaderBinaryFile");
194     case SaveShaderBinaryFileFunc:            return mTrace.FindMethod("SaveShaderBinaryFile");
195     case SaveFileFunc:                        return mTrace.FindMethod("SaveFile");
196     case CancelLoadFunc:                      return mTrace.FindMethod("CancelLoad");
197     case GetResourcesFunc:                    return mTrace.FindMethod("GetResources");
198     case IsLoadingFunc:                       return mTrace.FindMethod("IsLoading");
199     case SetDpiFunc:                          return mTrace.FindMethod("SetDpi");
200     case JoinLoaderThreadsFunc:               return mTrace.FindMethod("JoinLoaderThreads");
201   }
202   return false;
203 }
204
205 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
206 {
207   mIsLoadingResult = result;
208 }
209
210 void TestPlatformAbstraction::ClearReadyResources()
211 {
212   memset(&mResources, 0, sizeof(Resources));
213 }
214
215 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId  loadedId,
216                                                 Integration::ResourceTypeId  loadedType,
217                                                 Integration::ResourcePointer loadedResource)
218 {
219   mResources.loaded = true;
220   mResources.loadedId = loadedId;
221   mResources.loadedType = loadedType;
222   mResources.loadedResource = loadedResource;
223 }
224
225 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId  id,
226                                                     Integration::ResourceFailure failure)
227 {
228   mResources.loadFailed = true;
229   mResources.loadFailedId = id;
230   mResources.loadFailure = failure;
231 }
232
233 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
234 {
235   return mRequest;
236 }
237
238 void TestPlatformAbstraction::DiscardRequest()
239 {
240   delete mRequest;
241   mRequest = NULL;
242 }
243
244 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
245 {
246   mClosestSize = size;
247 }
248
249 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
250 {
251   mLoadFileResult.loadResult = result;
252   if( result )
253   {
254     mLoadFileResult.buffer = buffer;
255   }
256 }
257
258 void TestPlatformAbstraction::SetSaveFileResult( bool result )
259 {
260   mSaveFileResult = result;
261 }
262
263 } // namespace Dali