1 #ifndef DALI_TEST_PLATFORM_ABSTRACTION_H
2 #define DALI_TEST_PLATFORM_ABSTRACTION_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
29 #include <dali/integration-api/platform-abstraction.h>
30 #include <dali/public-api/math/vector2.h>
32 #include "test-trace-call-stack.h"
37 * Concrete implementation of the platform abstraction class.
39 class DALI_CORE_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
45 TestPlatformAbstraction();
50 ~TestPlatformAbstraction() override;
53 * @copydoc PlatformAbstraction::GetClosestImageSize()
55 ImageDimensions GetClosestImageSize(const std::string& filename,
57 FittingMode::Type fittingMode,
58 SamplingMode::Type samplingMode,
59 bool orientationCorrection) override;
62 * @copydoc PlatformAbstraction::GetClosestImageSize()
64 ImageDimensions GetClosestImageSize(Integration::ResourcePointer resourceBuffer,
66 FittingMode::Type fittingMode,
67 SamplingMode::Type samplingMode,
68 bool orientationCorrection) override;
71 * @copydoc PlatformAbstraction::LoadResourceSynchronously()
73 Integration::ResourcePointer LoadImageSynchronously(const Integration::BitmapResourceType& resourceType, const std::string& resourcePath) override;
76 * @copydoc PlatformAbstraction::DecodeBuffer()
78 Integration::BitmapPtr DecodeBuffer(const Dali::Integration::BitmapResourceType& resourceType, uint8_t* buffer, size_t size) override;
81 * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
83 bool LoadShaderBinaryFile(const std::string& filename, Dali::Vector<unsigned char>& buffer) const override;
86 * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
88 virtual bool SaveShaderBinaryFile(const std::string& filename, const unsigned char* buffer, unsigned int numBytes) const override
94 * @copydoc PlatformAbstraction::StartTimer()
96 uint32_t StartTimer(uint32_t milliseconds, CallbackBase* callback) override;
99 * @copydoc PlatformAbstraction::CancelTimer()
101 void CancelTimer(uint32_t timerId) override;
103 public: // TEST FUNCTIONS
104 // Enumeration of Platform Abstraction methods
107 LoadResourceSynchronouslyFunc,
108 LoadShaderBinaryFileFunc,
109 SaveShaderBinaryFileFunc
112 /** Call this every test */
115 inline void EnableTrace(bool enable)
117 mTrace.Enable(enable);
119 inline void ResetTrace()
123 inline TraceCallStack& GetTrace()
129 * @brief Checks if a platform function was called
130 * @param[in] func The function to check
131 * @return true if the function was called
133 bool WasCalled(TestFuncEnum func);
136 * @brief Sets the result to return when IsLoading is called by Core.
137 * @param[in] result The result to set.
139 void SetIsLoadingResult(bool result);
142 * @brief Clears all resource queues
144 void ClearReadyResources();
147 * @brief Sets the value returned by GetClosestImageSize.
148 * @param[in] size The size that should be returned.
150 void SetClosestImageSize(const Vector2& size);
153 * @brief Sets the result return by LoadFile.
154 * @param[in] result The value that LoadFile should return.
155 * @param[in] buffer The buffer of the loaded file.
157 void SetLoadFileResult(bool result, Dali::Vector<unsigned char>& buffer);
160 * @brief Sets the SaveFile result
161 * @param[in] result The value that SaveFile should return
163 void SetSaveFileResult(bool result);
166 * @brief Sets the resource loaded by LoadResourceSynchronously
167 * @param[in] resource The loaded resource
169 void SetSynchronouslyLoadedResource(Integration::ResourcePointer resource);
172 * @brief Sets the bitmap returned by DecodeBuffer()
173 * @param[in] bitmap The decoded bitmap
175 void SetDecodedBitmap(Integration::BitmapPtr bitmap);
178 * @brief Triggers the previously stored callback function
183 TestPlatformAbstraction(const TestPlatformAbstraction&); ///< Undefined
184 TestPlatformAbstraction& operator=(const TestPlatformAbstraction&); ///< Undefined
187 struct LoadFileResult
189 inline LoadFileResult()
195 Dali::Vector<unsigned char> buffer;
198 mutable TraceCallStack mTrace{true, "PlatformAbstraction::"};
199 bool mIsLoadingResult;
200 ImageDimensions mClosestSize;
202 LoadFileResult mLoadFileResult;
203 bool mSaveFileResult;
205 Integration::ResourcePointer mSynchronouslyLoadedResource;
206 Integration::BitmapPtr mDecodedBitmap;
209 CallbackBase* mCallbackFunction;
214 #endif /* DALI_TEST_PLATFORM_ABSTRACTION_H */