X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Futc-Dali-TextEditor.cpp;h=4e9890c999588db791f8ad6b85908c6f8e089779;hb=48000ec3ab1ca2d1f8001d192112e32357bb1dfc;hp=0d0b8bc44cc3ec08161e1028e47c4364e536e05a;hpb=17655f69059d8b9f766f350501b3f1ba5efb7231;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 0d0b8bc..4e9890c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -29,6 +29,7 @@ #include #include #include +#include "test-text-geometry-utils.h" using namespace Dali; using namespace Toolkit; @@ -136,6 +137,7 @@ 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; @@ -161,6 +163,13 @@ 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"); @@ -4447,6 +4456,439 @@ int utcDaliTextEditorCursorPositionChangedSignal(void) 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 utcDaliTextEditorSelectionWithSecondaryCursor(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorSelectionWithSecondaryCursor"); + + // Checks if the actor is created. + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true ); + editor.SetProperty( TextEditor::Property::TEXT, "اللغة العربية\nمرحبا بالجميع\nالسلام عليكم Hello world" ); + editor.SetProperty( TextEditor::Property::POINT_SIZE, 12.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( DevelTextEditor::Property::MIN_LINE_SIZE, 50.f ); + editor.SetProperty( DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, false ); + + // 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(); + + //Select the last Arabic word (RTL) & some the space before the English (LTR) letters. + DevelTextEditor::SelectText( editor, 35, 41 );// This will activate the alternative cursor position and thus 'cursorInfo.isSecondaryCursor' will be true. + + application.SendNotification(); + application.Render(); + + std::string selectedText = editor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "عليكم ", selectedText, TEST_LOCATION ); + + END_TEST; +} + int utcDaliTextEditorSelectionChangedSignal(void) { ToolkitTestApplication application; @@ -4578,4 +5020,212 @@ int utcDaliTextEditorSelectionChangedSignal(void) 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