2 * Copyright (c) 2014 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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali/integration-api/events/key-event-integ.h>
25 using namespace Toolkit;
28 int UtcDaliTextInputSetActiveStyle(void)
30 ToolkitTestApplication application;
32 tet_infoline("Testing Setting of Style to newly added text");
34 TextInput textInput = TextInput::New(); // create empty TextInput
36 Stage::GetCurrent().Add(textInput);
38 const std::string styledString = "Test String<i>ab</i>" ;
39 const std::string plainString = "Test String";
40 textInput.SetInitialText( plainString );
42 application.SendNotification();
45 textInput.SetEditable(true);
47 std::string retreivedMarkupString = textInput.GetMarkupText();
49 tet_infoline("Confirm markup text is a plain string ");
50 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
53 style.SetItalics( true );
55 tet_infoline("Apply style to TextInput");
56 textInput.SetActiveStyle( style );
58 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
59 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
61 application.SendNotification();
64 application.ProcessEvent(eventA);
65 application.SendNotification();
68 application.ProcessEvent(eventB);
69 application.SendNotification();
72 retreivedMarkupString = textInput.GetMarkupText();
74 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
78 int UtcDaliTextInputApplyStyleToSelectedText(void)
80 ToolkitTestApplication application;
82 tet_infoline("Testing application of style to selected text ");
84 TextInput textInput = TextInput::New(); // create empty TextInput
86 Stage::GetCurrent().Add(textInput);
88 const std::string styledString = "Test <i>String</i> to style";
89 const std::string plainString = "Test String to style";
90 textInput.SetInitialText( plainString );
92 application.SendNotification();
95 textInput.SetEditable(true);
97 std::string retreivedMarkupString = textInput.GetMarkupText();
99 tet_infoline("Confirm markup text is a plain string ");
100 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
103 style.SetItalics( true );
105 textInput.SelectText( 5, 11 );
107 tet_infoline("Apply style to selected text");
108 textInput.ApplyStyle( style );
110 application.Render();
112 retreivedMarkupString = textInput.GetMarkupText();
114 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
118 int UtcDaliTextInputApplyStyleToAll(void)
120 ToolkitTestApplication application;
122 tet_infoline("Testing application of style to all text ");
124 TextInput textInput = TextInput::New(); // create empty TextInput
126 Stage::GetCurrent().Add(textInput);
128 const std::string styledString = "<i>Test String to style</i>";
129 const std::string plainString = "Test String to style";
130 textInput.SetInitialText( plainString );
132 application.SendNotification();
133 application.Render();
135 textInput.SetEditable(true);
137 std::string retreivedMarkupString = textInput.GetMarkupText();
139 tet_infoline("Confirm markup text is a plain string ");
140 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
143 style.SetItalics( true );
145 tet_infoline("Apply style to all text");
146 textInput.ApplyStyleToAll( style );
148 application.Render();
150 retreivedMarkupString = textInput.GetMarkupText();
152 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
156 int UtcDaliTextInputGetStyleAtCursor(void)
158 ToolkitTestApplication application;
160 tet_infoline("Test getting style at cursor");
162 TextInput textInput = TextInput::New(); // create empty TextInput
164 Stage::GetCurrent().Add(textInput);
166 const std::string styledString = "Test Stringa<i>b</i>" ;
167 const std::string plainString = "Test String";
168 textInput.SetInitialText( plainString );
170 application.SendNotification();
171 application.Render();
173 textInput.SetEditable(true);
175 tet_infoline("Confirm style at cursor is default(plain)");
177 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
178 application.ProcessEvent(eventA);
179 application.SendNotification();
180 application.Render();
182 TextStyle retreivedStyleAtCursor = textInput.GetStyleAtCursor();
184 DALI_TEST_CHECK( style == retreivedStyleAtCursor );
185 DALI_TEST_CHECK( !retreivedStyleAtCursor.IsItalicsEnabled() );
187 tet_infoline("Set style before adding new character");
188 style.SetItalics( true );
189 textInput.SetActiveStyle( style );
191 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
192 application.ProcessEvent(eventB);
193 application.SendNotification();
194 application.Render();
196 tet_infoline("Confirm style at cursor is correct style");
197 retreivedStyleAtCursor = textInput.GetStyleAtCursor();
199 DALI_TEST_CHECK( retreivedStyleAtCursor.IsItalicsEnabled() );
201 tet_infoline("Confirm style at cursor is not a style that was not set");
202 DALI_TEST_CHECK( !retreivedStyleAtCursor.IsUnderlineEnabled() );
204 tet_infoline("Confirm markup text is correct");
205 DALI_TEST_EQUALS( styledString, textInput.GetMarkupText(), TEST_LOCATION);
212 int UtcDaliTextInputSetAndGetTextAlignment(void)
214 ToolkitTestApplication application;
216 TextInput textInput = TextInput::New();
217 textInput.SetTextAlignment(static_cast<Alignment::Type>( Alignment::HorizontalCenter) );
219 bool result = ( textInput.GetTextAlignment() & Alignment::HorizontalCenter ) ;
221 DALI_TEST_CHECK( result );
223 result = ( textInput.GetTextAlignment() & Alignment::HorizontalRight );
225 DALI_TEST_CHECK( !result );
229 int UtcDaliTextInputSetAndGetMultilinePolicy(void)
231 ToolkitTestApplication application;
233 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
234 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
236 TextInput textInput = TextInput::New();
237 Stage::GetCurrent().Add(textInput);
238 textInput.SetInitialText( "Hello world!" );
240 for( unsigned int epIndex = 0; epIndex < NUM_MULTILINE_POLICIES; ++epIndex )
242 textInput.SetMultilinePolicy( MULTILINE_POLICIES[epIndex] );
244 DALI_TEST_EQUALS( textInput.GetMultilinePolicy(), MULTILINE_POLICIES[epIndex], TEST_LOCATION );
249 int UtcDaliTextInputSetAndGetExceedEnabled(void)
251 ToolkitTestApplication application;
253 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
254 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
256 TextInput textInput = TextInput::New();
257 Stage::GetCurrent().Add(textInput);
258 textInput.SetInitialText( "Hello world!" );
260 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
262 textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
264 DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );