Merge "Revert the TextLabel to use the old renderer." into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Visual.cpp
index 23311e2..7cda6e5 100644 (file)
@@ -41,8 +41,37 @@ const char* TEST_MTL_FILE_NAME = TEST_RESOURCE_DIR "/ToyRobot-Metal.mtl";
 const char* TEST_RESOURCE_LOCATION = TEST_RESOURCE_DIR "/";
 
 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
+
+bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
+{
+  if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
+  {
+    for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
+    {
+      const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
+
+      Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
+      if( NULL != valueSet )
+      {
+        if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
+        {
+          tet_printf( "  Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
+          return false;
+        }
+      }
+      else
+      {
+        tet_printf( "  The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
+        return false;
+      }
+    }
+  }
+
+  return true;
 }
 
+} //namespace
+
 void dali_visual_startup(void)
 {
   test_return_value = TET_UNDEF;
@@ -162,16 +191,7 @@ int UtcDaliVisualSize(void)
   imageVisual.GetNaturalSize(naturalSize);
   DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 200.f), TEST_LOCATION );
 
-  // n patch visual
-  TestPlatformAbstraction& platform = application.GetPlatform();
-  Vector2 testSize(80.f, 160.f);
-  platform.SetClosestImageSize(testSize);
-  image = ResourceImage::New(TEST_NPATCH_FILE_NAME);
-  Visual::Base nPatchVisual = factory.CreateVisual( image );
-  nPatchVisual.SetSize( visualSize );
-  DALI_TEST_EQUALS( nPatchVisual.GetSize(), visualSize, TEST_LOCATION );
-  nPatchVisual.GetNaturalSize(naturalSize);
-  DALI_TEST_EQUALS( naturalSize, testSize, TEST_LOCATION );
+  // n patch visual is tested in the utc-Dali-VisualFactory.cpp
 
   // border visual
   float borderSize = 5.f;
@@ -221,6 +241,9 @@ int UtcDaliVisualSize(void)
   DALI_TEST_EQUALS( naturalSize, Vector2(100.f, 100.f), TEST_LOCATION ); // Natural size should still be 100, 100
 
   // Batch Image visual
+  TestPlatformAbstraction& platform = application.GetPlatform();
+  Vector2 testSize(80.f, 160.f);
+  platform.SetClosestImageSize(testSize);
   propertyMap.Clear();
   propertyMap.Insert( Visual::Property::TYPE, Visual::IMAGE );
   propertyMap.Insert( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
@@ -678,10 +701,6 @@ int UtcDaliVisualGetPropertyMap5(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_CHECK( value->Get<bool>() == false );
 
-  // Test the properties. TODO: to be completed.
-  imageVisual.SetProperty( ImageVisual::Property::URL, TEST_IMAGE_FILE_NAME );
-  Property::Value imageValue = imageVisual.GetProperty( ImageVisual::Property::URL );
-
   END_TEST;
 }
 
@@ -713,9 +732,6 @@ int UtcDaliVisualGetPropertyMap6(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_CHECK( value->Get<bool>() );
 
-  // Test the properties. TODO: to be completed.
-  nPatchVisual.SetProperty( ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME );
-  Property::Value nPatchValue = nPatchVisual.GetProperty( ImageVisual::Property::URL );
 
   END_TEST;
 }
@@ -963,7 +979,11 @@ int UtcDaliVisualGetPropertyMap10(void)
   propertyMap.Insert( "renderingBackend", static_cast<int>( Toolkit::Text::DEFAULT_RENDERING_BACKEND ) );
   propertyMap.Insert( "text", "Hello world" );
   propertyMap.Insert( "fontFamily", "TizenSans" );
-  propertyMap.Insert( "fontStyle", "{\"weight\":\"bold\"}" );
+
+  Property::Map fontStyleMapSet;
+  fontStyleMapSet.Insert( "weight", "bold" );
+  propertyMap.Insert( "fontStyle", fontStyleMapSet );
+
   propertyMap.Insert( "pointSize", 12.f );
   propertyMap.Insert( "multiLine", true );
   propertyMap.Insert( "horizontalAlignment", "CENTER" );
@@ -995,9 +1015,12 @@ int UtcDaliVisualGetPropertyMap10(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<std::string>(), "TizenSans", TEST_LOCATION );
 
-  value = resultMap.Find( TextVisual::Property::FONT_STYLE, Property::STRING );
+  value = resultMap.Find( TextVisual::Property::FONT_STYLE, Property::MAP );
   DALI_TEST_CHECK( value );
-  DALI_TEST_EQUALS( value->Get<std::string>(), "{\"weight\":\"bold\"}", TEST_LOCATION );
+
+  Property::Map fontStyleMapGet = value->Get<Property::Map>();
+  DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
+  DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
 
   value = resultMap.Find( TextVisual::Property::POINT_SIZE, Property::FLOAT );
   DALI_TEST_CHECK( value );
@@ -1024,8 +1047,7 @@ int UtcDaliVisualGetPropertyMap10(void)
   DALI_TEST_CHECK( !value->Get<bool>() );
 
   value = resultMap.Find( TextVisual::Property::ENABLE_AUTO_SCROLL, Property::BOOLEAN );
-  DALI_TEST_CHECK( value );
-  DALI_TEST_CHECK( !value->Get<bool>() );
+  DALI_TEST_CHECK( !value );
 
   value = resultMap.Find( TextVisual::Property::LINE_SPACING, Property::FLOAT );
   DALI_TEST_CHECK( value );
@@ -1560,4 +1582,37 @@ int UtcDaliVisualSetTransform7(void)
   END_TEST;
 }
 
+int UtcDaliNPatchVisualCustomShader(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "NPatchVisual with custom shader" );
+
+  VisualFactory factory = VisualFactory::Get();
+  Property::Map properties;
+  Property::Map shader;
+  const std::string fragmentShader = "Foobar";
+  shader[Dali::Toolkit::Visual::Shader::Property::FRAGMENT_SHADER] = fragmentShader;
+  properties[Dali::Toolkit::Visual::Property::TYPE] = Dali::Toolkit::Visual::IMAGE;
+  properties[Dali::Toolkit::Visual::Property::SHADER]=shader;
+  properties[Dali::Toolkit::ImageVisual::Property::URL] = TEST_NPATCH_FILE_NAME;
+
+  Visual::Base visual = factory.CreateVisual( properties );
+  Actor dummy = Actor::New();
+  // trigger creation through setting on stage
+  visual.SetOnStage( dummy );
+
+  Renderer renderer = dummy.GetRendererAt( 0 );
+  Shader shader2 = renderer.GetShader();
+  Property::Value value = shader2.GetProperty( Shader::Property::PROGRAM );
+  Property::Map* map = value.GetMap();
+  DALI_TEST_CHECK( map );
+
+  Property::Value* fragment = map->Find( "fragment" ); // fragment key name from shader-impl.cpp
+  // *map["vertex"]; is default here so not verifying it
+
+  DALI_TEST_EQUALS( fragmentShader, fragment->Get<std::string>(), TEST_LOCATION );
+
+  END_TEST;
+}
+