Updates following boost::function removal from adaptor
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextInput.cpp
index 5b56cec..9f8905e 100644 (file)
@@ -473,7 +473,7 @@ int UtcDaliTextInputSetAndGetBoundingRectangle(void)
 }
 
 
-int UtcDaliTextInputSetAndGetTextAlignment(void)
+int UtcDaliTextInputSetAndGetTextAlignment01(void)
 {
   ToolkitTestApplication application;
 
@@ -490,6 +490,22 @@ int UtcDaliTextInputSetAndGetTextAlignment(void)
   END_TEST;
 }
 
+int UtcDaliTextInputSetAndGetTextAlignment02(void)
+{
+  ToolkitTestApplication application;
+
+  TextInput textInput = TextInput::New();
+  textInput.SetTextAlignment(static_cast<Alignment::Type>( Alignment::HorizontalCenter) );
+
+  bool result = ( textInput.GetTextAlignment() & Alignment::HorizontalCenter ) ;
+
+  DALI_TEST_CHECK( result );
+
+  result = ( textInput.GetTextAlignment() & Alignment::HorizontalRight );
+
+  DALI_TEST_CHECK( !result );
+  END_TEST;
+}
 
 int UtcDaliTextInputSetSortModifier(void)
 {
@@ -726,3 +742,227 @@ int UtcDaliTextInputScroll(void)
   DALI_TEST_EQUALS( scrollPosition, Vector2( 149.153656f, 0.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
   END_TEST;
 }
+
+int UtcDaliTextInputSetActiveStyle(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline("Testing Setting of Style to newly added text");
+
+  TextInput textInput = TextInput::New();  // create empty TextInput
+
+  Stage::GetCurrent().Add(textInput);
+
+  const std::string styledString = "Test String<i>ab</i>" ;
+  const std::string plainString = "Test String";
+  textInput.SetInitialText( plainString );
+
+  application.SendNotification();
+  application.Render();
+
+  textInput.SetEditable(true);
+
+  std::string retreivedMarkupString = textInput.GetMarkupText();
+
+  tet_infoline("Confirm markup text is a plain string ");
+  DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
+
+  TextStyle style;
+  style.SetItalics( true );
+
+  tet_infoline("Apply style to TextInput");
+  textInput.SetActiveStyle( style );
+
+  Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
+  Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
+
+  application.SendNotification();
+  application.Render();
+
+  application.ProcessEvent(eventA);
+  application.SendNotification();
+  application.Render();
+
+  application.ProcessEvent(eventB);
+  application.SendNotification();
+  application.Render();
+
+  retreivedMarkupString = textInput.GetMarkupText();
+
+  DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliTextInputApplyStyleToSelectedText(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline("Testing application of style to selected text ");
+
+  TextInput textInput = TextInput::New();  // create empty TextInput
+
+  Stage::GetCurrent().Add(textInput);
+
+  const std::string styledString = "Test <i>String</i> to style";
+  const std::string plainString = "Test String to style";
+  textInput.SetInitialText( plainString );
+
+  application.SendNotification();
+  application.Render();
+
+  textInput.SetEditable(true);
+
+  std::string retreivedMarkupString = textInput.GetMarkupText();
+
+  tet_infoline("Confirm markup text is a plain string ");
+  DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
+
+  TextStyle style;
+  style.SetItalics( true );
+
+  textInput.SelectText( 5, 11 );
+
+  tet_infoline("Apply style to selected text");
+  textInput.ApplyStyle( style );
+
+  application.Render();
+
+  retreivedMarkupString = textInput.GetMarkupText();
+
+  DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliTextInputApplyStyleToAll(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline("Testing application of style to all text ");
+
+  TextInput textInput = TextInput::New();  // create empty TextInput
+
+  Stage::GetCurrent().Add(textInput);
+
+  const std::string styledString = "<i>Test String to style</i>";
+  const std::string plainString = "Test String to style";
+  textInput.SetInitialText( plainString );
+
+  application.SendNotification();
+  application.Render();
+
+  textInput.SetEditable(true);
+
+  std::string retreivedMarkupString = textInput.GetMarkupText();
+
+  tet_infoline("Confirm markup text is a plain string ");
+  DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
+
+  TextStyle style;
+  style.SetItalics( true );
+
+  tet_infoline("Apply style to all text");
+  textInput.ApplyStyleToAll( style );
+
+  application.Render();
+
+  retreivedMarkupString = textInput.GetMarkupText();
+
+  DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliTextInputGetStyleAtCursor(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline("Test getting style at cursor");
+
+  TextInput textInput = TextInput::New();  // create empty TextInput
+
+  Stage::GetCurrent().Add(textInput);
+
+  const std::string styledString = "Test Stringa<i>b</i>" ;
+  const std::string plainString = "Test String";
+  textInput.SetInitialText( plainString );
+
+  application.SendNotification();
+  application.Render();
+
+  textInput.SetEditable(true);
+
+  tet_infoline("Confirm style at cursor is default(plain)");
+  TextStyle style;
+  Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
+  application.ProcessEvent(eventA);
+  application.SendNotification();
+  application.Render();
+
+  TextStyle retreivedStyleAtCursor = textInput.GetStyleAtCursor();
+
+  DALI_TEST_CHECK( style == retreivedStyleAtCursor );
+  DALI_TEST_CHECK( !retreivedStyleAtCursor.IsItalicsEnabled() );
+
+  tet_infoline("Set style before adding new character");
+  style.SetItalics( true );
+  textInput.SetActiveStyle( style );
+
+  Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
+  application.ProcessEvent(eventB);
+  application.SendNotification();
+  application.Render();
+
+  tet_infoline("Confirm style at cursor is correct style");
+  retreivedStyleAtCursor = textInput.GetStyleAtCursor();
+
+  DALI_TEST_CHECK( retreivedStyleAtCursor.IsItalicsEnabled() );
+
+  tet_infoline("Confirm style at cursor is not a style that was not set");
+  DALI_TEST_CHECK( !retreivedStyleAtCursor.IsUnderlineEnabled() );
+
+  tet_infoline("Confirm markup text is correct");
+  DALI_TEST_EQUALS( styledString, textInput.GetMarkupText(), TEST_LOCATION);
+
+
+
+  END_TEST;
+}
+
+int UtcDaliTextInputSetAndGetMultilinePolicy(void)
+{
+  ToolkitTestApplication application;
+
+  const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
+  const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
+
+  TextInput textInput = TextInput::New();
+  Stage::GetCurrent().Add(textInput);
+  textInput.SetInitialText( "Hello world!" );
+
+  for( unsigned int epIndex = 0; epIndex < NUM_MULTILINE_POLICIES; ++epIndex )
+  {
+    textInput.SetMultilinePolicy( MULTILINE_POLICIES[epIndex] );
+
+    DALI_TEST_EQUALS( textInput.GetMultilinePolicy(), MULTILINE_POLICIES[epIndex], TEST_LOCATION );
+  }
+  END_TEST;
+}
+
+int UtcDaliTextInputSetAndGetExceedEnabled(void)
+{
+  ToolkitTestApplication application;
+
+  const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
+  const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
+
+  TextInput textInput = TextInput::New();
+  Stage::GetCurrent().Add(textInput);
+  textInput.SetInitialText( "Hello world!" );
+
+  for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
+  {
+    textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
+
+    DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );
+  }
+  END_TEST;
+}