Revert "[Tizen] Move DevelHandle::GetCurrentProperty to public"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Shader.cpp
index 2a9c404..dacfd96 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
@@ -19,6 +19,7 @@
 
 #include <stdlib.h>
 #include <dali/public-api/dali-core.h>
+#include <dali/devel-api/object/handle-devel.h>
 #include <dali-test-suite-utils.h>
 #include <mesh-builder.h>
 
@@ -73,6 +74,27 @@ int UtcDaliShaderMethodNew02(void)
   END_TEST;
 }
 
+int UtcDaliShaderAssignmentOperator(void)
+{
+  TestApplication application;
+
+  Shader shader1 = Shader::New(VertexSource, FragmentSource);
+
+  Shader shader2;
+
+  DALI_TEST_CHECK(!(shader1 == shader2));
+
+  shader2 = shader1;
+
+  DALI_TEST_CHECK(shader1 == shader2);
+
+  shader2 = Shader::New(VertexSource, FragmentSource);;
+
+  DALI_TEST_CHECK(!(shader1 == shader2));
+
+  END_TEST;
+}
+
 int UtcDaliShaderDownCast01(void)
 {
   TestApplication application;
@@ -102,11 +124,8 @@ int UtcDaliShaderConstraint01(void)
   tet_infoline("Test that a non-uniform shader property can be constrained");
 
   Shader shader = Shader::New(VertexSource, FragmentSource);
-  Material material = Material::New( shader );
-  material.SetProperty(Material::Property::COLOR, Color::WHITE);
-
   Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, material );
+  Renderer renderer = Renderer::New( geometry, shader );
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
@@ -114,7 +133,7 @@ int UtcDaliShaderConstraint01(void)
   Stage::GetCurrent().Add(actor);
 
   Vector4 initialColor = Color::WHITE;
-  Property::Index colorIndex = shader.RegisterProperty( "fade-color", initialColor );
+  Property::Index colorIndex = shader.RegisterProperty( "uFadeColor", initialColor );
 
   application.SendNotification();
   application.Render(0);
@@ -127,15 +146,15 @@ int UtcDaliShaderConstraint01(void)
   application.Render(0);
 
   // Expect no blue component in either buffer - yellow
-  DALI_TEST_EQUALS( shader.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
+  DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::YELLOW, TEST_LOCATION );
   application.Render(0);
-  DALI_TEST_EQUALS( shader.GetProperty<Vector4>(colorIndex), Color::YELLOW, TEST_LOCATION );
+  DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::YELLOW, TEST_LOCATION );
 
   shader.RemoveConstraints();
   shader.SetProperty(colorIndex, Color::WHITE );
   application.SendNotification();
   application.Render(0);
-  DALI_TEST_EQUALS( shader.GetProperty<Vector4>(colorIndex), Color::WHITE, TEST_LOCATION );
+  DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::WHITE, TEST_LOCATION );
 
   END_TEST;
 }
@@ -147,11 +166,8 @@ int UtcDaliShaderConstraint02(void)
   tet_infoline("Test that a uniform map shader property can be constrained");
 
   Shader shader = Shader::New(VertexSource, FragmentSource);
-  Material material = Material::New( shader );
-  material.SetProperty(Material::Property::COLOR, Color::WHITE);
-
   Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, material );
+  Renderer renderer = Renderer::New( geometry, shader );
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
@@ -161,8 +177,7 @@ int UtcDaliShaderConstraint02(void)
   application.Render(0);
 
   Vector4 initialColor = Color::WHITE;
-  Property::Index colorIndex = shader.RegisterProperty( "fade-color", initialColor );
-  shader.AddUniformMapping( colorIndex, std::string("uFadeColor") );
+  Property::Index colorIndex = shader.RegisterProperty( "uFadeColor", initialColor );
 
   TestGlAbstraction& gl = application.GetGlAbstraction();
 
@@ -198,8 +213,6 @@ int UtcDaliShaderConstraint02(void)
   END_TEST;
 }
 
-
-
 int UtcDaliShaderAnimatedProperty01(void)
 {
   TestApplication application;
@@ -207,11 +220,8 @@ int UtcDaliShaderAnimatedProperty01(void)
   tet_infoline("Test that a non-uniform shader property can be animated");
 
   Shader shader = Shader::New(VertexSource, FragmentSource);
-  Material material = Material::New( shader );
-  material.SetProperty(Material::Property::COLOR, Color::WHITE);
-
   Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, material );
+  Renderer renderer = Renderer::New( geometry, shader );
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
@@ -219,7 +229,7 @@ int UtcDaliShaderAnimatedProperty01(void)
   Stage::GetCurrent().Add(actor);
 
   Vector4 initialColor = Color::WHITE;
-  Property::Index colorIndex = shader.RegisterProperty( "fade-color", initialColor );
+  Property::Index colorIndex = shader.RegisterProperty( "uFadeColor", initialColor );
 
   application.SendNotification();
   application.Render(0);
@@ -235,11 +245,11 @@ int UtcDaliShaderAnimatedProperty01(void)
   application.SendNotification();
   application.Render(500);
 
-  DALI_TEST_EQUALS( shader.GetProperty<Vector4>(colorIndex), Color::WHITE * 0.5f, TEST_LOCATION );
+  DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
 
   application.Render(500);
 
-  DALI_TEST_EQUALS( shader.GetProperty<Vector4>(colorIndex), Color::TRANSPARENT, TEST_LOCATION );
+  DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
 
   END_TEST;
 }
@@ -251,11 +261,8 @@ int UtcDaliShaderAnimatedProperty02(void)
   tet_infoline("Test that a uniform map shader property can be animated");
 
   Shader shader = Shader::New(VertexSource, FragmentSource);
-  Material material = Material::New( shader );
-  material.SetProperty(Material::Property::COLOR, Color::WHITE);
-
   Geometry geometry = CreateQuadGeometry();
-  Renderer renderer = Renderer::New( geometry, material );
+  Renderer renderer = Renderer::New( geometry, shader );
 
   Actor actor = Actor::New();
   actor.AddRenderer(renderer);
@@ -265,8 +272,7 @@ int UtcDaliShaderAnimatedProperty02(void)
   application.Render(0);
 
   Vector4 initialColor = Color::WHITE;
-  Property::Index colorIndex = shader.RegisterProperty( "fade-color", initialColor );
-  shader.AddUniformMapping( colorIndex, std::string("uFadeColor") );
+  Property::Index colorIndex = shader.RegisterProperty( "uFadeColor", initialColor );
 
   TestGlAbstraction& gl = application.GetGlAbstraction();
 
@@ -296,3 +302,76 @@ int UtcDaliShaderAnimatedProperty02(void)
 
   END_TEST;
 }
+
+int UtcDaliShaderProgramProperty(void)
+{
+  TestApplication application;
+
+  tet_infoline("Test get/set progam property");
+
+  Shader shader = Shader::New("", "");
+  std::string hintSet = "MODIFIES_GEOMETRY";
+
+  Property::Map map;
+  map["vertex"] = VertexSource;
+  map["fragment"] = FragmentSource;
+  map["hints"] = hintSet;
+
+  shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+
+  Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
+  DALI_TEST_CHECK( value.GetType() == Property::MAP);
+  const Property::Map* outMap = value.GetMap();
+
+  std::string v = (*outMap)["vertex"].Get<std::string>();
+  std::string f = (*outMap)["fragment"].Get<std::string>();
+  std::string h = (*outMap)["hints"].Get<std::string>();
+
+  DALI_TEST_CHECK( v == VertexSource );
+  DALI_TEST_CHECK( f == FragmentSource );
+  DALI_TEST_CHECK( h == hintSet );
+
+  value = DevelHandle::GetCurrentProperty( shader, Shader::Property::PROGRAM );
+  DALI_TEST_CHECK( value.GetType() == Property::MAP);
+  outMap = value.GetMap();
+
+  v = (*outMap)["vertex"].Get<std::string>();
+  f = (*outMap)["fragment"].Get<std::string>();
+  h = (*outMap)["hints"].Get<std::string>();
+
+  DALI_TEST_CHECK( v == VertexSource );
+  DALI_TEST_CHECK( f == FragmentSource );
+  DALI_TEST_CHECK( h == hintSet );
+
+  std::string hintGot;
+
+  hintSet = "OUTPUT_IS_TRANSPARENT,MODIFIES_GEOMETRY";
+  map["hints"] = hintSet;
+  shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+  value = shader.GetProperty(Shader::Property::PROGRAM);
+  hintGot = (*value.GetMap())["hints"].Get<std::string>();
+  DALI_TEST_CHECK( hintGot == hintSet );
+
+  hintSet = "OUTPUT_IS_TRANSPARENT";
+  map["hints"] = hintSet;
+  shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+  value = shader.GetProperty(Shader::Property::PROGRAM);
+  hintGot = (*value.GetMap())["hints"].Get<std::string>();
+  DALI_TEST_CHECK( hintGot == hintSet );
+
+  hintSet = "NONE";
+  map["hints"] = hintSet;
+  shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+  value = shader.GetProperty(Shader::Property::PROGRAM);
+  hintGot = (*value.GetMap())["hints"].Get<std::string>();
+  DALI_TEST_CHECK( hintGot == hintSet );
+
+  hintSet = "";
+  map["hints"] = hintSet;
+  shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+  value = shader.GetProperty(Shader::Property::PROGRAM);
+  hintGot = (*value.GetMap())["hints"].Get<std::string>();
+  DALI_TEST_CHECK( hintGot == "NONE" );
+
+  END_TEST;
+}