(Automated Tests) Platform Abstraction now handles multiple resource requests
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-platform-abstraction.h
index 5c70e97..d9d3247 100644 (file)
@@ -1,34 +1,34 @@
 #ifndef __DALI_TEST_PLATFORM_ABSTRACTION_H__
 #define __DALI_TEST_PLATFORM_ABSTRACTION_H__
 
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 // EXTERNAL INCLUDES
-#include <set>
 #include <stdint.h>
 #include <cstring>
+#include <string>
+#include <vector>
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/platform-abstraction.h>
 
-#include <dali/integration-api/glyph-set.h>
 #include "test-trace-call-stack.h"
 
-
 namespace Dali
 {
 
@@ -40,37 +40,7 @@ class DALI_IMPORT_API TestPlatformAbstraction : public Dali::Integration::Platfo
 
 public:
 
-  struct Resources
-  {
-    bool                         loaded;
-    Integration::ResourceId      loadedId;
-    Integration::ResourceTypeId  loadedType;
-    Integration::ResourcePointer loadedResource;
-
-    bool                         loadFailed;
-    Integration::ResourceId      loadFailedId;
-    Integration::ResourceFailure loadFailure;
-
-    bool                         saved;
-    Integration::ResourceId      savedId;
-    Integration::ResourceTypeId  savedType;
-
-    bool                         saveFailed;
-    Integration::ResourceId      saveFailedId;
-    Integration::ResourceFailure saveFailure;
-  };
-
-  struct LoadFileResult
-  {
-    inline LoadFileResult()
-    : loadResult(false)
-    {
-
-    }
-
-    bool loadResult;
-    std::vector< unsigned char> buffer;
-  };
+  typedef Vector< Integration::ResourceRequest* > ResourceRequestContainer;
 
   /**
    * Constructor
@@ -83,11 +53,6 @@ public:
   virtual ~TestPlatformAbstraction();
 
   /**
-   * @copydoc PlatformAbstraction::GetTimeMicroseconds()
-   */
-  virtual void GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds);
-
-  /**
    * @copydoc PlatformAbstraction::Suspend()
    */
   virtual void Suspend();
@@ -97,13 +62,23 @@ public:
    */
   virtual void Resume();
 
-  virtual void GetClosestImageSize( const std::string& filename,
-                                    const ImageAttributes& attributes,
-                                    Vector2& closestSize);
+  /**
+   * @copydoc PlatformAbstraction::GetClosestImageSize()
+   */
+  virtual ImageDimensions GetClosestImageSize( const std::string& filename,
+                                                 ImageDimensions size,
+                                                 FittingMode::Type fittingMode,
+                                                 SamplingMode::Type samplingMode,
+                                                 bool orientationCorrection );
 
-  virtual void GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
-                                    const ImageAttributes& attributes,
-                                    Vector2& closestSize);
+  /**
+   * @copydoc PlatformAbstraction::GetClosestImageSize()
+   */
+  virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
+                                               ImageDimensions size,
+                                               FittingMode::Type fittingMode,
+                                               SamplingMode::Type samplingMode,
+                                               bool orientationCorrection );
 
   /**
    * @copydoc PlatformAbstraction::LoadResource()
@@ -116,9 +91,9 @@ public:
   virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath );
 
   /**
-   * @copydoc PlatformAbstraction::SaveResource()
+   * @copydoc PlatformAbstraction::DecodeBuffer()
    */
-  virtual void SaveResource(const Integration::ResourceRequest& request);
+  virtual Integration::BitmapPtr DecodeBuffer( const Dali::Integration::ResourceType& resourceType, uint8_t * buffer, size_t size );
 
   /**
    * @copydoc PlatformAbstraction::CancelLoad()
@@ -136,42 +111,9 @@ public:
   virtual bool IsLoading();
 
   /**
-   * @copydoc PlatformAbstraction::GetDefaultFontFamily()
-   */
-  virtual std::string GetDefaultFontFamily() const;
-
-  /**
    * @copydoc PlatformAbstraction::GetDefaultFontSize()
    */
-  virtual const float GetDefaultFontSize() const;
-
-  virtual const Dali::PixelSize GetFontLineHeightFromCapsHeight(const std::string& fontFamily, const std::string& fontStyle, const CapsHeight& capsHeight) const;
-
-  /**
-   * @copydoc PlatformAbstraction::GetGlyphData()
-   */
-  virtual Integration::GlyphSet* GetGlyphData ( const Integration::TextResourceType& textRequest,
-                                                const std::string& fontFamily,
-                                                bool getImageData ) const;
-
-  /**
-   * @copydoc PlatformAbstraction::GetCachedGlyphData()
-   */
-  virtual Integration::GlyphSet* GetCachedGlyphData( const Integration::TextResourceType& textRequest,
-                                                     const std::string& fontFamily ) const;
-
-
-  /**
-   * @copydoc PlatformAbstraction::GetGlobalMetrics()
-   */
-  virtual void GetGlobalMetrics( const std::string& fontFamily,
-                                 const std::string& fontStyle,
-                                 Integration::GlobalMetrics& globalMetrics ) const;
-
-  /**
-   * @copydoc PlatformAbstraction::GetFontPath()
-   */
-  virtual std::string GetFontPath(const std::string& family, bool bold, bool italic) const;
+  virtual int GetDefaultFontSize() const;
 
   /**
    * @copydoc PlatformAbstraction::SetDpi()
@@ -179,95 +121,45 @@ public:
   virtual void SetDpi (unsigned int dpiHorizontal, unsigned int dpiVertical);
 
   /**
-   * @copydoc PlatformAbstraction::GetFontFamilyForChars()
-   */
-  virtual std::string GetFontFamilyForChars(const TextArray& charsRequested) const;
-
-  /**
-   * @copydoc PlatformAbstraction::AllGlyphsSupported()
-   */
-  virtual bool AllGlyphsSupported(const std::string& name, const std::string& fontStyle, const TextArray& text) const;
-
-  /**
-   * @copydoc PlatformAbstraction::ValidateFontFamilyName()
-   */
-  virtual bool ValidateFontFamilyName(const std::string& fontFamily, const std::string& fontStyle, bool& isDefaultSystemFont, std::string& closestMatch, std::string& closestStyleMatch) const;
-
-  /**
-   * @copydoc PlatformAbstraction::GetFontList()
+   * @copydoc PlatformAbstraction::LoadFile()
    */
-  virtual std::vector<std::string> GetFontList( PlatformAbstraction::FontListMode mode ) const;
+  virtual bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
 
   /**
-   * @copydoc PlatformAbstraction::LoadFile()
+   * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
    */
-  virtual bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const;
+  virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
 
   /**
    * @copydoc PlatformAbstraction::SaveFile()
    */
-  virtual bool SaveFile(const std::string& filename, std::vector< unsigned char >& buffer) const;
-
-  virtual void JoinLoaderThreads();
-
-  virtual void UpdateDefaultsFromDevice();
-
-  virtual Integration::DynamicsFactory* GetDynamicsFactory();
-
-  virtual bool ReadGlobalMetricsFromCache( const std::string& fontFamily,
-                                           const std::string& fontStyle,
-                                           Integration::GlobalMetrics& globalMetrics );
-
-  virtual void WriteGlobalMetricsToCache( const std::string& fontFamily,
-                                          const std::string& fontStyle,
-                                          const Integration::GlobalMetrics& globalMetrics );
-
-  virtual bool ReadMetricsFromCache( const std::string& fontFamily,
-                                     const std::string& fontStyle,
-                                     std::vector<Integration::GlyphMetrics>& glyphMetricsContainer );
-  virtual void WriteMetricsToCache( const std::string& fontFamily,
-                                    const std::string& fontStyle,
-                                    const Integration::GlyphSet& glyphSet );
-
+  virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
 
-  virtual void GetFileNamesFromDirectory( const std::string& directoryName,
-                                          std::vector<std::string>& fileNames );
+ /**
+  * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
+  */
+  virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
 
-  virtual Integration::ImageDataPtr GetGlyphImage( const std::string& fontFamily, const std::string& fontStyle, float fontSize, uint32_t character ) const;
+  virtual void JoinLoaderThreads();
 
 public: // TEST FUNCTIONS
 
   // Enumeration of Platform Abstraction methods
   typedef enum
   {
-    GetTimeMicrosecondsFunc,
     SuspendFunc,
     ResumeFunc,
     LoadResourceFunc,
-    SaveResourceFunc,
+    LoadResourceSynchronouslyFunc,
     SaveFileFunc,
     LoadFileFunc,
+    LoadShaderBinaryFileFunc,
+    SaveShaderBinaryFileFunc,
     CancelLoadFunc,
     GetResourcesFunc,
     IsLoadingFunc,
-    GetDefaultFontFamilyFunc,
-    GetDefaultFontSizeFunc,
-    GetFontLineHeightFromCapsHeightFunc,
-    GetGlyphDataFunc,
-    GetCachedGlyphDataFunc,
     SetDpiFunc,
-    GetFontPathFunc,
     JoinLoaderThreadsFunc,
-    GetFontFamilyForCharsFunc,
-    AllGlyphsSupportedFunc,
-    ValidateFontFamilyNameFunc,
-    UpdateDefaultsFromDeviceFunc,
-    GetDynamicsFactoryFunc,
-    ValidateGetFontListFunc,
-    ReadGlobalMetricsFromCacheFileFunc,
-    WriteGlobalMetricsToCacheFileFunc,
-    ReadMetricsFromCacheFileFunc,
-    WriteMetricsToCacheFileFunc,
   } TestFuncEnum;
 
   /** Call this every test */
@@ -277,72 +169,144 @@ public: // TEST FUNCTIONS
   inline void ResetTrace() { mTrace.Reset(); }
   inline TraceCallStack& GetTrace() { return mTrace; }
 
+  /**
+   * @brief Checks if a platform function was called
+   * @param[in] func The function to check
+   * @return true if the function was called
+   */
   bool WasCalled(TestFuncEnum func);
 
-  void SetGetTimeMicrosecondsResult(size_t sec, size_t usec);
-
-  void IncrementGetTimeResult(size_t milliseconds);
-
+  /**
+   * @brief Sets the result to return when IsLoading is called by Core.
+   * @param[in] result The result to set.
+   */
   void SetIsLoadingResult(bool result);
 
-  void SetGetDefaultFontFamilyResult(std::string result);
-
+  /**
+   * @brief Sets the value returned by GetDefaultFontSize
+   * @param[in] result The value to return
+   */
   void SetGetDefaultFontSizeResult(float result);
 
-  void SetGetFontPathResult(std::string& result);
-
+  /**
+   * @brief Clears all resource queues
+   */
   void ClearReadyResources();
 
+  /**
+   * @brief Sets a particular resource request as loaded.
+   * @param[in] loadedId The ResourceID of the resource that has been loaded.
+   * @param[in] loadedType The type of resource that has been loaded.
+   * @param[in] loadedResource A pointer to the resource that has been loaded.
+   */
   void SetResourceLoaded(Integration::ResourceId  loadedId,
                          Integration::ResourceTypeId  loadedType,
                          Integration::ResourcePointer loadedResource);
 
+  /**
+   * @brief Sets a particular resource request as load failure.
+   * @param[in] id The ID of the failed resource request.
+   * @param[in] failure The type of failure.
+   */
   void SetResourceLoadFailed(Integration::ResourceId  id,
                              Integration::ResourceFailure failure);
 
-  void SetResourceSaved(Integration::ResourceId      savedId,
-                        Integration::ResourceTypeId  savedType);
+  /**
+   * @brief Retrieves the latest resource request
+   * @return A pointer to the latest resource request.
+   */
+  Integration::ResourceRequest* GetRequest();
 
-  void SetResourceSaveFailed(Integration::ResourceId  id,
-                             Integration::ResourceFailure failure);
+  /**
+   * @brief Retrieves a reference to a container of all the resource requests.
+   * @return A reference to a container of all the resource requests.
+   */
+  const ResourceRequestContainer& GetAllRequests() const;
 
-  Integration::ResourceRequest* GetRequest();
+  /**
+   * @brief Sets all resource requests as loaded.
+   */
+  void SetAllResourceRequestsAsLoaded();
+
+  /**
+   * @brief Sets all resource requests as loaded.
+   * @param[in] failure The failure type
+   */
+  void SetAllResourceRequestsAsFailed( Integration::ResourceFailure failure );
 
+  /**
+   * @brief Discards all current resource requests.
+   */
   void DiscardRequest();
 
+  /**
+   * @brief Sets the value returned by GetClosestImageSize.
+   * @param[in] size The size that should be returned.
+   */
   void SetClosestImageSize(const Vector2& size);
 
-  void SetLoadFileResult( bool result, std::vector< unsigned char >& buffer );
+  /**
+   * @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.
+   */
+  void SetLoadFileResult( bool result, Dali::Vector< unsigned char >& buffer );
 
+  /**
+   * @brief Sets the SaveFile result
+   * @param[in] result The value that SaveFile should return
+   */
   void SetSaveFileResult( bool result );
 
-  PlatformAbstraction::FontListMode GetLastFontListMode( );
+  /**
+   * @brief Sets the resource loaded by LoadResourceSynchronously
+   * @param[in] resource The loaded resource
+   */
+  void SetSynchronouslyLoadedResource( Integration::ResourcePointer resource );
 
-  void SetReadGlobalMetricsResult( bool success, Integration::GlobalMetrics& globalMetrics );
+private:
 
-  void SetReadMetricsResult( bool success, std::vector<Integration::GlyphMetrics>& glyphMetricsContainer );
+  struct LoadedResource
+  {
+    Integration::ResourceId      id;
+    Integration::ResourceTypeId  type;
+    Integration::ResourcePointer resource;
+  };
 
+  struct FailedLoad
+  {
+    Integration::ResourceId      id;
+    Integration::ResourceFailure failure;
+  };
+
+  struct LoadFileResult
+  {
+    inline LoadFileResult()
+    : loadResult(false)
+    {
+
+    }
+
+    bool loadResult;
+    Dali::Vector< unsigned char> buffer;
+  };
+
+  typedef std::vector< LoadedResource > LoadedResourceContainer;
+  typedef std::vector< FailedLoad > FailedLoadContainer;
 
-private:
   mutable TraceCallStack        mTrace;
-  size_t                        mSeconds;
-  size_t                        mMicroSeconds;
   bool                          mIsLoadingResult;
-  std::string                   mGetDefaultFontFamilyResult;
-  float                         mGetDefaultFontSizeResult;
-  std::string                   mGetFontPathResult;
-  Resources                     mResources;
-  Integration::ResourceRequest* mRequest;
+  int                           mGetDefaultFontSizeResult;
+  LoadedResourceContainer       mLoadedResourcesQueue;
+  FailedLoadContainer           mFailedLoadQueue;
+  ResourceRequestContainer      mResourceRequests;
   Vector2                       mSize;
   Vector2                       mClosestSize;
-  bool                          mReadGlobalMetricsResult;
-  bool                          mReadMetricsResult;
-  Integration::GlobalMetrics mReadGlobalMetrics;
-  std::vector<Integration::GlyphMetrics> mReadMetrics;
 
   LoadFileResult                mLoadFileResult;
   bool                          mSaveFileResult;
-  mutable FontListMode          mFontListMode;
+
+  Integration::ResourcePointer  mSynchronouslyLoadedResource;
 };
 
 } // Dali