X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-TextEditor.cpp;h=0bac46af1a0d263ccfd8bdee27c5b082d74cb7a4;hp=62625ef14279cb7c0ae28c42ae6b6c294526f2ad;hb=478e477e07fde916953748d2cd4befc0326bfc34;hpb=55bef2b585b85c078894362584c00f29e6fef58e diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 62625ef..0bac46a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include "test-text-geometry-utils.h" using namespace Dali; using namespace Toolkit; @@ -104,7 +106,9 @@ const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION = "matchSys const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength"; const char* const PROPERTY_NAME_FONT_SIZE_SCALE = "fontSizeScale"; const char* const PROPERTY_NAME_GRAB_HANDLE_COLOR = "grabHandleColor"; - +const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP = "enableGrabHandlePopup"; +const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "inputMethodSettings"; +const char* const PROPERTY_NAME_INPUT_FILTER = "inputFilter"; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color. @@ -130,11 +134,19 @@ const char* HANDLE_RIGHT_SELECTION_FILE_NAME = TEST_RESOURCE_DIR "/selection_han const std::string DEFAULT_DEVICE_NAME("hwKeyboard"); +static bool gSelectionChangedCallbackCalled; +static uint32_t oldSelectionStart; +static uint32_t oldSelectionEnd; +static bool gSelectionClearedCallbackCalled; static bool gAnchorClickedCallBackCalled; static bool gAnchorClickedCallBackNotCalled; static bool gTextChangedCallBackCalled; +static bool gInputFilteredAcceptedCallbackCalled; +static bool gInputFilteredRejectedCallbackCalled; static bool gInputStyleChangedCallbackCalled; static bool gMaxCharactersCallBackCalled; +static bool gCursorPositionChangedCallbackCalled; +static uint32_t oldCursorPos; static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask; struct CallbackFunctor @@ -151,6 +163,22 @@ struct CallbackFunctor bool* mCallbackFlag; }; +static void TestSelectionClearedCallback(TextEditor control) +{ + tet_infoline(" TestSelectionClearedCallback"); + + gSelectionClearedCallbackCalled = true; +} + +static void TestSelectionChangedCallback(TextEditor control, uint32_t oldStart, uint32_t oldEnd) +{ + tet_infoline(" TestSelectionChangedCallback"); + + gSelectionChangedCallbackCalled = true; + oldSelectionStart = oldStart; + oldSelectionEnd = oldEnd; +} + static void TestAnchorClickedCallback(TextEditor control, const char* href, unsigned int hrefLength) { tet_infoline(" TestAnchorClickedCallback"); @@ -163,6 +191,14 @@ static void TestAnchorClickedCallback(TextEditor control, const char* href, unsi } } +static void TestCursorPositionChangedCallback( TextEditor control, unsigned int oldPos ) +{ + tet_infoline(" TestCursorPositionChangedCallback"); + + gCursorPositionChangedCallbackCalled = true; + oldCursorPos = oldPos; +} + static void TestTextChangedCallback( TextEditor control ) { tet_infoline(" TestTextChangedCallback"); @@ -185,6 +221,20 @@ static void TestMaxLengthReachedCallback( TextEditor control ) gMaxCharactersCallBackCalled = true; } +static void TestInputFilteredCallback(TextEditor control, Toolkit::InputFilter::Property::Type type) +{ + tet_infoline(" TestInputFilteredCallback"); + + if(type == Toolkit::InputFilter::Property::ACCEPTED) + { + gInputFilteredAcceptedCallbackCalled = true; + } + else if(type == Toolkit::InputFilter::Property::REJECTED) + { + gInputFilteredRejectedCallbackCalled = true; + } +} + // Generate a KeyEvent to send to Core. Integration::KeyEvent GenerateKey( const std::string& keyName, const std::string& logicalKey, @@ -511,7 +561,9 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == DevelTextEditor::Property::MAX_LENGTH ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_COLOR ) == DevelTextEditor::Property::GRAB_HANDLE_COLOR ); - + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP ) == DevelTextEditor::Property::ENABLE_GRAB_HANDLE_POPUP ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == DevelTextEditor::Property::INPUT_METHOD_SETTINGS ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FILTER ) == DevelTextEditor::Property::INPUT_FILTER ); END_TEST; } @@ -930,9 +982,65 @@ int UtcDaliTextEditorSetPropertyP(void) editor.SetProperty( DevelTextEditor::Property::GRAB_HANDLE_COLOR, Color::GREEN ); DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::GRAB_HANDLE_COLOR ), Color::GREEN, TEST_LOCATION ); + // Test the ENABLE_GRAB_HANDLE_POPUP property + editor.SetProperty( DevelTextEditor::Property::ENABLE_GRAB_HANDLE_POPUP, false ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::ENABLE_GRAB_HANDLE_POPUP ), false, TEST_LOCATION); + + // Check the input method setting + Property::Map propertyMap; + InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER; + InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD; + InputMethod::ButtonAction::Type buttonAction = InputMethod::ButtonAction::GO; + int inputVariation = 1; + propertyMap["PANEL_LAYOUT"] = panelLayout; + propertyMap["AUTO_CAPITALIZE"] = autoCapital; + propertyMap["BUTTON_ACTION"] = buttonAction; + propertyMap["VARIATION"] = inputVariation; + editor.SetProperty( DevelTextEditor::Property::INPUT_METHOD_SETTINGS, propertyMap ); + + Property::Value value = editor.GetProperty( DevelTextEditor::Property::INPUT_METHOD_SETTINGS ); + Property::Map map; + DALI_TEST_CHECK( value.Get( map ) ); + + int layout = 0; + DALI_TEST_CHECK( map[ "PANEL_LAYOUT" ].Get( layout ) ); + DALI_TEST_EQUALS( static_cast(panelLayout), layout, TEST_LOCATION ); + + int capital = 0; + DALI_TEST_CHECK( map[ "AUTO_CAPITALIZE" ].Get( capital ) ); + DALI_TEST_EQUALS( static_cast(autoCapital), capital, TEST_LOCATION ); + + int action = 0; + DALI_TEST_CHECK( map[ "BUTTON_ACTION" ].Get( action ) ); + DALI_TEST_EQUALS( static_cast(buttonAction), action, TEST_LOCATION ); + + int variation = 0; + DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) ); + DALI_TEST_EQUALS( inputVariation, variation, TEST_LOCATION ); + + // Check the input filter property + Property::Map inputFilterMapSet; + Property::Map inputFilterMapGet; + inputFilterMapSet[InputFilter::Property::ACCEPTED] = "[\\w]"; + inputFilterMapSet[InputFilter::Property::REJECTED] = "[\\d]"; + + editor.SetProperty(DevelTextEditor::Property::INPUT_FILTER, inputFilterMapSet); + + inputFilterMapGet = editor.GetProperty(DevelTextEditor::Property::INPUT_FILTER); + DALI_TEST_EQUALS(inputFilterMapGet.Count(), inputFilterMapSet.Count(), TEST_LOCATION); + + // Clear + inputFilterMapSet.Clear(); + editor.SetProperty(DevelTextEditor::Property::INPUT_FILTER, inputFilterMapSet); + application.SendNotification(); application.Render(); + // Check the line size property + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MIN_LINE_SIZE ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + editor.SetProperty( DevelTextEditor::Property::MIN_LINE_SIZE, 50.f ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MIN_LINE_SIZE ), 50.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + END_TEST; } @@ -3009,13 +3117,13 @@ int UtcDaliTextEditorMatchSystemLanguageDirectionProperty(void) application.SendNotification(); application.Render(); - // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'false'. - DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION ); - - // Check the enable match system language direction property - editor.SetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true ); + // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'true'. DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), true, TEST_LOCATION ); + // Check the disable match system language direction property + editor.SetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, false ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION ); + application.SendNotification(); application.Render(); @@ -3066,6 +3174,58 @@ int utcDaliTextEditorMaxCharactersReached(void) END_TEST; } +int utcDaliTextEditorInputFiltered(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorInputFiltered"); + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK(editor); + + application.GetScene().Add(editor); + + Property::Map inputFilter; + + // Only digit is accepted. + inputFilter[InputFilter::Property::ACCEPTED] = "[\\d]"; + + // Set input filter to TextEditor. + editor.SetProperty(DevelTextEditor::Property::INPUT_FILTER, inputFilter); + + editor.SetKeyInputFocus(); + + // connect to the input filtered signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextEditor::InputFilteredSignal(editor).Connect(&TestInputFilteredCallback); + bool inputFilteredSignal = false; + editor.ConnectSignal(testTracker, "inputFiltered", CallbackFunctor(&inputFilteredSignal)); + + gInputFilteredAcceptedCallbackCalled = false; + + application.ProcessEvent(GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE )); + + DALI_TEST_CHECK(gInputFilteredAcceptedCallbackCalled); + DALI_TEST_CHECK(inputFilteredSignal); + + // Word is rejected. + inputFilter[InputFilter::Property::ACCEPTED] = ""; + inputFilter[InputFilter::Property::REJECTED] = "[\\w]"; + + // Set input filter to TextEditor. + editor.SetProperty(DevelTextEditor::Property::INPUT_FILTER, inputFilter); + + editor.SetKeyInputFocus(); + + inputFilteredSignal = false; + gInputFilteredRejectedCallbackCalled = false; + + application.ProcessEvent(GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + + DALI_TEST_CHECK(gInputFilteredAcceptedCallbackCalled); + DALI_TEST_CHECK(inputFilteredSignal); + + END_TEST; +} + int UtcDaliTextEditorSelectWholeText(void) { ToolkitTestApplication application; @@ -3118,6 +3278,65 @@ int UtcDaliTextEditorSelectWholeText(void) END_TEST; } +int UtcDaliTextEditorSelectText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorSelectText "); + + TextEditor textEditor = TextEditor::New(); + + application.GetScene().Add( textEditor ); + + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectText( textEditor ,0, 5 ); + + application.SendNotification(); + application.Render(); + + // Nothing is selected + std::string selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION ); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectText( textEditor, 0, 5 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 5, TEST_LOCATION ); + + // world is selected + DevelTextEditor::SelectText( textEditor, 6, 11 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 6, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 11, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliTextEditorSelectNone(void) { ToolkitTestApplication application; @@ -3341,6 +3560,7 @@ int UtcDaliTextEditorPrimaryCursorPosition(void) textEditor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 3); application.SendNotification(); application.Render(); + textEditor.SetKeyInputFocus(); application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); @@ -3480,6 +3700,49 @@ int utcDaliTextEditorGetHeightForWidthDoesNotChangeLineCountLineWrapCharCase(voi END_TEST; } +int utcDaliTextEditorGetHeightForWidthChangeLineCountWhenTextChanged(void) +{ + ToolkitTestApplication application; + + tet_infoline(" utcDaliTextEditorGetHeightForWidthChangeLineCountWhenTextChanged "); + + int lineCountBefore =0 ; + int lineCountAfter =0 ; + + // Create a text editor + TextEditor textEditor = TextEditor::New(); + //Set very large font-size using point-size + textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 10) ; + //Specify font-family + textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans"); + //Specify size + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 200.f, 100.f ) ); + //Set text longer than width of textEditor + textEditor.SetProperty( TextEditor::Property::TEXT, "Short text"); + //Set line wrap mode Character + textEditor.SetProperty(TextEditor::Property::LINE_WRAP_MODE, "CHARACTER"); + + application.GetScene().Add( textEditor ); + + application.SendNotification(); + application.Render(); + + + lineCountBefore = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + + textEditor.SetProperty( TextEditor::Property::TEXT, "This is very loooooooooooooooooooooooooooooooooooong text for test"); + lineCountAfter = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + + // When the text changed, the Line-count should be updated according to new text. + // Because the GetHeightForWidth is called in Controller::GetLineCount(float width) + DALI_TEST_EQUALS( lineCountBefore ,1, TEST_LOCATION ); + DALI_TEST_GREATER( lineCountAfter,1, TEST_LOCATION ); + + + END_TEST; +} + + int utcDaliTextEditorGetNaturalSizeDoesNotChangeLineCountScrollingCase(void) { ToolkitTestApplication application; @@ -3570,4 +3833,1352 @@ int utcDaliTextEditorGetNaturalSizeDoesNotChangeLineCountLineWrapCharCase(void) DALI_TEST_EQUALS( lineCountAfter , lineCountBefore, TEST_LOCATION ); END_TEST; +} + +int UtcDaliTextEditorAtlasLimitationIsEnabledForLargeFontPointSize(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorAtlasLimitationIsEnabledForLargeFontPointSize "); + + // +2: First one to handle the equal case. Second one to handle odd to even case of GetNaturalSize + const uint32_t lessThanWidth = TextAbstraction::FontClient::MAX_TEXT_ATLAS_WIDTH - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2; + const uint32_t lessThanHeight = TextAbstraction::FontClient::MAX_TEXT_ATLAS_HEIGHT - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2; + + // Create a text editor + TextEditor textEditor = TextEditor::New(); + + //Set size to avoid automatic eliding + textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025)); + //Set very large font-size using point-size + textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 1000) ; + //Specify font-family + textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans"); + //Set text to check if appear or not + textEditor.SetProperty( TextEditor::Property::TEXT, "A"); + + application.GetScene().Add( textEditor ); + + application.SendNotification(); + application.Render(); + //Use GetNaturalSize to verify that size of block does not exceed Atlas size + Vector3 naturalSize = textEditor.GetNaturalSize(); + + DALI_TEST_GREATER( lessThanWidth, static_cast(naturalSize.width), TEST_LOCATION ); + DALI_TEST_GREATER( lessThanHeight, static_cast(naturalSize.height), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorAtlasLimitationIsEnabledPerformanceCases(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorAtlasLimitationIsEnabledPerformanceCases "); + + // +2: First one to handle the equal case. Second one to handle odd to even case of GetNaturalSize + const uint32_t lessThanWidth = TextAbstraction::FontClient::MAX_TEXT_ATLAS_WIDTH - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2; + const uint32_t lessThanHeight = TextAbstraction::FontClient::MAX_TEXT_ATLAS_HEIGHT - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2; + + Vector3 naturalSize; //Use GetNaturalSize to verify that size of block does not exceed Atlas size + // Create a text editor + TextEditor textEditor = TextEditor::New(); + //Set size to avoid automatic eliding + textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025)); + textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans"); + textEditor.SetProperty( TextEditor::Property::TEXT, "A"); + + const int numberOfCases = 6; + int arrayCases[numberOfCases] = {323, 326, 330, 600, 1630, 2500}; + + for (int index=0; index < numberOfCases; index++) + { + tet_printf(" UtcDaliTextEditorAtlasLimitationIsEnabledPerformanceCases point-size= %d \n", arrayCases[index]); + textEditor.SetProperty( TextEditor::Property::POINT_SIZE, arrayCases[index]) ; + application.GetScene().Add( textEditor ); + application.SendNotification(); + application.Render(); + naturalSize = textEditor.GetNaturalSize(); + DALI_TEST_GREATER( lessThanWidth, static_cast(naturalSize.width), TEST_LOCATION ); + DALI_TEST_GREATER( lessThanHeight, static_cast(naturalSize.height), TEST_LOCATION ); + + } + + END_TEST; +} + +int UtcDaliTextEditorHyphenWrapMode(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorHyphenWrapMode "); + + int lineCount =0; + TextEditor textEditor = TextEditor::New(); + + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 150.0f, 300.f ) ); + + application.GetScene().Add( textEditor ); + application.SendNotification(); + application.Render(); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hi Experimen" ); + textEditor.SetProperty(TextEditor::Property::LINE_WRAP_MODE, DevelText::LineWrap::HYPHENATION); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( TextEditor::Property::LINE_WRAP_MODE ), static_cast< int >( DevelText::LineWrap::HYPHENATION ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + lineCount = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + /* + text will be : + Hi Exp- + erimen + */ + DALI_TEST_EQUALS( lineCount, 2, TEST_LOCATION ); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hi Experimen" ); + textEditor.SetProperty(TextEditor::Property::LINE_WRAP_MODE, DevelText::LineWrap::MIXED); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( TextEditor::Property::LINE_WRAP_MODE ), static_cast< int >( DevelText::LineWrap::MIXED ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + lineCount = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + /* + text will be : + Hi + Experi- + men + */ + DALI_TEST_EQUALS( lineCount, 3, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliToolkitTextEditorEllipsisPositionProperty(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty "); + TextEditor textEditor = TextEditor::New(); + + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty - Default is END"); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty - Change to START"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::START); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty - Change to MIDDLE"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::MIDDLE); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty - Change to END"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::END); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty - Change to START using integer"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, 1); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty - Change to MIDDLE using integer"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, 2); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextEditorEllipsisPositionProperty - Change to END using integer"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, 0); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to START using string - uppercase"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, "START"); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to MIDDLE using string - uppercase"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, "MIDDLE"); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to END using string - uppercase"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, "END"); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to START using string - lowercase"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, "start"); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to MIDDLE using string - lowercase"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, "middle"); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION ); + + tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to END using string - lowercase"); + textEditor.SetProperty(DevelTextEditor::Property::ELLIPSIS_POSITION, "end"); + DALI_TEST_EQUALS( textEditor.GetProperty< int >( DevelTextEditor::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorCopyText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorCopyText "); + + TextEditor textEditor = TextEditor::New(); + + std::string selectedText = ""; + std::string copiedText = ""; + + application.GetScene().Add( textEditor ); + + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + // Hello is selected + DevelTextEditor::SelectText( textEditor, 0, 5 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 5, TEST_LOCATION ); + + // Hello is copied + copiedText = DevelTextEditor::CopyText( textEditor ); + DALI_TEST_EQUALS( "Hello", copiedText, TEST_LOCATION ); + + // world is selected + DevelTextEditor::SelectText( textEditor, 6, 11 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 6, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 11, TEST_LOCATION ); + + // world is copied + copiedText = DevelTextEditor::CopyText( textEditor ); + DALI_TEST_EQUALS( "world", copiedText, TEST_LOCATION ); + + // "lo wo" is selected + DevelTextEditor::SelectText( textEditor, 3, 8 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "lo wo", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 3, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 8, TEST_LOCATION ); + + // "lo wo" is copied + copiedText = DevelTextEditor::CopyText( textEditor ); + DALI_TEST_EQUALS( "lo wo", copiedText, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorCutText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorCutText "); + + TextEditor textEditor = TextEditor::New(); + + std::string selectedText = ""; + + application.GetScene().Add( textEditor ); + + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + // Hello is selected + DevelTextEditor::SelectText( textEditor, 0, 5 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 5, TEST_LOCATION ); + + // Hello is cut + DALI_TEST_EQUALS( "Hello", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), " world", TEST_LOCATION ); + + // " w" is selected + DevelTextEditor::SelectText( textEditor, 0, 2 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( " w", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 2, TEST_LOCATION ); + + // " w" is cut + DALI_TEST_EQUALS( " w", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "orld", TEST_LOCATION ); + + // Test Cut from the middle + + // "rl" is selected + DevelTextEditor::SelectText( textEditor, 1, 3 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "rl", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 3, TEST_LOCATION ); + + // "rl" is cut + DALI_TEST_EQUALS( "rl", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "od", TEST_LOCATION ); + + // Test Cut from the end + + // "d" is selected + DevelTextEditor::SelectText( textEditor, 1, 2 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "d", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 2, TEST_LOCATION ); + + // "d" is cut + DALI_TEST_EQUALS( "d", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "o", TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorPasteText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorPasteText "); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + std::string cutText = ""; + std::string copiedText = ""; + + editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworld\nHello world" ); + editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap on the text editor + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Move to second line of the text. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Select some text in the right of the current cursor position + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_SHIFT_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Cut the selected text + cutText = DevelTextEditor::CutText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "wor", cutText, TEST_LOCATION ); + DALI_TEST_EQUALS( "Hello\nld\nHello world", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + // Select some text in the left of the current cursor position + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_SHIFT_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "",DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Copy the selected text + copiedText = DevelTextEditor::CopyText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "lo\n", copiedText, TEST_LOCATION ); + DALI_TEST_EQUALS( "Hello\nld\nHello world", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + + // Move the cursor to the third line + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Paste the selected text at the current cursor position + DevelTextEditor::PasteText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "Hello\nld\nHello lo\nworld", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + END_TEST; +} +int UtcDaliTextEditorLineSpacing(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorLineSpacing "); + + TextEditor textEditor = TextEditor::New(); + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.f ) ); + application.GetScene().Add( textEditor ); + application.SendNotification(); + application.Render(); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Line #1\nLine #2\nLine #3" ); + textEditor.SetProperty( DevelTextEditor::Property::LINE_SPACING, 0 ); + + Vector3 sizeBefore = textEditor.GetNaturalSize(); + + textEditor.SetProperty( DevelTextEditor::Property::LINE_SPACING, 20 ); + + //add 20 for each line 20 * 3 + DALI_TEST_EQUALS(sizeBefore.height + 60.0f, textEditor.GetNaturalSize().height, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliTextEditorMinLineSize(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorMinLineSize "); + + TextEditor textEditor = TextEditor::New(); + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 400.0f, 400.f ) ); + application.GetScene().Add( textEditor ); + application.SendNotification(); + application.Render(); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Line #1\nLine #2\nLine #3" ); + textEditor.SetProperty( DevelTextEditor::Property::MIN_LINE_SIZE, 0 ); + + Vector3 sizeBefore = textEditor.GetNaturalSize(); + + textEditor.SetProperty( DevelTextEditor::Property::MIN_LINE_SIZE, 60 ); + + DALI_TEST_NOT_EQUALS( sizeBefore, textEditor.GetNaturalSize(), 0.0f, TEST_LOCATION); + + //60 * 3 lines + DALI_TEST_EQUALS(180.0f, textEditor.GetNaturalSize().height, TEST_LOCATION); + + END_TEST; +} + +int utcDaliTextEditorCursorPositionChangedSignal(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorCursorPositionChangedSignal"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + // connect to the selection changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextEditor::CursorPositionChangedSignal(editor).Connect(&TestCursorPositionChangedCallback); + bool cursorPositionChangedSignal = false; + editor.ConnectSignal( testTracker, "cursorPositionChanged", CallbackFunctor(&cursorPositionChangedSignal) ); + + editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworld\nHello world" ); + editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + editor.SetKeyInputFocus(); + + // Tap on the text editor + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled); + DALI_TEST_EQUALS(oldCursorPos, 23, TEST_LOCATION); + + gCursorPositionChangedCallbackCalled = false; + + // Move to left. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled); + DALI_TEST_EQUALS(oldCursorPos, 18, TEST_LOCATION); + + gCursorPositionChangedCallbackCalled = false; + + // Insert C + application.ProcessEvent( GenerateKey( "c", "", "c", KEY_C_CODE, 0, 0, Integration::KeyEvent::DOWN, "c", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled); + DALI_TEST_EQUALS(oldCursorPos, 17, TEST_LOCATION); + + gCursorPositionChangedCallbackCalled = false; + + //delete one character + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled); + DALI_TEST_EQUALS(oldCursorPos, 18, TEST_LOCATION); + + gCursorPositionChangedCallbackCalled = false; + + editor.SetProperty( TextEditor::Property::TEXT, "Hello" ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled); + DALI_TEST_EQUALS(oldCursorPos, 17, TEST_LOCATION); + + gCursorPositionChangedCallbackCalled = false; + + editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 3); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled); + DALI_TEST_EQUALS(oldCursorPos, 5, TEST_LOCATION); + + END_TEST; +} + +int utcDaliTextEditorGeometryEllipsisStart(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorGeometryEllipsisStart"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + editor.SetProperty( TextEditor::Property::POINT_SIZE, 7.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true ); + editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, false ); + editor.SetProperty( DevelTextEditor::Property::ELLIPSIS, true ); + editor.SetProperty( DevelTextEditor::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::START ); + editor.SetProperty( TextEditor::Property::TEXT, "line1 \nline2\nline 3\nline4" ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + unsigned int expectedCount = 2; + unsigned int startIndex = 0; + unsigned int endIndex = 24; + + Vector positionsList = DevelTextEditor::GetTextPosition(editor, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(editor, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(37, 0)); + expectedSizes.PushBack(Vector2(20, 25)); + + expectedPositions.PushBack(Vector2(-1, 25)); + expectedSizes.PushBack(Vector2(52, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + +int utcDaliTextEditorGeometryEllipsisMiddle(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorGeometryEllipsisMiddle"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + editor.SetProperty( TextEditor::Property::POINT_SIZE, 7.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true ); + editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, false ); + editor.SetProperty( DevelTextEditor::Property::ELLIPSIS, true ); + editor.SetProperty( DevelTextEditor::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::MIDDLE ); + editor.SetProperty( TextEditor::Property::TEXT, "line1 \nline2\nline 3\nline4" ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + unsigned int expectedCount = 2; + unsigned int startIndex = 0; + unsigned int endIndex = 24; + + Vector positionsList = DevelTextEditor::GetTextPosition(editor, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(editor, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(-1, 0)); + expectedSizes.PushBack(Vector2(25, 25)); + + expectedPositions.PushBack(Vector2(-1, 25)); + expectedSizes.PushBack(Vector2(52, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + +int utcDaliTextEditorGeometryEllipsisEnd(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorGeometryEllipsisEnd"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + editor.SetProperty( TextEditor::Property::POINT_SIZE, 7.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true ); + editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, false ); + editor.SetProperty( DevelTextEditor::Property::ELLIPSIS, true ); + editor.SetProperty( DevelTextEditor::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::END ); + editor.SetProperty( TextEditor::Property::TEXT, "line1 \nline2\nline 3\nline4" ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + unsigned int expectedCount = 2; + unsigned int startIndex = 0; + unsigned int endIndex = 24; + + Vector positionsList = DevelTextEditor::GetTextPosition(editor, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(editor, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(-1, 0)); + expectedSizes.PushBack(Vector2(59, 25)); + + expectedPositions.PushBack(Vector2(-1, 25)); + expectedSizes.PushBack(Vector2(25, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + +int utcDaliTextEditorGeometryRTL(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorGeometryRTL"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + editor.SetProperty( TextEditor::Property::POINT_SIZE, 7.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true ); + editor.SetProperty( TextEditor::Property::TEXT, "line1 \nline2\nline 3\nالاخيرالسطر" ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + unsigned int expectedCount = 4; + unsigned int startIndex = 3; + unsigned int endIndex = 24; + + Vector positionsList = DevelTextEditor::GetTextPosition(editor, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(editor, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(24, 0)); + expectedSizes.PushBack(Vector2(33, 25)); + + expectedPositions.PushBack(Vector2(-1, 25)); + expectedSizes.PushBack(Vector2(52, 25)); + + expectedPositions.PushBack(Vector2(-1, 50)); + expectedSizes.PushBack(Vector2(59, 25)); + + expectedPositions.PushBack(Vector2(61, 75)); + expectedSizes.PushBack(Vector2(37, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + +int utcDaliTextEditorGeometryGlyphMiddle(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorGeometryGlyphMiddle"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + editor.SetProperty( TextEditor::Property::POINT_SIZE, 7.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 150.f, 200.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true ); + editor.SetProperty( TextEditor::Property::TEXT, "لا تحتوي على لا" ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + unsigned int expectedCount = 1; + unsigned int startIndex = 1; + unsigned int endIndex = 13; + + Vector positionsList = DevelTextEditor::GetTextPosition(editor, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(editor, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(6, 0)); + expectedSizes.PushBack(Vector2(124, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + +int utcDaliTextEditorSelectionClearedSignal(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorSelectionClearedSignal"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + // connect to the selection changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextEditor::SelectionClearedSignal(editor).Connect(&TestSelectionClearedCallback); + bool selectionClearedSignal = false; + editor.ConnectSignal( testTracker, "selectionCleared", CallbackFunctor(&selectionClearedSignal) ); + + editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworld\nHello world" ); + editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap on the text editor + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Move to second line of the text & Select some text in the right of the current cursor position + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // remove selection + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionClearedCallbackCalled); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap on the text editor + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + gSelectionClearedCallbackCalled = false; + + // Move to second line of the text & select. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + //remove selection + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionClearedCallbackCalled); + + gSelectionClearedCallbackCalled = false; + + // Render and notify + application.SendNotification(); + application.Render(); + + // Move to second line of the text & select. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // replace C with selected text + application.ProcessEvent( GenerateKey( "c", "", "c", KEY_C_CODE, 0, 0, Integration::KeyEvent::DOWN, "c", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionClearedCallbackCalled); + + gSelectionClearedCallbackCalled = false; + + // Render and notify + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectText( editor ,1, 3 ); + + // Render and notify + application.SendNotification(); + application.Render(); + + editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 3); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionClearedCallbackCalled); + + gSelectionClearedCallbackCalled = false; + + DevelTextEditor::SelectText( editor ,1, 3 ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // select none + DevelTextEditor::SelectNone(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionClearedCallbackCalled); + + END_TEST; +} + +int utcDaliTextEditorSelectionChangedSignal(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorSelectionChangedSignal"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + // connect to the selection changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextEditor::SelectionChangedSignal(editor).Connect(&TestSelectionChangedCallback); + bool selectionChangedSignal = false; + editor.ConnectSignal( testTracker, "selectionChanged", CallbackFunctor(&selectionChangedSignal) ); + + editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworld\nHello world" ); + editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap on the text editor + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Move to second line of the text. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Select some text in the right of the current cursor position + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_SHIFT_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + DALI_TEST_EQUALS(oldSelectionStart, oldSelectionEnd, TEST_LOCATION); + + gSelectionChangedCallbackCalled = false; + + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + DALI_TEST_EQUALS(oldSelectionStart, 6, TEST_LOCATION); + DALI_TEST_EQUALS(oldSelectionEnd, 7, TEST_LOCATION); + + gSelectionChangedCallbackCalled = false; + + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + DALI_TEST_EQUALS(oldSelectionStart, 6, TEST_LOCATION); + DALI_TEST_EQUALS(oldSelectionEnd, 8, TEST_LOCATION); + + gSelectionChangedCallbackCalled = false; + editor.SetKeyInputFocus(); + + // Render and notify + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectText( editor ,0, 5 ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + DALI_TEST_EQUALS(oldSelectionStart, oldSelectionEnd, TEST_LOCATION); + + gSelectionChangedCallbackCalled = false; + + editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 3); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + DALI_TEST_EQUALS(oldSelectionStart, 0, TEST_LOCATION); + DALI_TEST_EQUALS(oldSelectionEnd, 5, TEST_LOCATION); + + gSelectionChangedCallbackCalled = false; + + // select all text + DevelTextEditor::SelectWholeText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + DALI_TEST_EQUALS(oldSelectionStart, oldSelectionEnd, TEST_LOCATION); + + gSelectionChangedCallbackCalled = false; + + // select none + DevelTextEditor::SelectNone(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + DALI_TEST_EQUALS(oldSelectionStart, 0, TEST_LOCATION); + DALI_TEST_EQUALS(oldSelectionEnd, 23, TEST_LOCATION); + + END_TEST; +} + + +int utcDaliTextEditorInsertCharacterAfterInitWithResizePolicyNaturalSize(void) +{ + + //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE + //DaliException on vector: "Iterator not inside vector" + + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorInsertCharacterAfterInitWithResizePolicyNaturalSize"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + //Set multilines text + editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World"); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + //Set ResizePolicy to NaturalSize + editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Create a tap event to touch the text editor. + TestGenerateTap( application, 5.0f, 5.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Set currsor and add character (in first line) + editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 5); + application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::UP, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + //Check the changed text and cursor position + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get(), "Hellod \n World", TEST_LOCATION ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get(), 6, TEST_LOCATION ); + + // Render and notify + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int utcDaliTextEditorRemoveCharacterAfterInitWithResizePolicyNaturalSize(void) +{ + + //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE + //DaliException on vector: "Iterator not inside vector" + + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorRemoveCharacterAfterInitWithResizePolicyNaturalSize"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + //Set multilines text + editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World"); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + //Set ResizePolicy to NaturalSize + editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + + // Set currsor + editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 5); + application.SendNotification(); + application.Render(); + + // Set focus and remove character + editor.SetKeyInputFocus(); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + //Check the changed text and cursor position + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get(), "Hell \n World", TEST_LOCATION ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get(), 4, TEST_LOCATION ); + + // Render and notify + application.SendNotification(); + application.Render(); + + END_TEST; +} + +int utcDaliTextEditorCutSelectedTextAfterInitWithResizePolicyNaturalSize(void) +{ + + //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE + //DaliException on vector: "Iterator not inside vector" + + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorCutSelectedTextAfterInitWithResizePolicyNaturalSize"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + //Set multilines text + editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World"); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + //Set ResizePolicy to NaturalSize + editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + + //Select text at initialization (before the first render) + DevelTextEditor::SelectText( editor ,3, 5 ); + + // Render and notify + application.SendNotification(); + application.Render(); + + //Cut text + application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_CONTROL_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "x", "x", "x", KEY_X_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "x", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + //Check the changed text and cursor position + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get(), "Hel \n World", TEST_LOCATION ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get(), 3, TEST_LOCATION ); + + // Render and notify + application.SendNotification(); + application.Render(); + + END_TEST; +} + + +int utcDaliTextEditorDoubleEnterAfterInitWithResizePolicyNaturalSize(void) +{ + + //This is to test a crash when used Resize Policy equals USE_NATURAL_SIZE + //DaliException on vector: "Iterator not inside vector" + + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorDoubleEnterAfterInitWithResizePolicyNaturalSize"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + //Set multilines text + editor.SetProperty(Dali::Toolkit::TextEditor::Property::TEXT, "Hello \n World"); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + //Set ResizePolicy to NaturalSize + editor.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::USE_NATURAL_SIZE); + + // Set currsor + editor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 5); + application.SendNotification(); + application.Render(); + + // Set focus and double enter (new line) + editor.SetKeyInputFocus(); + application.ProcessEvent(GenerateKey("Enter", "", "\n", 13, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + application.ProcessEvent(GenerateKey("Enter", "", "\n", 13, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE)); + + // Render and notify + application.SendNotification(); + application.Render(); + + //Check the changed text and cursor position + DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::TEXT ).Get(), "Hello\n\n \n World", TEST_LOCATION ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get(), 7, TEST_LOCATION ); + + // Render and notify + application.SendNotification(); + application.Render(); + + END_TEST; } \ No newline at end of file