X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit-internal%2Futc-Dali-Text-Controller.cpp;h=3e53b671bb996df7dfb3625f3d7489fe50b0cc3c;hb=3ed4510ab5a2673eb62a6dafe327d8cd0e78d96a;hp=66b7149451aae39f53702ee38ccae086872a4fc8;hpb=9df674d995218c964b7e498f83daed40da766464;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp index 66b7149..3e53b67 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Controller.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 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 #include #include +#include #include #include #include @@ -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 ); @@ -285,6 +289,107 @@ int UtcDaliTextControllerImfEvent(void) END_TEST; } +int UtcDaliTextControllerImfPreeditStyle(void) +{ + tet_infoline(" UtcDaliTextControllerImfPreeditStyle"); + ToolkitTestApplication application; + + // Creates a text controller. + ControllerPtr controller = Controller::New(); + + std::string text; + InputMethodContext::EventData imfEvent; + + DALI_TEST_CHECK( controller ); + + // Configures the text controller similarly to the text-field. + ConfigureTextField( controller ); + + InputMethodContext inputMethodContext = InputMethodContext::New(); + + // Send COMMIT event. + imfEvent = InputMethodContext::EventData( InputMethodContext::COMMIT, "Hello ", 0, 6 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + + // Force to update the model. + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION ); + + // Send PRE_EDIT event + imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "w", 6, 1 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::NONE ); + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION ); + + imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "w", 6, 1 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + + // Set the preedit style as REVERSE + inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::REVERSE ); + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION ); + + imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "w", 6, 1 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + + // Set the preedit style as HIGHLIGHT + inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::HIGHLIGHT ); + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION ); + + imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "w", 6, 1 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + + // Set the preedit style as CUSTOM_PLATFORM_STYLE_1 + inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_1 ); + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION ); + + imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "w", 6, 1 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + + // Set the preedit style as CUSTOM_PLATFORM_STYLE_2 + inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_2 ); + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION ); + + imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "w", 6, 1 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + + // Set the preedit style as CUSTOM_PLATFORM_STYLE_3 + inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_3 ); + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION ); + + imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "w", 6, 1 ); + controller->OnInputMethodContextEvent( inputMethodContext, imfEvent ); + + // Set the preedit style as CUSTOM_PLATFORM_STYLE_4 + inputMethodContext.SetPreeditStyle( InputMethodContext::PreeditStyle::CUSTOM_PLATFORM_STYLE_4 ); + controller->GetNaturalSize(); + + controller->GetText( text ); + DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION ); + + tet_result(TET_PASS); + END_TEST; +} + int UtcDaliTextControllerTextPopupButtonTouched(void) { tet_infoline(" UtcDaliTextControllerTextPopupButtonTouched"); @@ -574,8 +679,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void) // single line, line spacing = 0px { const float EXPECTED_SPACING = 0.0f; - const Vector2 EXPECTED_LAYOUT_SIZE( 326.0f, 19.0f); - const Vector3 EXPECTED_NATURAL_SIZE( 326.0f, 20.0f, 0.0f ); + const Vector2 EXPECTED_LAYOUT_SIZE( 342.0f, 19.0f); + const Vector3 EXPECTED_NATURAL_SIZE( 342.0f, 20.0f, 0.0f ); controller->SetText(textSingle); controller->Relayout(size); @@ -593,8 +698,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void) // single line, line spacing = 20px { const float EXPECTED_SPACING = 20.0f; - const Vector2 EXPECTED_LAYOUT_SIZE( 326.0f, 19.0f ); - const Vector3 EXPECTED_NATURAL_SIZE( 326.0f, 40.0f, 0.0f ); + const Vector2 EXPECTED_LAYOUT_SIZE( 342.0f, 19.0f ); + const Vector3 EXPECTED_NATURAL_SIZE( 342.0f, 40.0f, 0.0f ); controller->SetText(textSingle); controller->Relayout(size); @@ -613,8 +718,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void) // multi-line, line spacing = 0px { const float EXPECTED_SPACING = 0.0f; - const Vector2 EXPECTED_LAYOUT_SIZE( 318.0f, 39.0f ); - const Vector3 EXPECTED_NATURAL_SIZE( 116.0f, 58.0f, 0.0f ); + const Vector2 EXPECTED_LAYOUT_SIZE( 332.0f, 39.0f ); + const Vector3 EXPECTED_NATURAL_SIZE( 118.0f, 58.0f, 0.0f ); controller->SetText(textMulti); controller->Relayout(size); @@ -633,8 +738,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void) // multi-line, line spacing = 20px { const float EXPECTED_SPACING = 20.0f; - const Vector2 EXPECTED_LAYOUT_SIZE( 115.0f, 57.0f ); - const Vector3 EXPECTED_NATURAL_SIZE( 116.0f, 118.0f, 0.0f ); + const Vector2 EXPECTED_LAYOUT_SIZE( 118.0f, 57.0f ); + const Vector3 EXPECTED_NATURAL_SIZE( 118.0f, 118.0f, 0.0f ); controller->SetText(textMulti); controller->Relayout(size); @@ -653,8 +758,8 @@ int UtcDaliTextControllerSetGetLineSpacingProperty(void) // multi-line, line spacing = 30px { const float EXPECTED_SPACING = 30.0f; - const Vector2 EXPECTED_LAYOUT_SIZE( 115.0f, 117.0f ); - const Vector3 EXPECTED_NATURAL_SIZE( 116.0f, 148.0f, 0.0f ); + const Vector2 EXPECTED_LAYOUT_SIZE( 118.0f, 117.0f ); + const Vector3 EXPECTED_NATURAL_SIZE( 118.0f, 148.0f, 0.0f ); controller->SetText(textMulti); controller->Relayout(size); @@ -1002,3 +1107,88 @@ 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 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; +}