bef3f33ef1daf1dffc14b47b507f68998687eb4a
[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 int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void)
113 {
114   ToolkitTestApplication application;
115   tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlas ");
116
117   // Create a text editor
118   TextEditor textEditor = TextEditor::New();
119   //Set size to avoid automatic eliding
120   textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
121   //Set very large font-size using point-size
122   textEditor.SetProperty( TextEditor::Property::POINT_SIZE, 1000);
123   //Specify font-family
124   textEditor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVu Sans");
125   //Set text to check if appear or not
126   textEditor.SetProperty(TextEditor::Property::TEXT, "A");
127
128   application.GetScene().Add( textEditor );
129
130   application.SendNotification();
131   application.Render();
132
133   //Check if Glyph is added to AtlasGlyphManger or not
134   int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
135   DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
136
137   END_TEST;
138 }
139
140
141 int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void)
142 {
143   ToolkitTestApplication application;
144   tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase ");
145
146   //Set Map of placeholder: text, font-family and point-size
147   Property::Map placeholderMapSet;
148   placeholderMapSet["text"] = "A";
149   placeholderMapSet["fontFamily"] = "DejaVu Sans";
150   placeholderMapSet["pixelSize"] = 1000.0f;
151
152   // Create a text editor
153   TextEditor textEditor = TextEditor::New();
154   //Set size to avoid automatic eliding
155   textEditor.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
156   //Set placeholder
157   textEditor.SetProperty( TextEditor::Property::PLACEHOLDER, placeholderMapSet) ;
158
159   application.GetScene().Add( textEditor );
160
161   application.SendNotification();
162   application.Render();
163
164   //Check if Glyph is added to AtlasGlyphManger or not
165   int countAtlas = AtlasGlyphManager::Get().GetMetrics().mAtlasMetrics.mAtlasCount;
166   DALI_TEST_EQUALS( countAtlas, 1, TEST_LOCATION );
167
168   END_TEST;
169 }