From ab4d9466a1f5411fef3ebf4fa0af49a492aa3bac Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Thu, 5 May 2016 20:20:53 +0100 Subject: [PATCH] (Automated Tests) Platform Abstraction now handles multiple resource requests Also synchronized some dali-test-suite-utils.h/cpp with toolkit. Change-Id: I28b2ea64cd25d5107de4ea5dae175bbf01232a9f --- automated-tests/src/dali-devel/utc-Dali-Atlas.cpp | 2 +- .../dali-test-suite-utils.cpp | 27 ++++- .../dali-test-suite-utils/dali-test-suite-utils.h | 101 ++++++++++++++++ .../test-platform-abstraction.cpp | 110 ++++++++++++----- .../test-platform-abstraction.h | 131 +++++++++++++++++---- automated-tests/src/dali/utc-Dali-Image.cpp | 6 + .../src/dali/utc-Dali-NinePatchImages.cpp | 4 +- 7 files changed, 315 insertions(+), 66 deletions(-) diff --git a/automated-tests/src/dali-devel/utc-Dali-Atlas.cpp b/automated-tests/src/dali-devel/utc-Dali-Atlas.cpp index 549b058..bff4bab 100644 --- a/automated-tests/src/dali-devel/utc-Dali-Atlas.cpp +++ b/automated-tests/src/dali-devel/utc-Dali-Atlas.cpp @@ -43,7 +43,7 @@ void PrepareResourceImage( TestApplication& application, unsigned int imageWidth memset( pixbuffer, initialColor, imageHeight*imageWidth*bytesPerPixel); Integration::ResourcePointer resourcePtr(bitmap); - platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); + platform.SetSynchronouslyLoadedResource( resourcePtr ); } PixelDataPtr CreatePixelData(unsigned int width, unsigned int height, Pixel::Format pixelFormat) diff --git a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp index 0a90c8e..467bb52 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.cpp @@ -233,12 +233,27 @@ void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* lo DALI_TEST_EQUALS(str1.c_str(), str2, location); } -/** - * Test whether two strings are equal. - * @param[in] str1 The first string - * @param[in] str2 The second string - * @param[in] location The TEST_LOCATION macro should be used here - */ +void DALI_TEST_EQUALS( Property::Value& str1, const char* str2, const char* location) +{ + bool result = false; + + if( str1.GetType() == Property::STRING ) + { + std::string string; + str1.Get(string); + result = !string.compare(str2); + } + + if( result ) + { + tet_result(TET_PASS); + } + else + { + tet_result(TET_FAIL); + } +} + void DALI_TEST_EQUALS( const char* str1, const std::string &str2, const char* location) { DALI_TEST_EQUALS(str1, str2.c_str(), location); diff --git a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h index baeaa6a..7f81872 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h +++ b/automated-tests/src/dali/dali-test-suite-utils/dali-test-suite-utils.h @@ -153,6 +153,82 @@ inline bool CompareType(Degree q1, Degree q2, float epsilon) return CompareType(q1.degree, q2.degree, epsilon); } +template <> +inline bool CompareType(Property::Value q1, Property::Value q2, float epsilon) +{ + Property::Type type = q1.GetType(); + if( type != q2.GetType() ) + { + return false; + } + + switch(type) + { + case Property::BOOLEAN: + { + bool a, b; + q1.Get(a); + q2.Get(b); + return a == b; + break; + } + case Property::INTEGER: + { + int a, b; + q1.Get(a); + q2.Get(b); + return a == b; + break; + } + case Property::FLOAT: + { + float a, b; + q1.Get(a); + q2.Get(b); + return CompareType(a, b, epsilon); + break; + } + case Property::VECTOR2: + { + Vector2 a, b; + q1.Get(a); + q2.Get(b); + return CompareType(a, b, epsilon); + break; + } + case Property::VECTOR3: + { + Vector3 a, b; + q1.Get(a); + q2.Get(b); + return CompareType(a, b, epsilon); + break; + } + case Property::RECTANGLE: + case Property::VECTOR4: + { + Vector4 a, b; + q1.Get(a); + q2.Get(b); + return CompareType(a, b, epsilon); + break; + } + case Property::ROTATION: + { + Quaternion a, b; + q1.Get(a); + q2.Get(b); + return CompareType(a, b, epsilon); + break; + } + default: + return false; + } + + return false; +} + + bool operator==(TimePeriod a, TimePeriod b); std::ostream& operator<<( std::ostream& ostream, TimePeriod value ); std::ostream& operator<<( std::ostream& ostream, Radian angle ); @@ -196,6 +272,23 @@ inline void DALI_TEST_EQUALS(Type value1, Type value2, float epsilon, const char } } +template +inline void DALI_TEST_NOT_EQUALS(Type value1, Type value2, float epsilon, const char* location) +{ + if( CompareType(value1, value2, epsilon) ) + { + std::ostringstream o; + o << value1 << " != " << value2 << std::endl; + fprintf(stderr, "%s, checking %s", location, o.str().c_str()); + tet_result(TET_FAIL); + } + else + { + tet_result(TET_PASS); + } +} + + /** * Test whether two TimePeriods are within a certain distance of each other. * @param[in] value1 The first value @@ -316,6 +409,14 @@ inline void DALI_TEST_EQUALS( const std::string &str1, const * @param[in] str2 The second string * @param[in] location The TEST_LOCATION macro should be used here */ +void DALI_TEST_EQUALS( Property::Value& str1, const char* str2, const char* location); + +/** + * Test whether two strings are equal. + * @param[in] str1 The first string + * @param[in] str2 The second string + * @param[in] location The TEST_LOCATION macro should be used here + */ void DALI_TEST_EQUALS( const std::string &str1, const char* str2, const char* location); /** diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp index 2f62474..db22b86 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp +++ b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.cpp @@ -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 diff --git a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h index d7e0563..d9d3247 100644 --- a/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h +++ b/automated-tests/src/dali/dali-test-suite-utils/test-platform-abstraction.h @@ -22,6 +22,7 @@ #include #include #include +#include // INTERNAL INCLUDES #include @@ -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 diff --git a/automated-tests/src/dali/utc-Dali-Image.cpp b/automated-tests/src/dali/utc-Dali-Image.cpp index 6701067..bc95619 100644 --- a/automated-tests/src/dali/utc-Dali-Image.cpp +++ b/automated-tests/src/dali/utc-Dali-Image.cpp @@ -190,6 +190,12 @@ int UtcDaliImageSignalUploaded(void) application.Render(16); application.SendNotification(); + request = platform.GetRequest(); + if(request) + { + platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource); + } + //upload application.Render(16); application.SendNotification(); diff --git a/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp b/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp index 94a762a..8885918 100644 --- a/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp +++ b/automated-tests/src/dali/utc-Dali-NinePatchImages.cpp @@ -139,9 +139,9 @@ NinePatchImage CustomizeNinePatch( TestApplication& application, AddChildRegionsToImage( bitmap, ninePatchImageWidth, ninePatchImageHeight, requiredChildRegion, pixelFormat ); } - tet_infoline("Getting resource"); + tet_infoline("Setting resource as it's loaded synchronously"); Integration::ResourcePointer resourcePtr(bitmap); - platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr ); + platform.SetSynchronouslyLoadedResource( resourcePtr ); Image image = ResourceImage::New( "blah.#.png" ); -- 2.7.4