2 * Copyright (c) 2021 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()
27 : mIsLoadingResult(false),
30 mSaveFileResult(false),
31 mSynchronouslyLoadedResource(),
33 mCallbackFunction(nullptr)
38 TestPlatformAbstraction::~TestPlatformAbstraction()
42 ImageDimensions TestPlatformAbstraction::GetClosestImageSize(const std::string& filename,
44 FittingMode::Type fittingMode,
45 SamplingMode::Type samplingMode,
46 bool orientationCorrection)
48 ImageDimensions closestSize = ImageDimensions(mClosestSize);
49 mTrace.PushCall("GetClosestImageSize", "");
53 ImageDimensions TestPlatformAbstraction::GetClosestImageSize(Integration::ResourcePointer resourceBuffer,
55 FittingMode::Type fittingMode,
56 SamplingMode::Type samplingMode,
57 bool orientationCorrection)
59 ImageDimensions closestSize = ImageDimensions(mClosestSize);
60 mTrace.PushCall("GetClosestImageSize", "");
64 Integration::ResourcePointer TestPlatformAbstraction::LoadImageSynchronously(const Integration::BitmapResourceType& resourceType, const std::string& resourcePath)
66 mTrace.PushCall("LoadResourceSynchronously", "");
67 return mSynchronouslyLoadedResource;
70 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer(const Integration::BitmapResourceType& resourceType, uint8_t* buffer, size_t size)
72 mTrace.PushCall("DecodeBuffer", "");
73 return mDecodedBitmap;
76 bool TestPlatformAbstraction::LoadShaderBinaryFile(const std::string& filename, Dali::Vector<unsigned char>& buffer) const
78 mTrace.PushCall("LoadShaderBinaryFile", "");
79 if(mLoadFileResult.loadResult)
81 buffer = mLoadFileResult.buffer;
84 return mLoadFileResult.loadResult;
87 /** Call this every test */
88 void TestPlatformAbstraction::Initialize()
92 mIsLoadingResult = false;
93 mSynchronouslyLoadedResource.Reset();
94 mDecodedBitmap.Reset();
97 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
101 case LoadResourceSynchronouslyFunc:
102 return mTrace.FindMethod("LoadResourceSynchronously");
103 case LoadShaderBinaryFileFunc:
104 return mTrace.FindMethod("LoadShaderBinaryFile");
105 case SaveShaderBinaryFileFunc:
106 return mTrace.FindMethod("SaveShaderBinaryFile");
111 void TestPlatformAbstraction::SetIsLoadingResult(bool result)
113 mIsLoadingResult = result;
116 void TestPlatformAbstraction::ClearReadyResources()
118 mSynchronouslyLoadedResource.Reset();
119 mDecodedBitmap.Reset();
122 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
124 mClosestSize = ImageDimensions(static_cast<uint32_t>(size.x), static_cast<uint32_t>(size.y));
127 void TestPlatformAbstraction::SetLoadFileResult(bool result, Dali::Vector<unsigned char>& buffer)
129 mLoadFileResult.loadResult = result;
132 mLoadFileResult.buffer = buffer;
136 void TestPlatformAbstraction::SetSaveFileResult(bool result)
138 mSaveFileResult = result;
141 void TestPlatformAbstraction::SetSynchronouslyLoadedResource(Integration::ResourcePointer resource)
143 mSynchronouslyLoadedResource = resource;
146 void TestPlatformAbstraction::SetDecodedBitmap(Integration::BitmapPtr bitmap)
148 mDecodedBitmap = bitmap;
151 uint32_t TestPlatformAbstraction::StartTimer(uint32_t milliseconds, CallbackBase* callback)
153 mCallbackFunction = callback;
158 void TestPlatformAbstraction::TriggerTimer()
160 if(mCallbackFunction != nullptr)
162 CallbackBase::Execute(*mCallbackFunction);
166 void TestPlatformAbstraction::CancelTimer(uint32_t timerId)
168 mCallbackFunction = nullptr;