Removed redundant resource loading code
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-platform-abstraction.cpp
1 /*
2  * Copyright (c) 2017 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   mSize(),
29   mClosestSize(),
30   mLoadFileResult(),
31   mSaveFileResult( false ),
32   mSynchronouslyLoadedResource()
33 {
34   Initialize();
35 }
36
37 TestPlatformAbstraction::~TestPlatformAbstraction()
38 {
39 }
40
41 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( const std::string& filename,
42                                                               ImageDimensions size,
43                                                               FittingMode::Type fittingMode,
44                                                               SamplingMode::Type samplingMode,
45                                                               bool orientationCorrection )
46 {
47   ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
48   mTrace.PushCall("GetClosestImageSize", "");
49   return closestSize;
50 }
51
52 ImageDimensions TestPlatformAbstraction::GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
53                                                    ImageDimensions size,
54                                                    FittingMode::Type fittingMode,
55                                                    SamplingMode::Type samplingMode,
56                                                    bool orientationCorrection )
57 {
58   ImageDimensions closestSize = ImageDimensions( mClosestSize.x, mClosestSize.y );
59   mTrace.PushCall("GetClosestImageSize", "");
60   return closestSize;
61 }
62
63 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
64 {
65   mTrace.PushCall("LoadResourceSynchronously", "");
66   return mSynchronouslyLoadedResource;
67 }
68
69 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
70 {
71   mTrace.PushCall("DecodeBuffer", "");
72   return mDecodedBitmap;
73 }
74
75 bool TestPlatformAbstraction::LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const
76 {
77   mTrace.PushCall("LoadShaderBinaryFile", "");
78   if( mLoadFileResult.loadResult )
79   {
80     buffer = mLoadFileResult.buffer;
81   }
82
83   return mLoadFileResult.loadResult;
84 }
85
86
87 /** Call this every test */
88 void TestPlatformAbstraction::Initialize()
89 {
90   mTrace.Reset();
91   mTrace.Enable(true);
92   mIsLoadingResult=false;
93   mSynchronouslyLoadedResource.Reset();
94   mDecodedBitmap.Reset();
95 }
96
97 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
98 {
99   switch(func)
100   {
101     case LoadResourceSynchronouslyFunc:       return mTrace.FindMethod("LoadResourceSynchronously");
102     case LoadShaderBinaryFileFunc:            return mTrace.FindMethod("LoadShaderBinaryFile");
103     case SaveShaderBinaryFileFunc:            return mTrace.FindMethod("SaveShaderBinaryFile");
104   }
105   return false;
106 }
107
108 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
109 {
110   mIsLoadingResult = result;
111 }
112
113 void TestPlatformAbstraction::ClearReadyResources()
114 {
115   mSynchronouslyLoadedResource.Reset();
116   mDecodedBitmap.Reset();
117 }
118
119 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
120 {
121   mClosestSize = size;
122 }
123
124 void TestPlatformAbstraction::SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer )
125 {
126   mLoadFileResult.loadResult = result;
127   if( result )
128   {
129     mLoadFileResult.buffer = buffer;
130   }
131 }
132
133 void TestPlatformAbstraction::SetSaveFileResult( bool result )
134 {
135   mSaveFileResult = result;
136 }
137
138 void TestPlatformAbstraction::SetSynchronouslyLoadedResource( Integration::ResourcePointer resource )
139 {
140   mSynchronouslyLoadedResource = resource;
141 }
142
143 void TestPlatformAbstraction::SetDecodedBitmap( Integration::BitmapPtr bitmap )
144 {
145   mDecodedBitmap = bitmap;
146 }
147
148 } // namespace Dali