Change the state of EventData to EDITING in RemoveText
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Text-Controller.cpp
index d37a1db..b756ed7 100755 (executable)
@@ -23,6 +23,7 @@
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <toolkit-text-utils.h>
+#include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
 #include <dali-toolkit/internal/text/text-controller.h>
 #include <dali-toolkit/internal/text/text-control-interface.h>
 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
@@ -257,6 +258,9 @@ int UtcDaliTextControllerImfEvent(void)
   controller->GetText( text );
   DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
 
+  // for coverage
+  inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::UNDERLINE );
+
   // Send PRE_EDIT event
   imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "wo", 6, 2 );
   controller->OnInputMethodContextEvent( inputMethodContext, imfEvent );
@@ -1002,3 +1006,125 @@ int UtcDaliTextControllerCheckInputFontPointSizeChanged(void)
 
   END_TEST;
 }
+
+int UtcDaliTextControllerSelectEvent(void)
+{
+  tet_infoline(" UtcDaliTextControllerSelectEvent");
+  ToolkitTestApplication application;
+
+  // Creates a text controller.
+  ControllerPtr controller = Controller::New();
+
+  // Configures the text controller similarly to the text-field.
+  ConfigureTextField( controller );
+
+  // Set the text
+  const std::string text("Hello World!");
+  controller->SetText( text );
+
+  // Select the whole text.
+  controller->SelectEvent( 0.f, 0.f, false );
+
+  // Perform a relayout
+  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  controller->Relayout(size);
+
+  // Get the implementation of the text controller
+  Controller::Impl& mImpl = Controller::Impl::GetImplementation( *controller.Get() );
+
+  // Check if the whole text is selected or not.
+  std::string retrieved_text;
+  mImpl.RetrieveSelection( retrieved_text, false );
+  DALI_TEST_EQUALS( "Hello", retrieved_text, TEST_LOCATION );
+
+  // Select the whole text.
+  controller->SelectEvent( 0.f, 0.f, true );
+
+  // Perform a relayout
+  controller->Relayout( size );
+
+  mImpl.RetrieveSelection( retrieved_text, false );
+  DALI_TEST_EQUALS( text, retrieved_text, TEST_LOCATION );
+
+  END_TEST;
+}
+
+
+int UtcDaliTextControllerMaxLengthSetText(void)
+{
+  tet_infoline(" UtcDaliTextControllerMaxLengthSetText");
+  ToolkitTestApplication application;
+
+  // Creates a text controller.
+  ControllerPtr controller = Controller::New();
+
+  ConfigureTextLabel(controller);
+
+  const Length MAX_TEXT_LENGTH = 1024u * 32u;
+
+  // make over length world
+  int maxLength = (1024u * 32u) + 10u;
+  char world[maxLength];
+  for( int i = 0; i < maxLength; i++ )
+  {
+    world[i] = 'a';
+  }
+
+  // Set the text
+  std::string text(world);
+  controller->SetText( text );
+
+  // Perform a relayout
+  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  controller->Relayout(size);
+
+  // check text length
+  controller->GetText( text );
+  Length textSize = text.size();
+
+  DALI_TEST_EQUALS( MAX_TEXT_LENGTH, textSize, TEST_LOCATION );
+
+  END_TEST;
+}
+
+int UtcDaliTextControllerRemoveTextChangeEventData(void)
+{
+  tet_infoline(" UtcDaliTextControllerRemoveTextChangeEventData");
+  ToolkitTestApplication application;
+
+  // Creates a text controller.
+  ControllerPtr controller = Controller::New();
+
+  ConfigureTextField( controller );
+
+  // Set the text
+  const std::string text( "Hello World!" );
+  controller->SetText( text );
+  controller->SetInputFontPointSize( 1.0f );
+
+  // Get the implementation of the text controller
+  Controller::Impl& mImpl = Controller::Impl::GetImplementation( *controller.Get() );
+
+  DALI_TEST_EQUALS( EventData::INACTIVE, mImpl.mEventData->mState, TEST_LOCATION );
+
+  // Send DELETE_SURROUNDING event
+  InputMethodContext::EventData imfEvent = InputMethodContext::EventData( InputMethodContext::DELETE_SURROUNDING, "", -1, 1 );
+  InputMethodContext inputMethodContext = InputMethodContext::New();
+  controller->OnInputMethodContextEvent( inputMethodContext, imfEvent );
+
+  // Force to update the model.
+  controller->GetNaturalSize();
+
+  // Simulate a key event to delete text
+  controller->KeyEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Dali::KeyEvent::Down ) );
+
+  DALI_TEST_EQUALS( EventData::EDITING, mImpl.mEventData->mState, TEST_LOCATION );
+
+  // Perform a relayout
+  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  controller->Relayout( size );
+
+  tet_result(TET_PASS);
+
+  END_TEST;
+}