Change raw pointer to unique_ptr
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextField.cpp
index f6e24e6..d00dc75 100644 (file)
@@ -3221,6 +3221,70 @@ int UtcDaliTextFieldSettingPlaceholder(void)
   END_TEST;
 }
 
+int UtcDaliTextFieldPlaceholderCoverage(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliTextFieldPlaceholderCoverage");
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  TextField fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderFontFamily() coverage.
+  Property::Map fontFamilyMap;
+  fontFamilyMap[Text::PlaceHolder::Property::FONT_FAMILY] = "Arial";
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontFamilyMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontSize coverage.
+  Property::Map fontSizeMap;
+  fontSizeMap[Text::PlaceHolder::Property::PIXEL_SIZE] = 15.0f;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontSizeMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontWeight coverage.
+  Property::Map fontStyleWeightMap;
+  Property::Map fontStyleWeightPropertyMap;
+  fontStyleWeightPropertyMap.Insert("weight", "bold");
+  fontStyleWeightMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWeightPropertyMap;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWeightMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontWidth coverage.
+  Property::Map fontStyleWidthMap;
+  Property::Map fontStyleWidthPropertyMap;
+  fontStyleWidthPropertyMap.Insert("width", "expanded");
+  fontStyleWidthMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWidthPropertyMap;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWidthMap);
+
+  // mPlaceholderFont is created only once, so create a new control for coverage.
+  fieldForCoverage = TextField::New();
+  DALI_TEST_CHECK(fieldForCoverage);
+  application.GetScene().Add(fieldForCoverage);
+
+  // for SetPlaceholderTextFontSlant coverage.
+  Property::Map fontStyleSlantMap;
+  Property::Map fontStyleSlantPropertyMap;
+  fontStyleSlantPropertyMap.Insert("slant", "italic");
+  fontStyleSlantMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleSlantPropertyMap;
+  fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleSlantMap);
+
+  END_TEST;
+}
+
 int UtcDaliTextFieldSetPaddingProperty(void)
 {
   ToolkitTestApplication application;
@@ -3482,6 +3546,66 @@ int UtcDaliTextFieldSelectWholeText(void)
   END_TEST;
 }
 
+int UtcDaliTextFieldSelectText(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextFieldSelectText ");
+
+  TextField textField = TextField::New();
+
+  application.GetScene().Add( textField );
+
+  textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
+  textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
+  textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+  application.SendNotification();
+  application.Render();
+
+  DevelTextField::SelectText( textField, 0, 5 );
+
+  application.SendNotification();
+  application.Render();
+
+  // Nothing is selected
+  std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+  DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
+
+  textField.SetProperty( TextField::Property::TEXT, "Hello world" );
+
+  application.SendNotification();
+  application.Render();
+
+  // Hello is selected
+  DevelTextField::SelectText( textField, 0, 5 );
+
+  application.SendNotification();
+  application.Render();
+
+  selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+  DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 0, TEST_LOCATION );
+  DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 5, TEST_LOCATION );
+
+  // world is selected
+  DevelTextField::SelectText( textField, 6, 11 );
+
+  application.SendNotification();
+  application.Render();
+
+  selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
+  DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION );
+
+  DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 6, TEST_LOCATION );
+  DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 11, TEST_LOCATION );
+
+  END_TEST;
+}
+
 int UtcDaliTextFieldSelectNone(void)
 {
   ToolkitTestApplication application;
@@ -3675,6 +3799,7 @@ int UtcDaliTextFieldPrimaryCursorPosition(void)
   textField.SetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
   application.SendNotification();
   application.Render();
+  textField.SetKeyInputFocus();
 
   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );