(Automated Tests) Platform Abstraction now handles multiple resource requests 52/68552/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 5 May 2016 19:23:15 +0000 (20:23 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 5 May 2016 19:23:15 +0000 (20:23 +0100)
Change-Id: I04beb35818241ce0a3f0a2f343ecbc26ef781b2c

automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-platform-abstraction.h

index 2f62474767f15bcb72973a3e2d0bc7f9f1bfbffd..db22b8638bbaa96b72bf8c8ba808e12914affc51 100644 (file)
@@ -26,12 +26,14 @@ TestPlatformAbstraction::TestPlatformAbstraction()
 : mTrace(),
   mIsLoadingResult( false ),
   mGetDefaultFontSizeResult( 0 ),
-  mResources(),
-  mRequest( NULL ),
+  mLoadedResourcesQueue(),
+  mFailedLoadQueue(),
+  mResourceRequests(),
   mSize(),
   mClosestSize(),
   mLoadFileResult(),
-  mSaveFileResult( false )
+  mSaveFileResult( false ),
+  mSynchronouslyLoadedResource()
 {
   Initialize();
 }
@@ -78,18 +80,14 @@ void TestPlatformAbstraction::LoadResource(const Integration::ResourceRequest& r
   out << "Type:" << request.GetType()->id << ", Path: " << request.GetPath() << std::endl ;
 
   mTrace.PushCall("LoadResource", out.str());
-  if(mRequest != NULL)
-  {
-    delete mRequest;
-    tet_infoline ("Warning: multiple resource requests not handled by Test Suite. You may see unexpected errors");
-  }
-  mRequest = new Integration::ResourceRequest(request);
+
+  mResourceRequests.PushBack( new Integration::ResourceRequest(request) );
 }
 
 Integration::ResourcePointer TestPlatformAbstraction::LoadResourceSynchronously( const Integration::ResourceType& resourceType, const std::string& resourcePath )
 {
   mTrace.PushCall("LoadResourceSynchronously", "");
-  return mResources.loadedResource;
+  return mSynchronouslyLoadedResource;
 }
 
 Integration::BitmapPtr TestPlatformAbstraction::DecodeBuffer( const Integration::ResourceType& resourceType, uint8_t * buffer, size_t size )
@@ -107,13 +105,19 @@ void TestPlatformAbstraction::GetResources(Integration::ResourceCache& cache)
 {
   mTrace.PushCall("GetResources", "");
 
-  if(mResources.loaded)
+  while( !mLoadedResourcesQueue.empty() )
   {
-    cache.LoadResponse( mResources.loadedId, mResources.loadedType, mResources.loadedResource, Integration::RESOURCE_COMPLETELY_LOADED );
+    LoadedResource loaded( *mLoadedResourcesQueue.begin() );
+    mLoadedResourcesQueue.erase( mLoadedResourcesQueue.begin() );
+    cache.LoadResponse( loaded.id, loaded.type, loaded.resource, Integration::RESOURCE_COMPLETELY_LOADED );
   }
-  if(mResources.loadFailed)
+
+  // iterate through the resources which failed to load
+  while( !mFailedLoadQueue.empty() )
   {
-    cache.LoadFailed( mResources.loadFailedId, mResources.loadFailure );
+    FailedLoad failed( *mFailedLoadQueue.begin() );
+    mFailedLoadQueue.erase( mFailedLoadQueue.begin() );
+    cache.LoadFailed( failed.id, failed.failure );
   }
 }
 
@@ -172,14 +176,11 @@ void TestPlatformAbstraction::Initialize()
 {
   mTrace.Reset();
   mTrace.Enable(true);
-  memset(&mResources, 0, sizeof(Resources));
+  mLoadedResourcesQueue.clear();
+  mFailedLoadQueue.clear();
+  mResourceRequests.Clear();
   mIsLoadingResult=false;
-
-  if(mRequest)
-  {
-    delete mRequest;
-    mRequest = 0;
-  }
+  mSynchronouslyLoadedResource.Reset();
 }
 
 bool TestPlatformAbstraction::WasCalled(TestFuncEnum func)
@@ -210,36 +211,76 @@ void TestPlatformAbstraction::SetIsLoadingResult(bool result)
 
 void TestPlatformAbstraction::ClearReadyResources()
 {
-  memset(&mResources, 0, sizeof(Resources));
+  mLoadedResourcesQueue.clear();
+  mFailedLoadQueue.clear();
+  mSynchronouslyLoadedResource.Reset();
 }
 
 void TestPlatformAbstraction::SetResourceLoaded(Integration::ResourceId  loadedId,
                                                 Integration::ResourceTypeId  loadedType,
                                                 Integration::ResourcePointer loadedResource)
 {
-  mResources.loaded = true;
-  mResources.loadedId = loadedId;
-  mResources.loadedType = loadedType;
-  mResources.loadedResource = loadedResource;
+  LoadedResource loadedInfo;
+  loadedInfo.id = loadedId;
+  loadedInfo.type = loadedType;
+  loadedInfo.resource = loadedResource;
+  mLoadedResourcesQueue.push_back( loadedInfo );
 }
 
 void TestPlatformAbstraction::SetResourceLoadFailed(Integration::ResourceId  id,
                                                     Integration::ResourceFailure failure)
 {
-  mResources.loadFailed = true;
-  mResources.loadFailedId = id;
-  mResources.loadFailure = failure;
+  FailedLoad failedInfo;
+  failedInfo.id = id;
+  failedInfo.failure = failure;
+  mFailedLoadQueue.push_back( failedInfo );
 }
 
 Integration::ResourceRequest* TestPlatformAbstraction::GetRequest()
 {
-  return mRequest;
+  Integration::ResourceRequest* request = NULL;
+
+  // Return last request
+  if( ! mResourceRequests.Empty() )
+  {
+    request = *( mResourceRequests.End() - 1 );
+  }
+
+  return request;
+}
+
+const TestPlatformAbstraction::ResourceRequestContainer& TestPlatformAbstraction::GetAllRequests() const
+{
+  return mResourceRequests;
+}
+
+void TestPlatformAbstraction::SetAllResourceRequestsAsLoaded()
+{
+  for( ResourceRequestContainer::Iterator iter = mResourceRequests.Begin(), endIter = mResourceRequests.End();
+       iter != endIter; ++iter )
+  {
+    Integration::ResourceRequest* request = *iter;
+    Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
+    Integration::ResourcePointer resource(bitmap);
+    bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, 80, 80, 80, 80);
+    SetResourceLoaded( request->GetId(), request->GetType()->id, resource );
+  }
+  mResourceRequests.Clear();
+}
+
+void TestPlatformAbstraction::SetAllResourceRequestsAsFailed( Integration::ResourceFailure failure )
+{
+  for( ResourceRequestContainer::Iterator iter = mResourceRequests.Begin(), endIter = mResourceRequests.End();
+       iter != endIter; ++iter )
+  {
+    SetResourceLoadFailed( (*iter)->GetId(), failure);
+  }
+  mResourceRequests.Clear();
 }
 
 void TestPlatformAbstraction::DiscardRequest()
 {
-  delete mRequest;
-  mRequest = NULL;
+  mResourceRequests.Clear();
 }
 
 void TestPlatformAbstraction::SetClosestImageSize(const Vector2& size)
@@ -261,4 +302,9 @@ void TestPlatformAbstraction::SetSaveFileResult( bool result )
   mSaveFileResult = result;
 }
 
+void TestPlatformAbstraction::SetSynchronouslyLoadedResource( Integration::ResourcePointer resource )
+{
+  mSynchronouslyLoadedResource = resource;
+}
+
 } // namespace Dali
index d7e05638329d01c8a747707b1a8f4fb3ab5288ac..d9d3247f85d3032764a7ae43e0ab44bbcd5458c0 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdint.h>
 #include <cstring>
 #include <string>
+#include <vector>
 
 // INTERNAL INCLUDES
 #include <dali/integration-api/platform-abstraction.h>
@@ -39,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
@@ -190,42 +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);
 
+  /**
+   * @brief Sets the result to return when IsLoading is called by Core.
+   * @param[in] result The result to set.
+   */
   void SetIsLoadingResult(bool result);
 
+  /**
+   * @brief Sets the value returned by GetDefaultFontSize
+   * @param[in] result The value to return
+   */
   void SetGetDefaultFontSizeResult(float 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;
   bool                          mIsLoadingResult;
   int                           mGetDefaultFontSizeResult;
-  Resources                     mResources;
-  Integration::ResourceRequest* mRequest;
+  LoadedResourceContainer       mLoadedResourcesQueue;
+  FailedLoadContainer           mFailedLoadQueue;
+  ResourceRequestContainer      mResourceRequests;
   Vector2                       mSize;
   Vector2                       mClosestSize;
 
   LoadFileResult                mLoadFileResult;
   bool                          mSaveFileResult;
+
+  Integration::ResourcePointer  mSynchronouslyLoadedResource;
 };
 
 } // Dali