(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 673e1af..d9d3247 100644 (file)
 // 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 "test-trace-call-stack.h"
 
-
 namespace Dali
 {
 
@@ -41,29 +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;
-  };
-
-  struct LoadFileResult
-  {
-    inline LoadFileResult()
-    : loadResult(false)
-    {
-
-    }
-
-    bool loadResult;
-    Dali::Vector< unsigned char> buffer;
-  };
+  typedef Vector< Integration::ResourceRequest* > ResourceRequestContainer;
 
   /**
    * Constructor
@@ -76,11 +53,6 @@ public:
   virtual ~TestPlatformAbstraction();
 
   /**
-   * @copydoc PlatformAbstraction::GetTimeMicroseconds()
-   */
-  virtual void GetTimeMicroseconds(unsigned int &seconds, unsigned int &microSeconds);
-
-  /**
    * @copydoc PlatformAbstraction::Suspend()
    */
   virtual void Suspend();
@@ -139,11 +111,6 @@ public:
   virtual bool IsLoading();
 
   /**
-   * @copydoc PlatformAbstraction::GetDefaultFontDescription()
-   */
-  virtual void GetDefaultFontDescription( std::string& family, std::string& style ) const;
-
-  /**
    * @copydoc PlatformAbstraction::GetDefaultFontSize()
    */
   virtual int GetDefaultFontSize() const;
@@ -161,15 +128,17 @@ public:
   /**
    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
    */
-  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; }
+  virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
 
   /**
    * @copydoc PlatformAbstraction::SaveFile()
    */
-  virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes) const;
+  virtual bool SaveFile(const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
+
+ /**
+  * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
+  */
+  virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const { return true; }
 
   virtual void JoinLoaderThreads();
 
@@ -178,10 +147,10 @@ public: // TEST FUNCTIONS
   // Enumeration of Platform Abstraction methods
   typedef enum
   {
-    GetTimeMicrosecondsFunc,
     SuspendFunc,
     ResumeFunc,
     LoadResourceFunc,
+    LoadResourceSynchronouslyFunc,
     SaveFileFunc,
     LoadFileFunc,
     LoadShaderBinaryFileFunc,
@@ -190,7 +159,7 @@ public: // TEST FUNCTIONS
     GetResourcesFunc,
     IsLoadingFunc,
     SetDpiFunc,
-    JoinLoaderThreadsFunc
+    JoinLoaderThreadsFunc,
   } TestFuncEnum;
 
   /** Call this every test */
@@ -200,51 +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);
 
+  /**
+   * @brief Retrieves the latest resource request
+   * @return A pointer to the latest resource request.
+   */
   Integration::ResourceRequest* GetRequest();
 
+  /**
+   * @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;
+
+  /**
+   * @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);
 
+  /**
+   * @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 );
 
+  /**
+   * @brief Sets the resource loaded by LoadResourceSynchronously
+   * @param[in] resource The loaded resource
+   */
+  void SetSynchronouslyLoadedResource( Integration::ResourcePointer resource );
+
 private:
+
+  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;
+
   mutable TraceCallStack        mTrace;
-  size_t                        mSeconds;
-  size_t                        mMicroSeconds;
   bool                          mIsLoadingResult;
-  Resources                     mResources;
-  Integration::ResourceRequest* mRequest;
+  int                           mGetDefaultFontSizeResult;
+  LoadedResourceContainer       mLoadedResourcesQueue;
+  FailedLoadContainer           mFailedLoadQueue;
+  ResourceRequestContainer      mResourceRequests;
   Vector2                       mSize;
   Vector2                       mClosestSize;
 
   LoadFileResult                mLoadFileResult;
   bool                          mSaveFileResult;
+
+  Integration::ResourcePointer  mSynchronouslyLoadedResource;
 };
 
 } // Dali