2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "test-platform-abstraction.h"
20 #include <dali/integration-api/bitmap.h>
22 #include "dali-test-suite-utils.h"
26 TestPlatformAbstraction::TestPlatformAbstraction()
28 mIsLoadingResult(false),
31 mSaveFileResult(false),
32 mSynchronouslyLoadedResource(),
34 mCallbackFunction(nullptr)
39 TestPlatformAbstraction::~TestPlatformAbstraction()
43 ImageDimensions TestPlatformAbstraction::GetClosestImageSize(const std::string& filename,
45 FittingMode::Type fittingMode,
46 SamplingMode::Type samplingMode,
47 bool orientationCorrection)
49 ImageDimensions closestSize = ImageDimensions(mClosestSize);
50 mTrace.PushCall("GetClosestImageSize", "");
54 ImageDimensions TestPlatformAbstraction::GetClosestImageSize(Integration::ResourcePointer resourceBuffer,
56 FittingMode::Type fittingMode,
57 SamplingMode::Type samplingMode,
58 bool orientationCorrection)
60 ImageDimensions closestSize = ImageDimensions(mClosestSize);
61 mTrace.PushCall("GetClosestImageSize", "");
65 Integration::ResourcePointer TestPlatformAbstraction::LoadImageSynchronously(const Integration::BitmapResourceType& resourceType, const std::string& resourcePath)
67 mTrace.PushCall("LoadResourceSynchronously", "");
68 return mSynchronouslyLoadedResource;
71 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer(const Integration::BitmapResourceType& resourceType, uint8_t* buffer, size_t size)
73 mTrace.PushCall("DecodeBuffer", "");
74 return mDecodedBitmap;
77 bool TestPlatformAbstraction::LoadShaderBinaryFile(const std::string& filename, Dali::Vector<unsigned char>& buffer) const
79 mTrace.PushCall("LoadShaderBinaryFile", "");
80 if(mLoadFileResult.loadResult)
82 buffer = mLoadFileResult.buffer;
85 return mLoadFileResult.loadResult;
88 /** Call this every test */
89 void TestPlatformAbstraction::Initialize()
93 mIsLoadingResult = false;
94 mSynchronouslyLoadedResource.Reset();
95 mDecodedBitmap.Reset();
98 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
102 case LoadResourceSynchronouslyFunc:
103 return mTrace.FindMethod("LoadResourceSynchronously");
104 case LoadShaderBinaryFileFunc:
105 return mTrace.FindMethod("LoadShaderBinaryFile");
106 case SaveShaderBinaryFileFunc:
107 return mTrace.FindMethod("SaveShaderBinaryFile");
112 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
114 mIsLoadingResult = result;
117 void TestPlatformAbstraction::ClearReadyResources()
119 mSynchronouslyLoadedResource.Reset();
120 mDecodedBitmap.Reset();
123 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
125 mClosestSize = ImageDimensions(static_cast<uint32_t>(size.x), static_cast<uint32_t>(size.y));
128 void TestPlatformAbstraction::SetLoadFileResult(bool result, Dali::Vector<unsigned char>& buffer)
130 mLoadFileResult.loadResult = result;
133 mLoadFileResult.buffer = buffer;
137 void TestPlatformAbstraction::SetSaveFileResult(bool result)
139 mSaveFileResult = result;
142 void TestPlatformAbstraction::SetSynchronouslyLoadedResource(Integration::ResourcePointer resource)
144 mSynchronouslyLoadedResource = resource;
147 void TestPlatformAbstraction::SetDecodedBitmap(Integration::BitmapPtr bitmap)
149 mDecodedBitmap = bitmap;
152 uint32_t TestPlatformAbstraction::StartTimer(uint32_t milliseconds, CallbackBase* callback)
154 mCallbackFunction = callback;
159 void TestPlatformAbstraction::TriggerTimer()
161 if(mCallbackFunction != nullptr)
163 CallbackBase::Execute(*mCallbackFunction);
167 void TestPlatformAbstraction::CancelTimer(uint32_t timerId)
169 mCallbackFunction = nullptr;