(GCC 6.2) Remove unused functions from automated tests
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-ImageFactory.cpp
index 59bc9ad..65833e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 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.
 #include <dali/internal/event/common/thread-local-storage.h>
 #include <dali/internal/event/images/image-factory.h>
 #include <dali/internal/event/resources/resource-ticket.h>
+#include <dali/internal/common/image-attributes.h>
 
 using namespace Dali;
 
 using Internal::ResourceTicketPtr;
 using Internal::ImageFactory;
 using Internal::ImageFactoryCache::RequestPtr;
-
+using Internal::ImageAttributes;
 
 namespace
 {
@@ -42,7 +43,7 @@ static void EmulateImageLoaded( TestApplication& application, unsigned int width
 {
   // emulate load success
   Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
-  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  ResourcePolicy::DISCARD );
+  Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS,  ResourcePolicy::OWNED_DISCARD );
   Integration::ResourcePointer resource( bitmap );
   bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, width, height, width, height );
   if( request )
@@ -67,27 +68,27 @@ int UtcDaliImageFactoryUseCachedRequest01(void)
 
   tet_infoline( "UtcDaliImageFactoryCachedRequest01 - Request same image more than once" );
 
-  Image image = Image::New( gTestImageFilename );
+  Image image = ResourceImage::New( gTestImageFilename );
 
   application.SendNotification();
   application.Render();
-  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
+  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceSynchronouslyFunc ) );
   application.GetPlatform().ResetTrace();
 
-  Image image2 = Image::New( gTestImageFilename );
+  Image image2 = ResourceImage::New( gTestImageFilename );
 
   application.SendNotification();
   application.Render();
 
-  // check resource is not loaded twice
-  DALI_TEST_CHECK( !application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
+  // Resource is loaded twice
+  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceSynchronouslyFunc ) );
   application.GetPlatform().ResetTrace();
 
-  Image image3 = Image::New( gTestImageFilename );
+  Image image3 = ResourceImage::New( gTestImageFilename );
 
   application.SendNotification();
   application.Render();
-  DALI_TEST_CHECK( !application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
+  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceSynchronouslyFunc ) );
   END_TEST;
 }
 
@@ -99,13 +100,13 @@ int UtcDaliImageFactoryUseCachedRequest02(void)
   // testing resource deletion when taken off stage
   tet_infoline( "UtcDaliImageFactoryCachedRequest02 - Discard previously requested resource" );
 
-  Image image = Image::New( gTestImageFilename, Image::Immediate, Image::Unused );
-  ImageActor actor = ImageActor::New( image );
+  Image image = ResourceImage::New( gTestImageFilename );
+  Actor actor = CreateRenderableActor( image );
 
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
+  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceSynchronouslyFunc ) );
   application.GetPlatform().ResetTrace();
 
   // Add actor to stage
@@ -124,16 +125,16 @@ int UtcDaliImageFactoryUseCachedRequest02(void)
   application.SendNotification();
 
   // Should find stale request in cache, so load image from filesystem
-  Image image2 = Image::New( gTestImageFilename );
+  Image image2 = ResourceImage::New( gTestImageFilename );
 
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
+  DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceSynchronouslyFunc ) );
   application.GetPlatform().ResetTrace();
 
   // Resource is reloaded
-  Image image3 = Image::New( gTestImageFilename );
+  Image image3 = ResourceImage::New( gTestImageFilename );
 
   application.SendNotification();
   application.Render();
@@ -153,22 +154,22 @@ int UtcDaliImageFactoryUseCachedRequest03(void)
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
   DALI_TEST_EQUALS( req, req2, TEST_LOCATION );
   DALI_TEST_EQUALS( ticket, ticket2, TEST_LOCATION );
 
   req2 = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket3 = imageFactory.Load( req2.Get() );
+  ResourceTicketPtr ticket3 = imageFactory.Load( *req2.Get() );
   DALI_TEST_EQUALS( req, req2, TEST_LOCATION );
   DALI_TEST_EQUALS( ticket, ticket3, TEST_LOCATION );
 
   // request differs in scaled size - not default size
-  ImageAttributes attr = ImageAttributes::New( 80, 160, Pixel::BGR8888 );
+  ImageAttributes attr = ImageAttributes::New( 80, 160);
   req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
-  ResourceTicketPtr ticket4 = imageFactory.Load( req2.Get() );
+  ResourceTicketPtr ticket4 = imageFactory.Load( *req2.Get() );
   DALI_TEST_CHECK( req != req2 );
   END_TEST;
 }
@@ -181,10 +182,10 @@ int UtcDaliImageFactoryUseCachedRequest04(void)
 
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
-  ImageAttributes attr = ImageAttributes::New( 80, 160, Pixel::BGR8888 );
+  ImageAttributes attr = ImageAttributes::New( 80, 160 );
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, &attr );
 
-  ImageAttributes attr2 = ImageAttributes::New( 80, 160, Pixel::BGR8888 );
+  ImageAttributes attr2 = ImageAttributes::New( 80, 160 );
   RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr2 );
   DALI_TEST_EQUALS( req, req2, TEST_LOCATION );
   END_TEST;
@@ -203,7 +204,7 @@ int UtcDaliImageFactoryCompatibleResource01(void)
 
   // request with default attributes ( size is 0,0 )
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -213,10 +214,11 @@ int UtcDaliImageFactoryCompatibleResource01(void)
   // emulate load success
   EmulateImageLoaded( application, 80, 80 );
 
+  // Request a second load using exact-match image size:
   ImageAttributes attr = ImageAttributes::New();
   attr.SetSize( 80, 80 );
   RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
-  ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
 
   DALI_TEST_CHECK( req != req2 ); // different requests
   DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
@@ -231,12 +233,12 @@ int UtcDaliImageFactoryCompatibleResource02(void)
 
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
-  Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetClosestImageSize(testSize);
+  Vector2 testSize( 2048.0f, 2048.0f );
+  application.GetPlatform().SetClosestImageSize( testSize );
 
   // request with default attributes ( size is 0,0 )
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -244,23 +246,57 @@ int UtcDaliImageFactoryCompatibleResource02(void)
   application.Render();
 
   // emulate load success
-  EmulateImageLoaded( application, 80, 80 );
+  EmulateImageLoaded( application, testSize.x, testSize.y );
 
-  // Request bigger size than actual image.
-  // This will load the same resource.
-  // However if image size changes later on to eg. 512*512 (file is overwritten),
-  // reissuing these two requests will load different resources.
+  // Request slightly bigger size than actual image.
+  // This will load the same resource as the ImageFactory cache uses a small fudge factor in matching.
   // See UtcDaliImageFactoryReload06
   ImageAttributes attr = ImageAttributes::New();
-  attr.SetSize( 92, 92 );
+  attr.SetSize( testSize.x + 1, testSize.y + 1 );
   RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
-  ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
 
   DALI_TEST_CHECK( req != req2 ); // different requests
   DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
   END_TEST;
 }
 
+// Different requests, incompatible resource, so two loads result:
+int UtcDaliImageFactoryInCompatibleResource(void)
+{
+  TestApplication application;
+  tet_infoline( "UtcDaliImageFactoryCompatibleResource02 - Two requests mapping to same resource." );
+
+  ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
+
+  Vector2 testSize(2048.0f, 2048.0f);
+  application.GetPlatform().SetClosestImageSize(testSize);
+
+  // request with default attributes ( size is 0,0 )
+  RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
+
+  application.SendNotification();
+  application.Render();
+  application.SendNotification();
+  application.Render();
+
+  // emulate load success
+  EmulateImageLoaded( application, testSize.x, testSize.y );
+
+  // Request substantially different size than actual image.
+  // This will issue a second resource load as difference in sizes is greater than
+  // the small fudge factor used in the ImageFactory cache.
+  ImageAttributes attr = ImageAttributes::New();
+  attr.SetSize( testSize.x - 16, testSize.y - 16 );
+  RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
+  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
+
+  DALI_TEST_CHECK( req != req2 ); // different requests
+  DALI_TEST_CHECK( ticket->GetId() != ticket2->GetId() ); // differnet resources
+  END_TEST;
+}
+
 // Different requests, compatible resource
 int UtcDaliImageFactoryCompatibleResource03(void)
 {
@@ -278,7 +314,7 @@ int UtcDaliImageFactoryCompatibleResource03(void)
 
   // request with default attributes ( size is 0,0 )
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, &attr );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -291,7 +327,7 @@ int UtcDaliImageFactoryCompatibleResource03(void)
   ImageAttributes attr2 = ImageAttributes::New();
   attr2.SetSize( 80, 80 );
   RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr2 );
-  ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
 
   DALI_TEST_CHECK( req != req2 ); // different requests
   DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
@@ -310,12 +346,12 @@ int UtcDaliImageFactoryReload01(void)
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
-  ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
   DALI_TEST_EQUALS( ticket, ticket2, TEST_LOCATION );
 
-  ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
   DALI_TEST_EQUALS( ticket, ticket3, TEST_LOCATION );
   END_TEST;
 }
@@ -332,7 +368,7 @@ int UtcDaliImageFactoryReload02(void)
   application.GetPlatform().SetClosestImageSize(testSize);
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -342,7 +378,7 @@ int UtcDaliImageFactoryReload02(void)
   DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
   application.GetPlatform().ResetTrace();
 
-  ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -356,7 +392,7 @@ int UtcDaliImageFactoryReload02(void)
   // emulate load success
   EmulateImageLoaded( application, 80, 80 );
 
-  ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -367,7 +403,7 @@ int UtcDaliImageFactoryReload02(void)
   DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
   application.GetPlatform().ResetTrace();
 
-  ticket3 = imageFactory.Reload( req.Get() );
+  ticket3 = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -390,7 +426,7 @@ int UtcDaliImageFactoryReload03(void)
   application.GetPlatform().SetClosestImageSize( testSize );
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -402,10 +438,10 @@ int UtcDaliImageFactoryReload03(void)
   application.GetPlatform().SetClosestImageSize( newSize );
 
   // Image file changed size, new resource request should be issued
-  ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
   DALI_TEST_CHECK( ticket != ticket2 );
 
-  ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
   DALI_TEST_EQUALS( ticket2, ticket3, TEST_LOCATION );
   END_TEST;
 }
@@ -422,7 +458,7 @@ int UtcDaliImageFactoryReload04(void)
   application.GetPlatform().SetClosestImageSize(testSize);
 
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -430,7 +466,7 @@ int UtcDaliImageFactoryReload04(void)
   DALI_TEST_CHECK( application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
   application.GetPlatform().ResetTrace();
 
-  ResourceTicketPtr ticket2 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -444,7 +480,7 @@ int UtcDaliImageFactoryReload04(void)
   // emulate load success
   EmulateImageLoaded( application, 80, 80 );
 
-  ResourceTicketPtr ticket3 = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket3 = imageFactory.Reload( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -457,7 +493,7 @@ int UtcDaliImageFactoryReload04(void)
   application.GetPlatform().ResetTrace();
 
   // still loading
-  ticket3 = imageFactory.Reload( req.Get() );
+  ticket3 = imageFactory.Reload( *req.Get() );
   application.SendNotification();
   application.Render();
   application.SendNotification();
@@ -490,13 +526,13 @@ int UtcDaliImageFactoryReload05(void)
   application.SendNotification();
   application.Render();
 
-  ResourceTicketPtr ticket = imageFactory.Reload( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Reload( *req.Get() );
 
   DALI_TEST_CHECK( !application.GetPlatform().WasCalled( TestPlatformAbstraction::LoadResourceFunc ) );
   DALI_TEST_CHECK( !ticket );
 
   // this happens when Image is put on stage
-  ticket = imageFactory.Load( req.Get() );
+  ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -505,7 +541,8 @@ int UtcDaliImageFactoryReload05(void)
   DALI_TEST_CHECK( ticket );
   application.GetPlatform().ResetTrace();
 
-  ticket = imageFactory.Reload( req.Get() );
+  ticket = imageFactory.Reload( *req.Get() );
+  DALI_TEST_CHECK( ticket );
 
   application.SendNotification();
   application.Render();
@@ -518,7 +555,8 @@ int UtcDaliImageFactoryReload05(void)
   // emulate load success
   EmulateImageLoaded( application, 80, 80 );
 
-  ticket = imageFactory.Reload( req.Get() );
+  ticket = imageFactory.Reload( *req.Get() );
+  DALI_TEST_CHECK( ticket );
 
   application.SendNotification();
   application.Render();
@@ -540,12 +578,12 @@ int UtcDaliImageFactoryReload06(void)
 
   ImageFactory& imageFactory  = Internal::ThreadLocalStorage::Get().GetImageFactory();
 
-  Vector2 testSize(80.0f, 80.0f);
-  application.GetPlatform().SetClosestImageSize(testSize);
+  Vector2 testSize(2048.0f, 2048.0f);
+    application.GetPlatform().SetClosestImageSize( testSize );
 
   // request with default attributes ( size is 0,0 )
   RequestPtr req = imageFactory.RegisterRequest( gTestImageFilename, NULL );
-  ResourceTicketPtr ticket = imageFactory.Load( req.Get() );
+  ResourceTicketPtr ticket = imageFactory.Load( *req.Get() );
 
   application.SendNotification();
   application.Render();
@@ -553,16 +591,16 @@ int UtcDaliImageFactoryReload06(void)
   application.Render();
 
   // emulate load success
-  EmulateImageLoaded( application, 80, 80 );
+  EmulateImageLoaded( application, testSize.x, testSize.y );
 
   // Request bigger size than actual image.
   // This will load the same resource.
   // However if image size changes later on to eg. 512*512 (file is overwritten),
   // reissuing these two requests will load different resources.
   ImageAttributes attr = ImageAttributes::New();
-  attr.SetSize( 92, 92 );
+  attr.SetSize( testSize.x + 1, testSize.y + 1 );
   RequestPtr req2 = imageFactory.RegisterRequest( gTestImageFilename, &attr );
-  ResourceTicketPtr ticket2 = imageFactory.Load( req2.Get() );
+  ResourceTicketPtr ticket2 = imageFactory.Load( *req2.Get() );
 
   DALI_TEST_CHECK( req != req2 ); // different requests
   DALI_TEST_EQUALS( ticket->GetId(), ticket2->GetId(), TEST_LOCATION ); // same resource
@@ -571,14 +609,14 @@ int UtcDaliImageFactoryReload06(void)
   application.GetPlatform().SetClosestImageSize(newSize);
 
   // reload fixed size (192,192) request
-  ticket2 = imageFactory.Reload( req2.Get() );
+  ticket2 = imageFactory.Reload( *req2.Get() );
 
   // emulate load success
   // note: this is the only way to emulate what size is loaded by platform abstraction
-  EmulateImageLoaded( application, 92, 92 );
+  EmulateImageLoaded( application, testSize.x + 1, testSize.y + 1 );
 
   // reload default size request
-  ticket = imageFactory.Reload( req.Get() );
+  ticket = imageFactory.Reload( *req.Get() );
 
   DALI_TEST_CHECK( ticket->GetId() != ticket2->GetId() ); // different resources
   END_TEST;