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