Example #1
0
int UtcDaliPropertyArrayResize(void)
{
  Property::Array array;

  array.Resize(3);
  DALI_TEST_CHECK( array.Count() == 3 );

  array.Resize(5);
  DALI_TEST_CHECK( array.Count() == 5 );

  END_TEST;
}
Example #2
0
int UtcDaliPropertyArrayCountP(void)
{
  Property::Array array;
  DALI_TEST_CHECK( 0 == array.Capacity() );
  DALI_TEST_CHECK( 0 == array.Count() );

  array.Reserve(3);

  DALI_TEST_CHECK( 3 == array.Capacity() );
  DALI_TEST_CHECK( 0 == array.Count() );

  array.PushBack( 1 );
  array.PushBack( "world" );
  array.PushBack( 3 );

  DALI_TEST_CHECK( 3 == array.Count() );

  END_TEST;
}
int UtcDaliControlRendererGetPropertyMap4(void)
{
  ToolkitTestApplication application;
  tet_infoline( "UtcDaliControlRendererGetPropertyMap4: radial GradientRenderer" );

  RendererFactory factory = RendererFactory::Get();
  DALI_TEST_CHECK( factory );

  Property::Map propertyMap;
  propertyMap.Insert("renderer-type", "gradient-renderer");

  Vector2 center(100.f, 100.f);
  float radius = 100.f;
  propertyMap.Insert("gradient-units", "user-space");
  propertyMap.Insert("gradient-center", center);
  propertyMap.Insert("gradient-radius", radius);
  propertyMap.Insert("gradient-stop-offset", Vector3(0.1f, 0.3f, 1.1f));

  Property::Array stopColors;
  stopColors.PushBack( Color::RED );
  stopColors.PushBack( Color::BLACK );
  stopColors.PushBack( Color::GREEN );
  propertyMap.Insert("gradient-stop-color", stopColors);

  ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap);
  DALI_TEST_CHECK( gradientRenderer );

  Property::Map resultMap;
  gradientRenderer.CreatePropertyMap( resultMap );

  // check the property values from the returned map from control renderer
  Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "gradient-renderer" );

  value = resultMap.Find( "gradient-units", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "user-space" );

  value = resultMap.Find( "gradient-spread-method", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "pad" );

  value = resultMap.Find( "gradient-center", Property::VECTOR2 );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<Vector2>(), center , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-radius", Property::FLOAT );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<float>(), radius , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-offset", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* offsetArray = value->GetArray();
  DALI_TEST_CHECK( offsetArray->Count() == 3 );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.1f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.3f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  // any stop value will be clamped to [0.0, 1.0];
  DALI_TEST_EQUALS( offsetArray->GetElementAt(2).Get<float>(), 1.0f , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-color", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* colorArray = value->GetArray();
  DALI_TEST_CHECK( colorArray->Count() == 3 );
  DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::BLACK , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( colorArray->GetElementAt(2).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  END_TEST;
}
int UtcDaliControlRendererGetPropertyMap3(void)
{
  ToolkitTestApplication application;
  tet_infoline( "UtcDaliControlRendererGetPropertyMap3: linear GradientRenderer" );

  RendererFactory factory = RendererFactory::Get();
  DALI_TEST_CHECK( factory );

  Property::Map propertyMap;
  propertyMap.Insert("renderer-type", "gradient-renderer");

  Vector2 start(-1.f, -1.f);
  Vector2 end(1.f, 1.f);
  propertyMap.Insert("gradient-start-position", start);
  propertyMap.Insert("gradient-end-position", end);
  propertyMap.Insert("gradient-spread-method", "repeat");

  propertyMap.Insert("gradient-stop-offset", Vector2(0.2f, 0.8f));

  Property::Array stopColors;
  stopColors.PushBack( Color::RED );
  stopColors.PushBack( Color::GREEN );
  propertyMap.Insert("gradient-stop-color", stopColors);

  ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap);

  Property::Map resultMap;
  gradientRenderer.CreatePropertyMap( resultMap );

  // check the property values from the returned map from control renderer
  Property::Value* value = resultMap.Find( "renderer-type", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "gradient-renderer" );

  value = resultMap.Find( "gradient-units", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "object-bounding-box" );

  value = resultMap.Find( "gradient-spread-method", Property::STRING );
  DALI_TEST_CHECK( value );
  DALI_TEST_CHECK( value->Get<std::string>() == "repeat" );

  value = resultMap.Find( "gradient-start-position", Property::VECTOR2 );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<Vector2>(), start , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-end-position", Property::VECTOR2 );
  DALI_TEST_CHECK( value );
  DALI_TEST_EQUALS( value->Get<Vector2>(), end , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-offset", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* offsetArray = value->GetArray();
  DALI_TEST_CHECK( offsetArray->Count() == 2 );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(0).Get<float>(), 0.2f , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( offsetArray->GetElementAt(1).Get<float>(), 0.8f , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  value = resultMap.Find( "gradient-stop-color", Property::ARRAY );
  DALI_TEST_CHECK( value );
  Property::Array* colorArray = value->GetArray();
  DALI_TEST_CHECK( colorArray->Count() == 2 );
  DALI_TEST_EQUALS( colorArray->GetElementAt(0).Get<Vector4>(), Color::RED , Math::MACHINE_EPSILON_100, TEST_LOCATION );
  DALI_TEST_EQUALS( colorArray->GetElementAt(1).Get<Vector4>(), Color::GREEN , Math::MACHINE_EPSILON_100, TEST_LOCATION );

  END_TEST;
}
Example #5
0
bool SetPropertyFromNode( const TreeNode& node, Property::Type type, Property::Value& value,
                          const Replacement& replacer )
{
  bool done = false;

  switch(type)
  {
    case Property::BOOLEAN:
    {
      if( OptionalBoolean v = replacer.IsBoolean(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::FLOAT:
    {
      if( OptionalFloat v = replacer.IsFloat(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::INTEGER:
    {
      if( OptionalInteger v = replacer.IsInteger(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::VECTOR2:
    {
      if( OptionalVector2 v = replacer.IsVector2(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::VECTOR3:
    {
      if( OptionalVector3 v = replacer.IsVector3(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::VECTOR4:
    {
      if( OptionalVector4 v = replacer.IsVector4(node) )
      {
        value = *v;
        done = true;
      }
      else if( OptionalString s = replacer.IsString(node) )
      {
        if( (*s)[0] == '#' && 7 == (*s).size() )
        {
          value = HexStringToVector4( &(*s)[1] );
          done = true;
        }
        else if( Dali::ColorController::Get() )
        {
          Vector4 color;
          done = Dali::ColorController::Get().RetrieveColor( *s, color );
          value = color;
        }
      }
      else if( TreeNode::OBJECT == node.GetType() )
      {
        // check for "r", "g" and "b" child color component nodes
        OptionalInteger r = replacer.IsInteger( IsChild(node, "r") );
        OptionalInteger g = replacer.IsInteger( IsChild(node, "g") );
        OptionalInteger b = replacer.IsInteger( IsChild(node, "b") );
        if( r && g && b )
        {
          float red( (*r) * (1.0f/255.0f) );
          float green( (*g) * (1.0f/255.0f) );
          float blue( (*b) * (1.0f/255.0f) );
          // check for optional "a" (alpha) node, default to fully opaque if it is not found.
          float alpha( 1.0f );
          OptionalInteger a = replacer.IsInteger( IsChild(node, "a") );
          if( a )
          {
            alpha = (*a) * (1.0f/255.0f);
          }
          value = Vector4( red, green, blue, alpha );
          done = true;
        }
      }
      break;
    }
    case Property::MATRIX3:
    {
      if( OptionalMatrix3 v = replacer.IsMatrix3(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::MATRIX:
    {
      if( OptionalMatrix v = replacer.IsMatrix(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::RECTANGLE:
    {
      if( OptionalRect v = replacer.IsRect(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::ROTATION:
    {
      if(4 == node.Size())
      {
        if( OptionalVector4 ov = replacer.IsVector4(node) )
        {
          const Vector4& v = *ov;
          // angle, axis as per spec
          value = Quaternion(Radian(Degree(v[3])),
                             Vector3(v[0],v[1],v[2]));
          done = true;
        }
      }
      else
      {
        // degrees Euler as per spec
        if( OptionalVector3 v = replacer.IsVector3(node) )
        {
          value = Quaternion(Radian(Degree((*v).x)),
                             Radian(Degree((*v).y)),
                             Radian(Degree((*v).z)));
          done = true;
        }
      }
      break;
    }
    case Property::STRING:
    {
      if( OptionalString v = replacer.IsString(node) )
      {
        value = *v;
        done = true;
      }
      break;
    }
    case Property::ARRAY:
    {
      if( replacer.IsArray( node, value ) )
      {
        done = true;
      }
      else if(node.Size())
      {
        value = Property::Value(Property::ARRAY);
        Property::Array* array = value.GetArray();

        unsigned int i = 0;
        TreeNode::ConstIterator iter(node.CBegin());

        if( array )
        {
          for( ; i < node.Size(); ++i, ++iter)
          {
            Property::Value childValue;
            if( SetPropertyFromNode( (*iter).second, childValue, replacer ) )
            {
              array->PushBack( childValue );
            }
          }

          if( array->Count() == node.Size() )
          {
            done = true;
          }
          else
          {
            done = false;
          }
        }
      }
      break;
    }
    case Property::MAP:
    {
      if( replacer.IsMap( node, value ) )
      {
        done = true;
      }
      else if(node.Size())
      {
        value = Property::Value(Property::MAP);
        Property::Map* map = value.GetMap();

        unsigned int i = 0;
        TreeNode::ConstIterator iter(node.CBegin());

        if( map )
        {
          for( ; i < node.Size(); ++i, ++iter)
          {
            Property::Value childValue;
            if( SetPropertyFromNode( (*iter).second, childValue, replacer ) )
            {
              map->Insert( (*iter).first, childValue );
            }
          }

          if( map->Count() == node.Size() )
          {
            done = true;
          }
          else
          {
            done = false;
          }
        }
      }
      break;
    }
    case Property::NONE:
    {
      break;
    }
  } // switch type

  return done;
}