Merge "Support Underline to Markup using underlined-character-run" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-TextEditor-internal.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23
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>
27
28 using namespace Dali;
29 using namespace Toolkit;
30 using namespace Text;
31
32 int UtcDaliTextEditorSelectText(void)
33 {
34   ToolkitTestApplication application;
35   tet_infoline( "UtcDaliTextEditorSelectText" );
36
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" );
41
42   // Add the text editor to the stage
43   application.GetScene().Add( textEditor );
44
45   application.SendNotification();
46   application.Render();
47
48   Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
49
50   application.SendNotification();
51   application.Render();
52
53   // Highlight the whole text
54   textEditorImpl.SelectWholeText();
55
56   application.SendNotification();
57   application.Render();
58
59   std::string selectedText = textEditorImpl.GetSelectedText();
60   DALI_TEST_CHECK( selectedText == "Hello World" );
61
62   // Select None
63   textEditorImpl.SelectNone();
64
65   application.SendNotification();
66   application.Render();
67
68   selectedText = textEditorImpl.GetSelectedText();
69   DALI_TEST_CHECK( selectedText == "" );
70
71   END_TEST;
72 }
73
74 int UtcDaliTextEditorMarkupUnderline(void)
75 {
76   ToolkitTestApplication application;
77   tet_infoline(" UtcDaliTextEditorMarkupUnderline ");
78
79   TextEditor textEditor = TextEditor::New();
80
81   application.GetScene().Add( textEditor );
82
83   textEditor.SetProperty( TextEditor::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
84   textEditor.SetProperty( TextEditor ::Property::ENABLE_MARKUP,  true );
85
86   application.SendNotification();
87   application.Render();
88
89   uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
90
91   Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
92   const Text::Length numberOfUnderlineRuns = textEditorImpl.getController()->GetTextModel()->GetNumberOfUnderlineRuns();
93
94   DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
95
96   Vector<GlyphRun> underlineRuns;
97   underlineRuns.Resize(numberOfUnderlineRuns);
98   textEditorImpl.getController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
99
100   //ABC are underlined
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);
104
105   //GH are underlined
106   DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
107   DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
108
109   END_TEST;
110
111 }