2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/internal/controls/text-controls/text-editor-impl.h>
25 #include <dali-toolkit/internal/text/text-controller.h>
26 #include <dali-toolkit/internal/text/text-controller-impl.h>
29 using namespace Toolkit;
32 int UtcDaliTextEditorSelectText(void)
34 ToolkitTestApplication application;
35 tet_infoline( "UtcDaliTextEditorSelectText" );
37 // Create a text editor
38 TextEditor textEditor = TextEditor::New();
39 textEditor.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
40 textEditor.SetProperty( TextEditor::Property::TEXT, "Hello World" );
42 // Add the text editor to the stage
43 application.GetScene().Add( textEditor );
45 application.SendNotification();
48 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
50 application.SendNotification();
53 // Highlight the whole text
54 textEditorImpl.SelectWholeText();
56 application.SendNotification();
59 std::string selectedText = textEditorImpl.GetSelectedText();
60 DALI_TEST_CHECK( selectedText == "Hello World" );
63 textEditorImpl.SelectNone();
65 application.SendNotification();
68 selectedText = textEditorImpl.GetSelectedText();
69 DALI_TEST_CHECK( selectedText == "" );
74 int UtcDaliTextEditorMarkupUnderline(void)
76 ToolkitTestApplication application;
77 tet_infoline(" UtcDaliTextEditorMarkupUnderline ");
79 TextEditor textEditor = TextEditor::New();
81 application.GetScene().Add( textEditor );
83 textEditor.SetProperty( TextEditor::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
84 textEditor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true );
86 application.SendNotification();
89 uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
91 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
92 const Text::Length numberOfUnderlineRuns = textEditorImpl.getController()->GetTextModel()->GetNumberOfUnderlineRuns();
94 DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
96 Vector<GlyphRun> underlineRuns;
97 underlineRuns.Resize(numberOfUnderlineRuns);
98 textEditorImpl.getController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
101 DALI_TEST_EQUALS( underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION);
102 DALI_TEST_EQUALS( underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION);
103 DALI_TEST_EQUALS( underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION);
106 DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
107 DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);