b19d653ca32d4a5995e7777b60085a10868bf7a5
[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/text/rendering/atlas/atlas-glyph-manager.h>
25 #include <dali-toolkit/internal/controls/text-controls/text-editor-impl.h>
26 #include <dali-toolkit/internal/text/text-controller.h>
27 #include <dali-toolkit/internal/text/text-controller-impl.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31 using namespace Text;
32
33 int UtcDaliTextEditorSelectText(void)
34 {
35   ToolkitTestApplication application;
36   tet_infoline( "UtcDaliTextEditorSelectText" );
37
38   // Create a text editor
39   TextEditor textEditor = TextEditor::New();
40   textEditor.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
41   textEditor.SetProperty( TextEditor::Property::TEXT, "Hello World" );
42
43   // Add the text editor to the stage
44   application.GetScene().Add( textEditor );
45
46   application.SendNotification();
47   application.Render();
48
49   Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
50
51   application.SendNotification();
52   application.Render();
53
54   // Highlight the whole text
55   textEditorImpl.SelectWholeText();
56
57   application.SendNotification();
58   application.Render();
59
60   std::string selectedText = textEditorImpl.GetSelectedText();
61   DALI_TEST_CHECK( selectedText == "Hello World" );
62
63   // Select None
64   textEditorImpl.SelectNone();
65
66   application.SendNotification();
67   application.Render();
68
69   selectedText = textEditorImpl.GetSelectedText();
70   DALI_TEST_CHECK( selectedText == "" );
71
72   END_TEST;
73 }
74
75 int UtcDaliTextEditorMarkupUnderline(void)
76 {
77   ToolkitTestApplication application;
78   tet_infoline(" UtcDaliTextEditorMarkupUnderline ");
79
80   TextEditor textEditor = TextEditor::New();
81
82   application.GetScene().Add( textEditor );
83
84   textEditor.SetProperty( TextEditor::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
85   textEditor.SetProperty( TextEditor ::Property::ENABLE_MARKUP,  true );
86
87   application.SendNotification();
88   application.Render();
89
90   uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
91
92   Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
93   const Text::Length numberOfUnderlineRuns = textEditorImpl.getController()->GetTextModel()->GetNumberOfUnderlineRuns();
94
95   DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
96
97   Vector<GlyphRun> underlineRuns;
98   underlineRuns.Resize(numberOfUnderlineRuns);
99   textEditorImpl.getController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
100
101   //ABC are underlined
102   DALI_TEST_EQUALS( underlineRuns[0u].glyphIndex, 0u, TEST_LOCATION);
103   DALI_TEST_EQUALS( underlineRuns[1u].glyphIndex, 1u, TEST_LOCATION);
104   DALI_TEST_EQUALS( underlineRuns[2u].glyphIndex, 2u, TEST_LOCATION);
105
106   //GH are underlined
107   DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
108   DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
109
110   END_TEST;
111 }
112
113 int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void)
114 {
115   ToolkitTestApplication application;
116   tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlas ");
117
118   // Create a text editor
119   TextEditor textEditor = TextEditor::New();
120   //Set size to avoid automatic eliding
121   textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
122   //Set very large font-size using point-size
123   textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 1000);
124   //Specify font-family
125   textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans");
126   //Set text to check if appear or not
127   textEditor.SetProperty(TextEditor::Property::TEXT, "A");
128
129   application.GetScene().Add( textEditor );
130
131   application.SendNotification();
132   application.Render();
133
134   //Check if Glyph is added to AtlasGlyphManger or not
135   int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
136   DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
137
138   END_TEST;
139 }
140
141
142 int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void)
143 {
144   ToolkitTestApplication application;
145   tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase ");
146
147   //Set Map of placeholder: text, font-family and point-size
148   Property::Map placeholderMapSet;
149   placeholderMapSet["text"] = "A";
150   placeholderMapSet["fontFamily"] = "DejaVu Sans";
151   placeholderMapSet["pixelSize"] = 1000.0f;
152
153   // Create a text editor
154   TextEditor textEditor = TextEditor::New();
155   //Set size to avoid automatic eliding
156   textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
157   //Set placeholder
158   textEditor.SetProperty( TextEditor::Property::PLACEHOLDER, placeholderMapSet) ;
159
160   application.GetScene().Add( textEditor );
161
162   application.SendNotification();
163   application.Render();
164
165   //Check if Glyph is added to AtlasGlyphManger or not
166   int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
167   DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
168
169   END_TEST;
170 }