Merge "Fixed test cases after changes in ResourceImage" into devel/master
authorPaul Wisbey <p.wisbey@samsung.com>
Fri, 20 Jan 2017 09:19:25 +0000 (01:19 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 20 Jan 2017 09:19:26 +0000 (01:19 -0800)
automated-tests/src/dali-toolkit/utc-Dali-Button.cpp
dali-toolkit/internal/controls/buttons/button-impl.cpp
dali-toolkit/internal/controls/buttons/radio-button-impl.cpp
dali-toolkit/internal/image-loader/atlas-packer.cpp
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.h
dali-toolkit/public-api/controls/buttons/check-box-button.h
dali-toolkit/public-api/controls/buttons/push-button.h
dali-toolkit/public-api/controls/buttons/radio-button.cpp
dali-toolkit/public-api/controls/buttons/radio-button.h

index 9452649..244f667 100644 (file)
@@ -504,6 +504,47 @@ int UtcDaliButtonSetLabelStringWithPropertyMapP(void)
   END_TEST;
 }
 
+int UtcDaliButtonSetLabelStringWithPropertyMapStringsP(void)
+{
+  ToolkitTestApplication application;
+
+  Button button = PushButton::New();
+
+  tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Setting Button text using String then replacing with Enum then string");
+
+  Property::Map textVisualMapInitial;
+  textVisualMapInitial["visualType"] = "TEXT";
+  textVisualMapInitial["pointSize"] =  15.0f;
+  textVisualMapInitial["text"] = "button label initial";
+
+  button.SetProperty( Button::Property::LABEL, textVisualMapInitial );
+
+  DALI_TEST_EQUALS( GetButtonText( button ), "button label initial", TEST_LOCATION );
+
+  tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Intermediate part of test");
+
+  Property::Map propertyMap;
+  propertyMap.Insert( Toolkit::Visual::Property::TYPE,  Toolkit::DevelVisual::TEXT );
+  propertyMap.Insert( Toolkit::TextVisual::Property::TEXT,  "error if this is the final text" );
+  propertyMap.Insert( Toolkit::TextVisual::Property::POINT_SIZE, 15.0f );
+
+  button.SetProperty( Button::Property::LABEL, propertyMap );
+
+  DALI_TEST_EQUALS( GetButtonText( button ), "error if this is the final text", TEST_LOCATION );
+
+  tet_infoline(" UtcDaliButtonSetLabelStringWithPropertyMapStringsP Final part of test");
+
+  Property::Map textVisualMap;
+  textVisualMap["visualType"] = "TEXT";
+  textVisualMap["pointSize"] =  15.0f;
+  textVisualMap["text"] = "Button Label";
+
+  button.SetProperty( Toolkit::Button::Property::LABEL, textVisualMap );
+
+  DALI_TEST_EQUALS( GetButtonText( button ), "Button Label", TEST_LOCATION );
+  END_TEST;
+}
+
 int UtcDaliButtonSetLabelWithStringP(void)
 {
   ToolkitTestApplication application;
index ed9b2c8..a8ab543 100644 (file)
@@ -39,6 +39,7 @@
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/internal/visuals/text/text-visual.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 
@@ -1228,7 +1229,7 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope
           DALI_LOG_INFO( gLogButtonFilter, Debug::Verbose, "Button::SetProperty Setting TextVisual with string[%s]\n", textString.c_str() );
 
           Property::Map setPropertyMap;
-          setPropertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT)
+          setPropertyMap.Add( Toolkit::Visual::Property::TYPE, Toolkit::DevelVisual::TEXT )
                         .Add( Toolkit::TextVisual::Property::TEXT, textString );
 
           GetImplementation( button ).MergeWithExistingLabelProperties( setPropertyMap, outTextVisualProperties );
@@ -1239,6 +1240,7 @@ void Button::SetProperty( BaseObject* object, Property::Index index, const Prope
           Property::Map* setPropertyMap = value.GetMap();
           if( setPropertyMap )
           {
+            TextVisual::ConvertStringKeysToIndexKeys( *setPropertyMap );
             GetImplementation( button ).MergeWithExistingLabelProperties( *setPropertyMap, outTextVisualProperties );
           }
         }
index 79ff320..e54ad82 100644 (file)
@@ -105,7 +105,7 @@ void RadioButton::OnStateChange( State newState )
         Dali::Toolkit::RadioButton radioButtonChild = Dali::Toolkit::RadioButton::DownCast( parent.GetChildAt( i ) );
         if( radioButtonChild && radioButtonChild != Self() )
         {
-          radioButtonChild.SetSelected( false );
+          radioButtonChild.SetProperty( Toolkit::Button::Property::SELECTED, false );
         }
       }
     }
index e02eba6..26ad3e0 100644 (file)
@@ -258,12 +258,11 @@ void AtlasPacker::GrowPack( SizeType blockWidth, SizeType blockHeight,
     firstFit = InsertNode( mRoot->child[1], blockWidth, blockHeight );
   }
 
-  if( firstFit != NULL )
-  {
-    firstFit->occupied = true;
-    packPositionX = firstFit->rectArea.x;
-    packPositionY = firstFit->rectArea.y;
-  }
+  DALI_ASSERT_ALWAYS( firstFit != NULL && "It should never happen!")
+
+  firstFit->occupied = true;
+  packPositionX = firstFit->rectArea.x;
+  packPositionY = firstFit->rectArea.y;
 }
 
 void AtlasPacker::GrowNode( SizeType blockWidth, SizeType blockHeight )
index 6977eb5..f3b895b 100644 (file)
@@ -137,6 +137,60 @@ const char* FRAGMENT_SHADER_ATLAS_CLAMP = DALI_COMPOSE_SHADER(
     }\n
 );
 
+/**
+ * Return Property index for the given string key
+ * param[in] stringKey the string index key
+ * return the key as an index
+ */
+
+Dali::Property::Index StringKeyToIndexKey( const std::string& stringKey )
+{
+  Dali::Property::Index result = Property::INVALID_KEY;
+
+  if( stringKey == VISUAL_TYPE )
+  {
+    result = Toolkit::Visual::Property::TYPE;
+  }
+  else if( stringKey == TEXT_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::TEXT;
+  }
+  else if( stringKey == FONT_FAMILY_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::FONT_FAMILY;
+  }
+  else if( stringKey == FONT_STYLE_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::FONT_STYLE;
+  }
+  else if( stringKey == POINT_SIZE_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::POINT_SIZE;
+  }
+  else if( stringKey == MULTI_LINE_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::MULTI_LINE;
+  }
+  else if( stringKey == HORIZONTAL_ALIGNMENT_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT;
+  }
+  else if( stringKey == VERTICAL_ALIGNMENT_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT;
+  }
+  else if( stringKey == TEXT_COLOR_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::TEXT_COLOR;
+  }
+  else if( stringKey == ENABLE_MARKUP_PROPERTY )
+  {
+    result = Toolkit::TextVisual::Property::ENABLE_MARKUP;
+  }
+
+  return result;
+}
+
 } // unnamed namespace
 
 TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache, const Property::Map& properties )
@@ -146,6 +200,27 @@ TextVisualPtr TextVisual::New( VisualFactoryCache& factoryCache, const Property:
   return TextVisualPtr;
 }
 
+void TextVisual::ConvertStringKeysToIndexKeys( Property::Map& propertyMap )
+{
+  Property::Map outMap;
+
+  for( Property::Map::SizeType index = 0u, count = propertyMap.Count(); index < count; ++index )
+  {
+    const KeyValuePair& keyValue = propertyMap.GetKeyValue( index );
+
+    Property::Index indexKey = keyValue.first.indexKey;
+
+    if ( keyValue.first.type == Property::Key::STRING )
+    {
+      indexKey = StringKeyToIndexKey( keyValue.first.stringKey );
+    }
+
+    outMap.Insert( indexKey, keyValue.second );
+  }
+
+  propertyMap = outMap;
+}
+
 float TextVisual::GetHeightForWidth( float width )
 {
   return mController->GetHeightForWidth( width );
@@ -202,54 +277,14 @@ void TextVisual::DoSetProperties( const Property::Map& propertyMap )
   {
     const KeyValuePair& keyValue = propertyMap.GetKeyValue( index );
 
-    switch( keyValue.first.type )
+    Property::Index indexKey = keyValue.first.indexKey;
+
+    if( keyValue.first.type == Property::Key::STRING )
     {
-      case Property::Key::INDEX:
-      {
-        DoSetProperty( keyValue.first.indexKey, keyValue.second );
-        break;
-      }
-      case Property::Key::STRING:
-      {
-        if( keyValue.first.stringKey == TEXT_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::TEXT, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == FONT_FAMILY_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::FONT_FAMILY, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == FONT_STYLE_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::FONT_STYLE, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == POINT_SIZE_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::POINT_SIZE, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == MULTI_LINE_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::MULTI_LINE, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == HORIZONTAL_ALIGNMENT_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::HORIZONTAL_ALIGNMENT, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == VERTICAL_ALIGNMENT_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::VERTICAL_ALIGNMENT, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == TEXT_COLOR_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::TEXT_COLOR, keyValue.second );
-        }
-        else if( keyValue.first.stringKey == ENABLE_MARKUP_PROPERTY )
-        {
-          DoSetProperty( Toolkit::TextVisual::Property::ENABLE_MARKUP, keyValue.second );
-        }
-        break;
-      }
+      indexKey = StringKeyToIndexKey( keyValue.first.stringKey );
     }
+
+    DoSetProperty( indexKey, keyValue.second );
   }
 
   // Elide the text if it exceeds the boundaries.
index ebeb867..9edf08c 100644 (file)
@@ -76,6 +76,12 @@ public:
    */
   static TextVisualPtr New( VisualFactoryCache& factoryCache, const Property::Map& properties );
 
+  /**
+   * @brief Converts all strings keys in property map to index keys.  Property Map can then be merged correctly.
+   * @param[in,out] propertyMap containing string keys or a mix of strings and indexes. Will be changed to index keys.
+   */
+  static void ConvertStringKeysToIndexKeys( Property::Map& propertyMap );
+
 public: // from Visual::Base
 
   /**
index 105f784..4473734 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_CHECK_BOX_BUTTON_H__
 
 /*
- * 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.
@@ -60,7 +60,7 @@ class CheckBoxButton;
  * {
  *   CheckBoxButton button = CheckBoxButton::New();
  *   button.SetParentOrigin( ParentOrigin::CENTER );
- *   button.SetLabelText( "Check" );
+ *   button.SetProperty( Button::Property::LABEL, "Check" );
  *   button.SetSize( 200, 40 );
  *   button.SetBackgroundColor( Color::WHITE );
  *   Stage::GetCurrent().Add( button );
index f0d2e29..c0535fe 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_PUSH_BUTTON_H__
 
 /*
- * 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.
@@ -54,7 +54,7 @@ class PushButton;
  * {
  *   PushButton button = PushButton::New();
  *   button.SetParentOrigin( ParentOrigin::CENTER );
- *   button.SetLabelText( "Press" );
+ *   button.SetProperty( Button::Property::LABEL, "Press" );
  *   Stage::GetCurrent().Add( button );
  *
  *   // Connect to button signals emitted by the button
index 0802b74..7538723 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.
@@ -71,7 +71,7 @@ RadioButton RadioButton::New()
 RadioButton RadioButton::New( const std::string& label )
 {
   RadioButton radioButton = Internal::RadioButton::New();
-  radioButton.SetLabelText( label );
+  radioButton.SetProperty( Toolkit::Button::Property::LABEL, label );
   return radioButton;
 }
 
index 0bc276e..99a4815 100644 (file)
@@ -2,7 +2,7 @@
 #define __DALI_TOOLKIT_RADIO_BUTTON_H__
 
 /*
- * 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.
@@ -45,7 +45,7 @@ class RadioButton;
  *
  * Radio buttons are designed to select one of many option at the same time.
  *
- * Every button have its own \e label and \e state, which can be modified by Button::SetLabelText and Button::SetSelected.
+ * Every button have its own \e label and \e state, which can be modified by Button::Property::LABEL and Button::Property::SELECTED.
  *
  * RadioButton can change its current state using Button::SetSelected.
  *
@@ -69,14 +69,14 @@ class RadioButton;
  *
  * // Make the first RadioButton and add it to its parent
  * RadioButton button1 = RadioButton::New();
- * button1.SetLabelText( "button1" );
+ * button1.SetProperty( Button::Property::LABEL, "button1" );
  * button1.SetBackgroundColor( Color::WHITE );
  * button1.SetPosition( 0, -40 );
  * radioGroup.Add( button1 );
  *
  * // Make more RadioButtons and add them to their parent
  * RadioButton button2 = RadioButton::New();
- * button2.SetLabelText( "button2" );
+ * button2.SetProperty( Toolkit::Button::Property::LABEL, "button2" );
  * button2.SetBackgroundColor( Color::WHITE );
  * button2.SetPosition( 0, 40 );
  * radioGroup.Add( button2 );