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=e74ccf4bbd254685dc6ccf281c05ded9e649841a;hp=6bf3ef900392fdd87fa5d8fb0a3f18fc2a47244b;hb=c570552b94d9532440de9440b845c4fc06f8d411;hpb=517dab63fca9d69d49a68c8763fe477f53cc6d5f diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 6bf3ef9..e74ccf4 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -102,6 +102,7 @@ const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION = "enableSh const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE = "enableGrabHandle"; const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION = "matchSystemLanguageDirection"; const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength"; +const char* const PROPERTY_NAME_FONT_SIZE_SCALE = "fontSizeScale"; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); @@ -487,6 +488,7 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_COUNT) == TextEditor::Property::LINE_COUNT ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == TextEditor::Property::ENABLE_SELECTION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextEditor::Property::PLACEHOLDER ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_SIZE_SCALE ) == DevelTextEditor::Property::FONT_SIZE_SCALE ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == DevelTextEditor::Property::PLACEHOLDER_TEXT ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == DevelTextEditor::Property::PLACEHOLDER_TEXT_COLOR ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextEditor::Property::ENABLE_SHIFT_SELECTION ); @@ -494,6 +496,7 @@ 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 ); + END_TEST; } @@ -558,6 +561,10 @@ int UtcDaliTextEditorSetPropertyP(void) editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f ); DALI_TEST_EQUALS( editor.GetProperty( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + editor.SetProperty( DevelTextEditor::Property::FONT_SIZE_SCALE, 2.5f ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::FONT_SIZE_SCALE ), 2.5f, Math::MACHINE_EPSILON_1000, TEST_LOCATION ); + editor.SetProperty( DevelTextEditor::Property::FONT_SIZE_SCALE, 1.0f ); + // Reset font style. fontStyleMapSet.Clear(); fontStyleMapSet.Insert( "weight", "normal" ); @@ -968,6 +975,19 @@ int utcDaliTextEditorTextChangedP(void) application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); DALI_TEST_CHECK( gTextChangedCallBackCalled ); + // Remove all text + editor.SetProperty( TextField::Property::TEXT, "" ); + + // Pressing backspace key: TextChangedCallback should not be called when there is no text in texteditor. + gTextChangedCallBackCalled = false; + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + DALI_TEST_CHECK( !gTextChangedCallBackCalled ); + + // Pressing delete key: TextChangedCallback should not be called when there is no text in texteditor. + gTextChangedCallBackCalled = false; + application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + DALI_TEST_CHECK( !gTextChangedCallBackCalled ); + END_TEST; } @@ -2172,6 +2192,54 @@ int utcDaliTextEditorEvent07(void) //text is "c" DALI_TEST_EQUALS( "c", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + // select all text + DevelTextEditor::SelectWholeText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Copy the selected text using logical keys + 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( "ؤ", "c", "ؤ", KEY_C_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "c", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // select none + DevelTextEditor::SelectNone(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Paste the selected using logical keys + 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( "ر", "v", "ر", KEY_V_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "v", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + //text is "cc" + DALI_TEST_EQUALS( "cc", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + // select all using logical keys + 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( "ش", "a", "ش", KEY_A_CODE, KEY_CONTROL_MODIFIER, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // cut text using logical keys + 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", "ء", 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(); + + //text is "" + DALI_TEST_EQUALS( "", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + END_TEST; } @@ -2861,6 +2929,107 @@ int utcDaliTextEditorMaxCharactersReached(void) END_TEST; } +int UtcDaliTextEditorSelectWholeText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorSelectWholeText "); + + 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(); + + DALI_TEST_EQUALS( 1u, textEditor.GetChildCount(), TEST_LOCATION ); + + DevelTextEditor::SelectWholeText( textEditor ); + + application.SendNotification(); + application.Render(); + + // Nothing should have been selected. The number of children is still 1 + DALI_TEST_EQUALS( 1u, textEditor.GetChildCount(), TEST_LOCATION ); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectWholeText( textEditor ); + + application.SendNotification(); + application.Render(); + + // Should be 2 children, the stencil and the layer + DALI_TEST_EQUALS( 2u, textEditor.GetChildCount(), TEST_LOCATION ); + + // The offscreen root actor should have two actors: the renderer and the highlight actor. + Actor stencil = textEditor.GetChildAt( 0u ); + + // The highlight actor is drawn first, so is the first actor in the list + Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u ); + DALI_TEST_CHECK( highlight ); + + END_TEST; +} + +int UtcDaliTextEditorSelectNone(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorSelectWholeText "); + + 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(); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + // Nothing is selected + std::string selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION ); + + DevelTextEditor::SelectWholeText( textEditor ); + + application.SendNotification(); + application.Render(); + + // whole text is selected + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello world", selectedText, TEST_LOCATION ); + + DevelTextEditor::SelectNone( textEditor ); + + application.SendNotification(); + application.Render(); + + // Nothing is selected + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliTextEditorSelectRange(void) { ToolkitTestApplication application; @@ -2882,8 +3051,201 @@ int UtcDaliTextEditorSelectRange(void) textEditor.SetProperty( DevelTextEditor::Property::SELECTED_TEXT_START, 0 ); textEditor.SetProperty( DevelTextEditor::Property::SELECTED_TEXT_END, 5 ); + // Hello is selected + std::string 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 ); END_TEST; -} \ No newline at end of file +} + +int UtcDaliTextEditorEnableEditing(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorEnableEditing "); + + 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(); + + textEditor.SetKeyInputFocus(); + textEditor.SetProperty( DevelTextEditor::Property::ENABLE_EDITING, false ); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "", TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::ENABLE_EDITING ).Get(), false, TEST_LOCATION ); + + textEditor.SetKeyInputFocus(); + textEditor.SetProperty( DevelTextEditor::Property::ENABLE_EDITING, true ); + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "D", TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::ENABLE_EDITING ).Get(), true, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorScrolling(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorScrolling "); + + TextEditor textEditor = TextEditor::New(); + DALI_TEST_CHECK( textEditor ); + + application.GetScene().Add( textEditor ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + textEditor.SetProperty(TextEditor::Property::TEXT, "Tex1\nTex2\nTex3\nTex4\nTex5\nTex6\nTex7\nTex8"); + textEditor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER); + textEditor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER); + textEditor.SetProperty(Actor::Property::SIZE, Vector2(60.0f, 160.0f)); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + + DevelTextEditor::ScrollBy(textEditor, Vector2(1.0f, 1.0f)); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 1.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + DevelTextEditor::ScrollBy(textEditor, Vector2(0.0f, 1000.0f)); + + DALI_TEST_NOT_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 1.0f, 0.1f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + textEditor.SetProperty(DevelTextEditor::Property::VERTICAL_SCROLL_POSITION , 0.0f); + textEditor.SetProperty(DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION , 0.0f); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get(), 0.0f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliToolkitTextEditorFontSizeScale(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliToolkitTextEditorFontSizeScale"); + + TextEditor textEditor = TextEditor::New(); + textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 30.f ); + textEditor.SetProperty( TextEditor::Property::TEXT, "Test" ); + Vector3 nonScaledSize = textEditor.GetNaturalSize(); + + TextEditor textEditorScaled = TextEditor::New(); + textEditorScaled.SetProperty( TextEditor::Property::POINT_SIZE, 15.f ); + textEditorScaled.SetProperty( Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE, 2.f ); + textEditorScaled.SetProperty( TextEditor::Property::TEXT, "Test" ); + Vector3 scaledSize = textEditorScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + textEditor.SetProperty( TextEditor::Property::PIXEL_SIZE, 30.f ); + textEditor.SetProperty( TextEditor::Property::TEXT, "Test" ); + nonScaledSize = textEditor.GetNaturalSize(); + + textEditorScaled.SetProperty( TextEditor::Property::PIXEL_SIZE, 15.f ); + textEditorScaled.SetProperty( Toolkit::DevelTextEditor::Property::FONT_SIZE_SCALE, 2.f ); + textEditorScaled.SetProperty( TextEditor::Property::TEXT, "Test" ); + scaledSize = textEditorScaled.GetNaturalSize(); + + DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorPrimaryCursorPosition(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextPrimaryCursorPosition "); + + TextEditor textEditor = TextEditor::New(); + + application.GetScene().Add( textEditor ); + + textEditor.SetProperty( TextEditor::Property::TEXT, "ABCEF"); + 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 ); + + textEditor.SetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION, 3); + application.SendNotification(); + application.Render(); + + application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "ABCDEF", TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::PRIMARY_CURSOR_POSITION ).Get(), 4, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorLineCountAfterGetNaturalSize(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorLineCountAfterGetNaturalSize "); + + TextEditor textEditor = TextEditor::New(); + textEditor.SetProperty(TextEditor::Property::TEXT, "A\nB\nC\nD\nE\nF\n"); + 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 ); + application.GetScene().Add( textEditor ); + + application.SendNotification(); + application.Render(); + + int lineCount = 0; + lineCount = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 7, TEST_LOCATION ); + + textEditor.GetNaturalSize(); + + // Create a tap event to touch the text editor. + TestGenerateTap( application, 18.0f, 25.0f ); + + application.SendNotification(); + application.Render(); + + lineCount = textEditor.GetProperty( TextEditor::Property::LINE_COUNT ); + DALI_TEST_EQUALS( lineCount, 7, TEST_LOCATION ); + + END_TEST; +}