1 #ifndef DALI_TEST_PLATFORM_ABSTRACTION_H
2 #define DALI_TEST_PLATFORM_ABSTRACTION_H
5 * Copyright (c) 2019 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.
28 #include <dali/integration-api/platform-abstraction.h>
29 #include <dali/public-api/math/vector2.h>
31 #include "test-trace-call-stack.h"
37 * Concrete implementation of the platform abstraction class.
39 class DALI_CORE_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
47 TestPlatformAbstraction();
52 virtual ~TestPlatformAbstraction();
55 * @copydoc PlatformAbstraction::GetClosestImageSize()
57 virtual ImageDimensions GetClosestImageSize( const std::string& filename,
59 FittingMode::Type fittingMode,
60 SamplingMode::Type samplingMode,
61 bool orientationCorrection );
64 * @copydoc PlatformAbstraction::GetClosestImageSize()
66 virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
68 FittingMode::Type fittingMode,
69 SamplingMode::Type samplingMode,
70 bool orientationCorrection );
73 * @copydoc PlatformAbstraction::LoadResourceSynchronously()
75 virtual Integration::ResourcePointer LoadImageSynchronously( const Integration::BitmapResourceType& resourceType, const std::string& resourcePath );
78 * @copydoc PlatformAbstraction::DecodeBuffer()
80 virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::BitmapResourceType& resourceType, uint8_t * buffer, size_t size );
83 * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
85 virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
88 * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
90 virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
93 * @copydoc PlatformAbstraction::StartTimer()
95 virtual uint32_t StartTimer( uint32_t milliseconds, CallbackBase* callback );
98 * @copydoc PlatformAbstraction::CancelTimer()
100 virtual void CancelTimer ( uint32_t timerId );
102 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) { mTrace.Enable(enable); }
116 inline void ResetTrace() { mTrace.Reset(); }
117 inline TraceCallStack& GetTrace() { return mTrace; }
120 * @brief Checks if a platform function was called
121 * @param[in] func The function to check
122 * @return true if the function was called
124 bool WasCalled(TestFuncEnum func);
127 * @brief Sets the result to return when IsLoading is called by Core.
128 * @param[in] result The result to set.
130 void SetIsLoadingResult(bool result);
133 * @brief Clears all resource queues
135 void ClearReadyResources();
138 * @brief Sets the value returned by GetClosestImageSize.
139 * @param[in] size The size that should be returned.
141 void SetClosestImageSize( const Vector2& size );
144 * @brief Sets the result return by LoadFile.
145 * @param[in] result The value that LoadFile should return.
146 * @param[in] buffer The buffer of the loaded file.
148 void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
151 * @brief Sets the SaveFile result
152 * @param[in] result The value that SaveFile should return
154 void SetSaveFileResult( bool result );
157 * @brief Sets the resource loaded by LoadResourceSynchronously
158 * @param[in] resource The loaded resource
160 void SetSynchronouslyLoadedResource( Integration::ResourcePointer resource );
163 * @brief Sets the bitmap returned by DecodeBuffer()
164 * @param[in] bitmap The decoded bitmap
166 void SetDecodedBitmap( Integration::BitmapPtr bitmap );
169 * @brief Triggers the previously stored callback function
175 TestPlatformAbstraction( const TestPlatformAbstraction& ); ///< Undefined
176 TestPlatformAbstraction& operator=( const TestPlatformAbstraction& ); ///< Undefined
180 struct LoadFileResult
182 inline LoadFileResult()
189 Dali::Vector< unsigned char> buffer;
192 mutable TraceCallStack mTrace;
193 bool mIsLoadingResult;
194 ImageDimensions mClosestSize;
196 LoadFileResult mLoadFileResult;
197 bool mSaveFileResult;
199 Integration::ResourcePointer mSynchronouslyLoadedResource;
200 Integration::BitmapPtr mDecodedBitmap;
203 CallbackBase* mCallbackFunction;
208 #endif /* DALI_TEST_PLATFORM_ABSTRACTION_H */