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/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>
30 using namespace Toolkit;
33 int UtcDaliTextEditorSelectText(void)
35 ToolkitTestApplication application;
36 tet_infoline( "UtcDaliTextEditorSelectText" );
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" );
43 // Add the text editor to the stage
44 application.GetScene().Add( textEditor );
46 application.SendNotification();
49 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
51 application.SendNotification();
54 // Highlight the whole text
55 textEditorImpl.SelectWholeText();
57 application.SendNotification();
60 std::string selectedText = textEditorImpl.GetSelectedText();
61 DALI_TEST_CHECK( selectedText == "Hello World" );
64 textEditorImpl.SelectNone();
66 application.SendNotification();
69 selectedText = textEditorImpl.GetSelectedText();
70 DALI_TEST_CHECK( selectedText == "" );
75 int UtcDaliTextEditorMarkupUnderline(void)
77 ToolkitTestApplication application;
78 tet_infoline(" UtcDaliTextEditorMarkupUnderline ");
80 TextEditor textEditor = TextEditor::New();
82 application.GetScene().Add( textEditor );
84 textEditor.SetProperty( TextEditor::Property::TEXT, "<u>ABC</u>EF<u>GH</u>" );
85 textEditor.SetProperty( TextEditor ::Property::ENABLE_MARKUP, true );
87 application.SendNotification();
90 uint32_t expectedNumberOfUnderlinedGlyphs = 5u;
92 Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor );
93 const Text::Length numberOfUnderlineRuns = textEditorImpl.getController()->GetTextModel()->GetNumberOfUnderlineRuns();
95 DALI_TEST_EQUALS( numberOfUnderlineRuns, expectedNumberOfUnderlinedGlyphs, TEST_LOCATION );
97 Vector<GlyphRun> underlineRuns;
98 underlineRuns.Resize(numberOfUnderlineRuns);
99 textEditorImpl.getController()->GetTextModel()->GetUnderlineRuns(underlineRuns.Begin(), 0u, numberOfUnderlineRuns);
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);
107 DALI_TEST_EQUALS( underlineRuns[3u].glyphIndex, 5u, TEST_LOCATION);
108 DALI_TEST_EQUALS( underlineRuns[4u].glyphIndex, 6u, TEST_LOCATION);
113 int UtcDaliTextEditorFontPointSizeLargerThanAtlas(void)
115 ToolkitTestApplication application;
116 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlas ");
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");
129 application.GetScene().Add( textEditor );
131 application.SendNotification();
132 application.Render();
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 );
142 int UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase(void)
144 ToolkitTestApplication application;
145 tet_infoline(" UtcDaliTextEditorFontPointSizeLargerThanAtlasPlaceholderCase ");
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;
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));
158 textEditor.SetProperty( TextEditor::Property::PLACEHOLDER, placeholderMapSet) ;
160 application.GetScene().Add( textEditor );
162 application.SendNotification();
163 application.Render();
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 );