Updates for const->constexpr
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Text-Controller.cpp
index 3e53b67..708e4fb 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
@@ -23,6 +23,7 @@
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <toolkit-text-utils.h>
+#include <dali/devel-api/events/key-event-devel.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>
@@ -58,12 +59,7 @@ Dali::KeyEvent GenerateKey( const std::string& keyName,
                             unsigned long timeStamp,
                             const Dali::KeyEvent::State& keyState )
 {
-  return Dali::KeyEvent( keyName,
-                         keyString,
-                         keyCode,
-                         keyModifier,
-                         timeStamp,
-                         keyState );
+  return DevelKeyEvent::New( keyName, "", keyString, keyCode, keyModifier, timeStamp, keyState, "", "", Device::Class::NONE, Device::Subclass::NONE );
 }
 
 } // namespace
@@ -425,7 +421,7 @@ int UtcDaliTextControllerTextPopupButtonTouched(void)
                                                                                                             TextSelectionPopup::CLIPBOARD );
 
   textPopup.EnableButtons( buttonsToEnable );
-  Stage::GetCurrent().Add( textPopup );
+  application.GetScene().Add( textPopup );
   textPopup.ShowPopup();
 
   // Render and notify
@@ -663,7 +659,7 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void)
   tet_infoline(" UtcDaliTextControllerSetGetLineSpacingProperty");
   ToolkitTestApplication application;
 
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
 
   // single line text
   const std::string textSingle("A Quick Brown Fox Jumps Over The Lazy Dog");
@@ -679,8 +675,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void)
   // single line, line spacing = 0px
   {
     const float EXPECTED_SPACING = 0.0f;
-    const Vector2 EXPECTED_LAYOUT_SIZE( 342.0f, 19.0f);
-    const Vector3 EXPECTED_NATURAL_SIZE( 342.0f, 20.0f, 0.0f );
+    const Vector2 EXPECTED_LAYOUT_SIZE( 360.0f, 19.0f);
+    const Vector3 EXPECTED_NATURAL_SIZE( 360.0f, 20.0f, 0.0f );
 
     controller->SetText(textSingle);
     controller->Relayout(size);
@@ -698,8 +694,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void)
   // single line, line spacing = 20px
   {
     const float EXPECTED_SPACING = 20.0f;
-    const Vector2 EXPECTED_LAYOUT_SIZE( 342.0f, 19.0f );
-    const Vector3 EXPECTED_NATURAL_SIZE( 342.0f, 40.0f, 0.0f );
+    const Vector2 EXPECTED_LAYOUT_SIZE( 360.0f, 19.0f );
+    const Vector3 EXPECTED_NATURAL_SIZE( 360.0f, 40.0f, 0.0f );
 
     controller->SetText(textSingle);
     controller->Relayout(size);
@@ -718,8 +714,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void)
   // multi-line, line spacing = 0px
   {
     const float EXPECTED_SPACING = 0.0f;
-    const Vector2 EXPECTED_LAYOUT_SIZE( 332.0f, 39.0f );
-    const Vector3 EXPECTED_NATURAL_SIZE( 118.0f, 58.0f, 0.0f );
+    const Vector2 EXPECTED_LAYOUT_SIZE( 350.0f, 39.0f );
+    const Vector3 EXPECTED_NATURAL_SIZE( 124.0f, 58.0f, 0.0f );
 
     controller->SetText(textMulti);
     controller->Relayout(size);
@@ -738,8 +734,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void)
   // multi-line, line spacing = 20px
   {
     const float EXPECTED_SPACING = 20.0f;
-    const Vector2 EXPECTED_LAYOUT_SIZE( 118.0f, 57.0f );
-    const Vector3 EXPECTED_NATURAL_SIZE( 118.0f, 118.0f, 0.0f );
+    const Vector2 EXPECTED_LAYOUT_SIZE( 124.0f, 57.0f );
+    const Vector3 EXPECTED_NATURAL_SIZE( 124.0f, 118.0f, 0.0f );
 
     controller->SetText(textMulti);
     controller->Relayout(size);
@@ -758,8 +754,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void)
   // multi-line, line spacing = 30px
   {
     const float EXPECTED_SPACING = 30.0f;
-    const Vector2 EXPECTED_LAYOUT_SIZE( 118.0f, 117.0f );
-    const Vector3 EXPECTED_NATURAL_SIZE( 118.0f, 148.0f, 0.0f );
+    const Vector2 EXPECTED_LAYOUT_SIZE( 124.0f, 117.0f );
+    const Vector3 EXPECTED_NATURAL_SIZE( 124.0f, 148.0f, 0.0f );
 
     controller->SetText(textMulti);
     controller->Relayout(size);
@@ -804,7 +800,7 @@ int UtcDaliTextControllerCheckBufferIndices(void)
   mImpl.mOperationsPending = Controller::ALL_OPERATIONS;
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   tet_result(TET_PASS);
@@ -855,7 +851,7 @@ int UtcDaliTextControllerCheckInputColorChanged(void)
   DALI_TEST_EQUALS( Controller::COLOR, static_cast<Controller::OperationsMask>( mImpl.mOperationsPending & Controller::COLOR ), TEST_LOCATION );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   tet_result(TET_PASS);
@@ -904,7 +900,7 @@ int UtcDaliTextControllerCheckInputFontFamilyChanged(void)
                     TEST_LOCATION );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   tet_result(TET_PASS);
@@ -953,7 +949,7 @@ int UtcDaliTextControllerCheckInputFontWeightChanged(void)
                     TEST_LOCATION );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   tet_result(TET_PASS);
@@ -1002,7 +998,7 @@ int UtcDaliTextControllerCheckInputFontWidthChanged(void)
                     TEST_LOCATION );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   tet_result(TET_PASS);
@@ -1051,7 +1047,7 @@ int UtcDaliTextControllerCheckInputFontSlantChanged(void)
                     TEST_LOCATION );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   tet_result(TET_PASS);
@@ -1100,7 +1096,7 @@ int UtcDaliTextControllerCheckInputFontPointSizeChanged(void)
                     TEST_LOCATION );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   tet_result(TET_PASS);
@@ -1124,10 +1120,10 @@ int UtcDaliTextControllerSelectEvent(void)
   controller->SetText( text );
 
   // Select the whole text.
-  controller->SelectEvent( 0.f, 0.f, false );
+  controller->SelectEvent( 0.f, 0.f, SelectionType::INTERACTIVE );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   // Get the implementation of the text controller
@@ -1139,7 +1135,7 @@ int UtcDaliTextControllerSelectEvent(void)
   DALI_TEST_EQUALS( "Hello", retrieved_text, TEST_LOCATION );
 
   // Select the whole text.
-  controller->SelectEvent( 0.f, 0.f, true );
+  controller->SelectEvent( 0.f, 0.f, SelectionType::ALL );
 
   // Perform a relayout
   controller->Relayout( size );
@@ -1185,7 +1181,106 @@ int UtcDaliTextControllerRemoveTextChangeEventData(void)
   DALI_TEST_EQUALS( EventData::EDITING, mImpl.mEventData->mState, TEST_LOCATION );
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
+  controller->Relayout( size );
+
+  tet_result(TET_PASS);
+
+  END_TEST;
+}
+
+int UtcDaliTextControllerCheckInputFontPointSizeUpdated(void)
+{
+  tet_infoline(" UtcDaliTextControllerCheckInputFontPointSizeUpdated");
+  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 );
+  controller->KeyboardFocusGainEvent();
+
+  application.SendNotification();
+  application.Render();
+
+  // Perform a relayout
+  const Size size( application.GetScene().GetSize() );
+  controller->Relayout(size);
+
+  // simulate a key event.
+  controller->KeyEvent( GenerateKey( "a", "a", 38, 0, 0, Dali::KeyEvent::Down ) );
+
+  // change the input font point size
+  controller->SetInputFontPointSize( 20.f );
+
+  application.SendNotification();
+  application.Render();
+
+  // Perform a relayout
+  controller->Relayout(size);
+
+  tet_result(TET_PASS);
+
+  END_TEST;
+}
+
+int UtcDaliTextControllerDeleteSurroundings(void)
+{
+  tet_infoline(" UtcDaliTextControllerDeleteSurroundings");
+  ToolkitTestApplication application;
+
+  // Creates a text controller.
+  ControllerPtr controller = Controller::New();
+
+  ConfigureTextField( controller );
+
+  // 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 );
+
+  InputMethodContext inputMethodContext = InputMethodContext::New();
+  // Add some pre-edit text, such as Korean
+  InputMethodContext::EventData imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "ㅂㅂㅂ", 0, 3 );
+  controller->OnInputMethodContextEvent( inputMethodContext, imfEvent );
+
+  // Perform a relayout
+  const Size size( application.GetScene().GetSize() );
+
+  application.SendNotification();
+  application.Render();
+
+  controller->Relayout( size );
+
+  // Simulate a key event to delete one text
+  controller->KeyEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Dali::KeyEvent::Down ) );
+
+  // Send DELETE_SURROUNDING event (Delete All text)
+  imfEvent = InputMethodContext::EventData( InputMethodContext::DELETE_SURROUNDING, "", -2, 2 );
+  controller->OnInputMethodContextEvent( inputMethodContext, imfEvent );
+
+  application.SendNotification();
+  application.Render();
+
+  controller->Relayout( size );
+
+  // simulate a key event to add text
+  controller->KeyEvent( GenerateKey( "ㅇ", "ㅇ", 238, 0, 0, Dali::KeyEvent::Down ) );
+  controller->KeyEvent( GenerateKey( "ㅇ", "ㅇ", 238, 0, 0, Dali::KeyEvent::Down ) );
+
+  DALI_TEST_EQUALS( EventData::EDITING, mImpl.mEventData->mState, TEST_LOCATION );
+
+  // Force to update the model.
+  controller->GetNaturalSize();
+
+  application.SendNotification();
+  application.Render();
+
   controller->Relayout( size );
 
   tet_result(TET_PASS);