-#ifndef __DALI_TEST_PLATFORM_ABSTRACTION_H__
-#define __DALI_TEST_PLATFORM_ABSTRACTION_H__
+#ifndef DALI_TEST_PLATFORM_ABSTRACTION_H
+#define DALI_TEST_PLATFORM_ABSTRACTION_H
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// EXTERNAL INCLUDES
#include <stdint.h>
+
#include <cstring>
-#include <dali/public-api/images/image-operations.h>
+#include <string>
+#include <vector>
// INTERNAL INCLUDES
-#include <dali/devel-api/common/set-wrapper.h>
#include <dali/integration-api/platform-abstraction.h>
+#include <dali/public-api/math/vector2.h>
#include "test-trace-call-stack.h"
-
namespace Dali
{
-
/**
* Concrete implementation of the platform abstraction class.
*/
-class DALI_IMPORT_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
+class DALI_CORE_API TestPlatformAbstraction : public Dali::Integration::PlatformAbstraction
{
-
public:
-
- struct Resources
- {
- bool loaded;
- Integration::ResourceId loadedId;
- Integration::ResourceTypeId loadedType;
- Integration::ResourcePointer loadedResource;
-
- bool loadFailed;
- Integration::ResourceId loadFailedId;
- Integration::ResourceFailure loadFailure;
- };
-
- struct LoadFileResult
- {
- inline LoadFileResult()
- : loadResult(false)
- {
-
- }
-
- bool loadResult;
- Dali::Vector< unsigned char> buffer;
- };
-
/**
* Constructor
*/
/**
* Destructor
*/
- virtual ~TestPlatformAbstraction();
+ ~TestPlatformAbstraction() override;
/**
- * @copydoc PlatformAbstraction::GetTimeMicroseconds()
+ * @copydoc PlatformAbstraction::GetClosestImageSize()
*/
- virtual void GetTimeMicroseconds(unsigned int &seconds, unsigned int µSeconds);
+ ImageDimensions GetClosestImageSize(const std::string& filename,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection) override;
/**
- * @copydoc PlatformAbstraction::Suspend()
+ * @copydoc PlatformAbstraction::GetClosestImageSize()
*/
- virtual void Suspend();
+ ImageDimensions GetClosestImageSize(Integration::ResourcePointer resourceBuffer,
+ ImageDimensions size,
+ FittingMode::Type fittingMode,
+ SamplingMode::Type samplingMode,
+ bool orientationCorrection) override;
/**
- * @copydoc PlatformAbstraction::Resume()
+ * @copydoc PlatformAbstraction::LoadResourceSynchronously()
*/
- virtual void Resume();
+ Integration::ResourcePointer LoadImageSynchronously(const Integration::BitmapResourceType& resourceType, const std::string& resourcePath) override;
/**
- * @copydoc PlatformAbstraction::GetClosestImageSize()
+ * @copydoc PlatformAbstraction::DecodeBuffer()
*/
- virtual ImageDimensions GetClosestImageSize( const std::string& filename,
- ImageDimensions size,
- FittingMode::Type fittingMode,
- SamplingMode::Type samplingMode,
- bool orientationCorrection );
+ Integration::BitmapPtr DecodeBuffer(const Dali::Integration::BitmapResourceType& resourceType, uint8_t* buffer, size_t size) override;
/**
- * @copydoc PlatformAbstraction::GetClosestImageSize()
+ * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
*/
- virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
- ImageDimensions size,
- FittingMode::Type fittingMode,
- SamplingMode::Type samplingMode,
- bool orientationCorrection );
+ bool LoadShaderBinaryFile(const std::string& filename, Dali::Vector<unsigned char>& buffer) const override;
/**
- * @copydoc PlatformAbstraction::LoadResource()
+ * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
*/
- virtual void LoadResource(const Integration::ResourceRequest& request);
+ virtual bool SaveShaderBinaryFile(const std::string& filename, const unsigned char* buffer, unsigned int numBytes) const override
+ {
+ return true;
+ }
/**
- * @copydoc PlatformAbstraction::LoadResourceSynchronously()
+ * @copydoc PlatformAbstraction::StartTimer()
*/
- virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
+ uint32_t StartTimer(uint32_t milliseconds, CallbackBase* callback) override;
- /**
- * @copydoc PlatformAbstraction::DecodeBuffer()
+ /*
+ * @copydoc PlatformAbstraction::CancelTimer()
*/
- virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
+ void CancelTimer(uint32_t timerId) override;
+
+public: // TEST FUNCTIONS
+ // Enumeration of Platform Abstraction methods
+ typedef enum
+ {
+ LoadResourceSynchronouslyFunc,
+ LoadShaderBinaryFileFunc,
+ SaveShaderBinaryFileFunc
+ } TestFuncEnum;
+
+ /** Call this every test */
+ void Initialize();
+
+ inline void EnableTrace(bool enable)
+ {
+ mTrace.Enable(enable);
+ }
+ inline void ResetTrace()
+ {
+ mTrace.Reset();
+ }
+ inline TraceCallStack& GetTrace()
+ {
+ return mTrace;
+ }
/**
- * @copydoc PlatformAbstraction::CancelLoad()
+ * @brief Checks if a platform function was called
+ * @param[in] func The function to check
+ * @return true if the function was called
*/
- virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
+ bool WasCalled(TestFuncEnum func);
/**
- * @copydoc PlatformAbstraction::GetResources()
+ * @brief Sets the result to return when IsLoading is called by Core.
+ * @param[in] result The result to set.
*/
- virtual void GetResources(Integration::ResourceCache& cache);
+ void SetIsLoadingResult(bool result);
/**
- * @copydoc PlatformAbstraction::IsLoading()
+ * @brief Clears all resource queues
*/
- virtual bool IsLoading();
+ void ClearReadyResources();
/**
- * @copydoc PlatformAbstraction::GetDefaultFontSize()
+ * @brief Sets the value returned by GetClosestImageSize.
+ * @param[in] size The size that should be returned.
*/
- virtual int GetDefaultFontSize() const;
+ void SetClosestImageSize(const Vector2& size);
/**
- * @copydoc PlatformAbstraction::SetDpi()
+ * @brief Sets the result return by LoadFile.
+ * @param[in] result The value that LoadFile should return.
+ * @param[in] buffer The buffer of the loaded file.
*/
- virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
+ void SetLoadFileResult(bool result, Dali::Vector<unsigned char>& buffer);
/**
- * @copydoc PlatformAbstraction::LoadFile()
+ * @brief Sets the SaveFile result
+ * @param[in] result The value that SaveFile should return
*/
- virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
+ void SetSaveFileResult(bool result);
/**
- * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
+ * @brief Sets the resource loaded by LoadResourceSynchronously
+ * @param[in] resource The loaded resource
*/
- virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer
-) const;
-
- virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
+ void SetSynchronouslyLoadedResource(Integration::ResourcePointer resource);
/**
- * @copydoc PlatformAbstraction::SaveFile()
+ * @brief Sets the bitmap returned by DecodeBuffer()
+ * @param[in] bitmap The decoded bitmap
*/
- virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes) const;
+ void SetDecodedBitmap(Integration::BitmapPtr bitmap);
- virtual void JoinLoaderThreads();
+ /**
+ * @brief Triggers the previously stored callback function
+ */
+ void TriggerTimer();
-public: // TEST FUNCTIONS
+private:
+ TestPlatformAbstraction(const TestPlatformAbstraction&); ///< Undefined
+ TestPlatformAbstraction& operator=(const TestPlatformAbstraction&); ///< Undefined
- // Enumeration of Platform Abstraction methods
- typedef enum
+private:
+ struct LoadFileResult
{
- GetTimeMicrosecondsFunc,
- SuspendFunc,
- ResumeFunc,
- LoadResourceFunc,
- SaveFileFunc,
- LoadFileFunc,
- LoadShaderBinaryFileFunc,
- SaveShaderBinaryFileFunc,
- CancelLoadFunc,
- GetResourcesFunc,
- IsLoadingFunc,
- SetDpiFunc,
- JoinLoaderThreadsFunc
- } TestFuncEnum;
-
- /** Call this every test */
- void Initialize();
-
- inline void EnableTrace(bool enable) { mTrace.Enable(enable); }
- inline void ResetTrace() { mTrace.Reset(); }
- inline TraceCallStack& GetTrace() { return mTrace; }
-
- bool WasCalled(TestFuncEnum func);
-
- void SetGetTimeMicrosecondsResult(size_t sec, size_t usec);
-
- void IncrementGetTimeResult(size_t milliseconds);
-
- void SetIsLoadingResult(bool result);
-
- void SetGetDefaultFontFamilyResult(std::string result);
-
- void SetGetDefaultFontSizeResult(float result);
-
- void SetGetFontPathResult(std::string& result);
-
- void ClearReadyResources();
-
- void SetResourceLoaded(Integration::ResourceId loadedId,
- Integration::ResourceTypeId loadedType,
- Integration::ResourcePointer loadedResource);
-
- void SetResourceLoadFailed(Integration::ResourceId id,
- Integration::ResourceFailure failure);
-
- Integration::ResourceRequest* GetRequest();
+ inline LoadFileResult()
+ : loadResult(false)
+ {
+ }
- void DiscardRequest();
+ bool loadResult;
+ Dali::Vector<unsigned char> buffer;
+ };
- void SetClosestImageSize(const Vector2& size);
+ mutable TraceCallStack mTrace{true, "PlatformAbstraction::"};
+ bool mIsLoadingResult;
+ ImageDimensions mClosestSize;
- void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
+ LoadFileResult mLoadFileResult;
+ bool mSaveFileResult;
- void SetSaveFileResult( bool result );
+ Integration::ResourcePointer mSynchronouslyLoadedResource;
+ Integration::BitmapPtr mDecodedBitmap;
-private:
- mutable TraceCallStack mTrace;
- size_t mSeconds;
- size_t mMicroSeconds;
- bool mIsLoadingResult;
- Resources mResources;
- Integration::ResourceRequest* mRequest;
- Vector2 mSize;
- Vector2 mClosestSize;
-
- LoadFileResult mLoadFileResult;
- bool mSaveFileResult;
+ uint32_t mTimerId;
+ CallbackBase* mCallbackFunction;
};
-} // Dali
+} // namespace Dali
-#endif /* __DALI_TET_PLATFORM_ABSTRACTION_H__ */
+#endif /* DALI_TEST_PLATFORM_ABSTRACTION_H */