Merge "Update gbs build makefile for node addon" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ImageView.cpp
index e40862c..cc62d54 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali/devel-api/scripting/scripting.h>
+#include <dali/devel-api/rendering/material.h>
+#include <dali/devel-api/rendering/renderer.h>
 
 using namespace Dali;
 using namespace Toolkit;
@@ -53,11 +55,11 @@ void TestImage( ImageView imageView, BufferImage image )
 
   int width = 0;
   DALI_TEST_CHECK( map[ "width" ].Get( width ) );
-  DALI_TEST_EQUALS( width, image.GetWidth(), TEST_LOCATION );
+  DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
 
   int height = 0;
   DALI_TEST_CHECK( map[ "height" ].Get( height ) );
-  DALI_TEST_EQUALS( height, image.GetHeight(), TEST_LOCATION );
+  DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
 
   std::string type;
   DALI_TEST_CHECK( map[ "type" ].Get( type ) );
@@ -75,14 +77,14 @@ void TestImage( ImageView imageView, ResourceImage image )
   {
     int width = 0;
     DALI_TEST_CHECK( map[ "width" ].Get( width ) );
-    DALI_TEST_EQUALS( width, image.GetWidth(), TEST_LOCATION );
+    DALI_TEST_EQUALS( (unsigned int)width, image.GetWidth(), TEST_LOCATION );
   }
 
   if( map.Find( "height" ) )
   {
     int height = 0;
     DALI_TEST_CHECK( map[ "height" ].Get( height ) );
-    DALI_TEST_EQUALS( height, image.GetHeight(), TEST_LOCATION );
+    DALI_TEST_EQUALS( (unsigned int)height, image.GetHeight(), TEST_LOCATION );
   }
 
   DALI_TEST_CHECK( map.Find( "type" ) );
@@ -238,7 +240,7 @@ int UtcDaliImageViewSetGetProperty01(void)
   ImageView imageView = ImageView::New();
 
   Property::Index idx = imageView.GetPropertyIndex( "image" );
-  DALI_TEST_EQUALS( idx, ImageView::Property::IMAGE, TEST_LOCATION );
+  DALI_TEST_EQUALS( idx, (Property::Index)ImageView::Property::IMAGE, TEST_LOCATION );
 
   imageView.SetProperty( idx, TEST_IMAGE_FILE_NAME );
   TestUrl( imageView, TEST_IMAGE_FILE_NAME );
@@ -246,6 +248,90 @@ int UtcDaliImageViewSetGetProperty01(void)
   END_TEST;
 }
 
+int UtcDaliImageViewSetGetProperty02(void)
+{
+  ToolkitTestApplication application;
+
+  Image image = CreateBufferImage( 10, 10, Color::WHITE );
+  ImageView imageView = ImageView::New(image);
+  Vector4 fullImageRect( 0.f, 0.f, 1.f, 1.f );
+
+  Stage::GetCurrent().Add( imageView );
+
+  application.SendNotification();
+  application.Render();
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  Vector4 pixelAreaUniform;
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
+  DALI_TEST_EQUALS( pixelAreaUniform, fullImageRect, TEST_LOCATION );
+
+  Property::Value value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
+  Vector4 pixelAreaValue;
+  DALI_TEST_CHECK( value.Get(pixelAreaValue) );
+  DALI_TEST_EQUALS( pixelAreaValue, fullImageRect, TEST_LOCATION );
+
+  Vector4 pixelAreaSet( 0.2f, 0.2f, 0.3f, 0.3f );
+  imageView.SetProperty( ImageView::Property::PIXEL_AREA, pixelAreaSet);
+
+  application.SendNotification();
+  application.Render();
+
+  value = imageView.GetProperty( ImageView::Property::PIXEL_AREA );
+  value.Get(pixelAreaValue);
+  DALI_TEST_EQUALS( pixelAreaValue, pixelAreaSet, TEST_LOCATION );
+
+  DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "pixelArea", pixelAreaUniform ) );
+  DALI_TEST_EQUALS( pixelAreaUniform, pixelAreaSet, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliImageViewSetGetProperty03(void)
+{
+  ToolkitTestApplication application;
+
+  Image image = CreateBufferImage( 10, 10, Color::WHITE );
+  ImageView imageView = ImageView::New(image);
+  Stage::GetCurrent().Add( imageView );
+  application.SendNotification();
+  application.Render();
+
+ // conventional alpha blending
+  Material material = imageView.GetRendererAt( 0 ).GetMaterial();
+  BlendingFactor::Type srcFactorRgb;
+  BlendingFactor::Type destFactorRgb;
+  BlendingFactor::Type srcFactorAlpha;
+  BlendingFactor::Type destFactorAlpha;
+  material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha);
+  DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::SRC_ALPHA );
+  DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
+  DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
+  DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE_MINUS_SRC_ALPHA );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+
+  float alphaBlendingUniform;
+  DALI_TEST_CHECK( gl.GetUniformValue<float>( "uAlphaBlending", alphaBlendingUniform ) );
+  DALI_TEST_EQUALS( alphaBlendingUniform, 1.f, TEST_LOCATION );
+
+  // pre-multiplied alpha blending
+  imageView.SetProperty( Toolkit::ImageView::Property::PRE_MULTIPLIED_ALPHA, true );
+  application.SendNotification();
+  application.Render();
+
+  material.GetBlendFunc(srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha);
+  DALI_TEST_CHECK( srcFactorRgb == BlendingFactor::ONE );
+  DALI_TEST_CHECK( destFactorRgb == BlendingFactor::ONE_MINUS_SRC_ALPHA );
+  DALI_TEST_CHECK( srcFactorAlpha == BlendingFactor::ONE );
+  DALI_TEST_CHECK( destFactorAlpha == BlendingFactor::ONE );
+
+  DALI_TEST_CHECK( gl.GetUniformValue<float>( "uAlphaBlending", alphaBlendingUniform ) );
+  DALI_TEST_EQUALS( alphaBlendingUniform, 0.f, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliImageViewSizeWithBackground(void)
 {
   ToolkitTestApplication application;
@@ -260,8 +346,8 @@ int UtcDaliImageViewSizeWithBackground(void)
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_EQUALS( imageView.GetCurrentSize().width, width, TEST_LOCATION );
-  DALI_TEST_EQUALS( imageView.GetCurrentSize().height, height, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
 
   END_TEST;
 }
@@ -285,8 +371,8 @@ int UtcDaliImageViewSizeWithBackgroundAndImage(void)
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_EQUALS( imageView.GetCurrentSize().width, width, TEST_LOCATION );
-  DALI_TEST_EQUALS( imageView.GetCurrentSize().height, height, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageView.GetCurrentSize().width, (float)width, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageView.GetCurrentSize().height, (float)height, TEST_LOCATION );
 
   END_TEST;
 }
@@ -333,8 +419,8 @@ int UtcDaliImageViewHeightForWidthBackgroundAndImage(void)
   application.SendNotification();
   application.Render();
 
-  DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), height, TEST_LOCATION );
-  DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), width, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageView.GetHeightForWidth( width ), (float)height, TEST_LOCATION );
+  DALI_TEST_EQUALS( imageView.GetWidthForHeight( height ), (float)width, TEST_LOCATION );
 
   END_TEST;
 }
@@ -505,3 +591,62 @@ int UtcDaliImageViewSetImageN(void)
 
   END_TEST;
 }
+
+int UtcDaliImageViewSetImageTypeChangesP(void)
+{
+  ToolkitTestApplication application;
+
+  ImageView imageView = ImageView::New();
+
+
+  std::string url;
+  Property::Map map;
+
+  Property::Value value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+
+  // Set a URL
+  imageView.SetImage( "TEST_URL" );
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+
+  DALI_TEST_CHECK( value.Get( url ) );   // Value should NOT be empty
+  DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+
+  // Set an empty Image
+  imageView.SetImage( Image() );
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+
+  // Set an Image
+  ResourceImage image1 = ResourceImage::New( TEST_IMAGE_FILE_NAME );
+  imageView.SetImage( image1 );
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( value.Get( map ) );   // Value should NOT be empty
+
+  // Set an empty URL
+  imageView.SetImage( "" );
+  value = imageView.GetProperty( imageView.GetPropertyIndex( "image" ) );
+
+  DALI_TEST_CHECK( ! value.Get( url ) ); // Value should be empty
+  DALI_TEST_CHECK( ! value.Get( map ) ); // Value should be empty
+
+  END_TEST;
+}
+
+int UtcDaliImageViewResourceUrlP(void)
+{
+  ToolkitTestApplication application;
+
+  ImageView imageView = ImageView::New();
+  DALI_TEST_CHECK( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >().empty() );
+
+  imageView.SetProperty( ImageView::Property::RESOURCE_URL, "TestString" );
+  DALI_TEST_EQUALS( imageView.GetProperty( ImageView::Property::RESOURCE_URL ).Get< std::string >(), "TestString", TEST_LOCATION );
+
+  END_TEST;
+}