Updates for const->constexpr
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Text-Controller.cpp
index b32e328..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");
@@ -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);
@@ -1127,7 +1123,7 @@ int UtcDaliTextControllerSelectEvent(void)
   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
@@ -1185,7 +1181,7 @@ 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);
@@ -1213,7 +1209,7 @@ int UtcDaliTextControllerCheckInputFontPointSizeUpdated(void)
   application.Render();
 
   // Perform a relayout
-  const Size size( Dali::Stage::GetCurrent().GetSize() );
+  const Size size( application.GetScene().GetSize() );
   controller->Relayout(size);
 
   // simulate a key event.
@@ -1232,3 +1228,62 @@ int UtcDaliTextControllerCheckInputFontPointSizeUpdated(void)
 
   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);
+
+  END_TEST;
+}