2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21 #include <dali/integration-api/events/key-event-integ.h>
24 using namespace Toolkit;
27 int UtcDaliTextInputSetActiveStyle(void)
29 ToolkitTestApplication application;
31 tet_infoline("Testing Setting of Style to newly added text");
33 TextInput textInput = TextInput::New(); // create empty TextInput
35 Stage::GetCurrent().Add(textInput);
37 const std::string styledString = "Test String<i>ab</i>" ;
38 const std::string plainString = "Test String";
39 textInput.SetInitialText( plainString );
41 application.SendNotification();
44 textInput.SetEditable(true);
46 std::string retreivedMarkupString = textInput.GetMarkupText();
48 tet_infoline("Confirm markup text is a plain string ");
49 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
52 style.SetItalics( true );
54 tet_infoline("Apply style to TextInput");
55 textInput.SetActiveStyle( style );
57 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
58 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
60 application.SendNotification();
63 application.ProcessEvent(eventA);
64 application.SendNotification();
67 application.ProcessEvent(eventB);
68 application.SendNotification();
71 retreivedMarkupString = textInput.GetMarkupText();
73 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
77 int UtcDaliTextInputApplyStyleToSelectedText(void)
79 ToolkitTestApplication application;
81 tet_infoline("Testing application of style to selected text ");
83 TextInput textInput = TextInput::New(); // create empty TextInput
85 Stage::GetCurrent().Add(textInput);
87 const std::string styledString = "Test <i>String</i> to style";
88 const std::string plainString = "Test String to style";
89 textInput.SetInitialText( plainString );
91 application.SendNotification();
94 textInput.SetEditable(true);
96 std::string retreivedMarkupString = textInput.GetMarkupText();
98 tet_infoline("Confirm markup text is a plain string ");
99 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
102 style.SetItalics( true );
104 textInput.SelectText( 5, 11 );
106 tet_infoline("Apply style to selected text");
107 textInput.ApplyStyle( style );
109 application.Render();
111 retreivedMarkupString = textInput.GetMarkupText();
113 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
117 int UtcDaliTextInputApplyStyleToAll(void)
119 ToolkitTestApplication application;
121 tet_infoline("Testing application of style to all text ");
123 TextInput textInput = TextInput::New(); // create empty TextInput
125 Stage::GetCurrent().Add(textInput);
127 const std::string styledString = "<i>Test String to style</i>";
128 const std::string plainString = "Test String to style";
129 textInput.SetInitialText( plainString );
131 application.SendNotification();
132 application.Render();
134 textInput.SetEditable(true);
136 std::string retreivedMarkupString = textInput.GetMarkupText();
138 tet_infoline("Confirm markup text is a plain string ");
139 DALI_TEST_EQUALS( plainString,textInput.GetText(), TEST_LOCATION);
142 style.SetItalics( true );
144 tet_infoline("Apply style to all text");
145 textInput.ApplyStyleToAll( style );
147 application.Render();
149 retreivedMarkupString = textInput.GetMarkupText();
151 DALI_TEST_EQUALS( styledString, retreivedMarkupString, TEST_LOCATION);
155 int UtcDaliTextInputGetStyleAtCursor(void)
157 ToolkitTestApplication application;
159 tet_infoline("Test getting style at cursor");
161 TextInput textInput = TextInput::New(); // create empty TextInput
163 Stage::GetCurrent().Add(textInput);
165 const std::string styledString = "Test Stringa<i>b</i>" ;
166 const std::string plainString = "Test String";
167 textInput.SetInitialText( plainString );
169 application.SendNotification();
170 application.Render();
172 textInput.SetEditable(true);
174 tet_infoline("Confirm style at cursor is default(plain)");
176 Integration::KeyEvent eventA("a", "a", 0, 0, 0, Integration::KeyEvent::Down );
177 application.ProcessEvent(eventA);
178 application.SendNotification();
179 application.Render();
181 TextStyle retreivedStyleAtCursor = textInput.GetStyleAtCursor();
183 DALI_TEST_CHECK( style == retreivedStyleAtCursor );
184 DALI_TEST_CHECK( !retreivedStyleAtCursor.GetItalics() );
186 tet_infoline("Set style before adding new character");
187 style.SetItalics( true );
188 textInput.SetActiveStyle( style );
190 Integration::KeyEvent eventB("b", "b", 0, 0, 0, Integration::KeyEvent::Down );
191 application.ProcessEvent(eventB);
192 application.SendNotification();
193 application.Render();
195 tet_infoline("Confirm style at cursor is correct style");
196 retreivedStyleAtCursor = textInput.GetStyleAtCursor();
198 DALI_TEST_CHECK( retreivedStyleAtCursor.GetItalics() );
200 tet_infoline("Confirm style at cursor is not a style that was not set");
201 DALI_TEST_CHECK( !retreivedStyleAtCursor.GetUnderline() );
203 tet_infoline("Confirm markup text is correct");
204 DALI_TEST_EQUALS( styledString, textInput.GetMarkupText(), TEST_LOCATION);
211 int UtcDaliTextInputSetAndGetTextAlignment(void)
213 ToolkitTestApplication application;
215 TextInput textInput = TextInput::New();
216 textInput.SetTextAlignment(static_cast<Alignment::Type>( Alignment::HorizontalCenter) );
218 bool result = ( textInput.GetTextAlignment() & Alignment::HorizontalCenter ) ;
220 DALI_TEST_CHECK( result );
222 result = ( textInput.GetTextAlignment() & Alignment::HorizontalRight );
224 DALI_TEST_CHECK( !result );
228 int UtcDaliTextInputSetAndGetMultilinePolicy(void)
230 ToolkitTestApplication application;
232 const TextView::MultilinePolicy MULTILINE_POLICIES[] = { TextView::SplitByNewLineChar, TextView::SplitByWord, TextView::SplitByChar };
233 const unsigned int NUM_MULTILINE_POLICIES = sizeof( MULTILINE_POLICIES ) / sizeof( unsigned int );
235 TextInput textInput = TextInput::New();
236 Stage::GetCurrent().Add(textInput);
237 textInput.SetInitialText( "Hello world!" );
239 for( unsigned int epIndex = 0; epIndex < NUM_MULTILINE_POLICIES; ++epIndex )
241 textInput.SetMultilinePolicy( MULTILINE_POLICIES[epIndex] );
243 DALI_TEST_EQUALS( textInput.GetMultilinePolicy(), MULTILINE_POLICIES[epIndex], TEST_LOCATION );
248 int UtcDaliTextInputSetAndGetExceedEnabled(void)
250 ToolkitTestApplication application;
252 const TextView::ExceedPolicy EXCEED_POLICIES[] = { TextView::Original, TextView::Fade, TextView::Split, TextView::ShrinkToFit };
253 const unsigned int NUM_EXCEED_POLICIES = sizeof( EXCEED_POLICIES ) / sizeof( unsigned int );
255 TextInput textInput = TextInput::New();
256 Stage::GetCurrent().Add(textInput);
257 textInput.SetInitialText( "Hello world!" );
259 for( unsigned int epIndex = 0; epIndex < NUM_EXCEED_POLICIES; ++epIndex )
261 textInput.SetWidthExceedPolicy( EXCEED_POLICIES[epIndex] );
263 DALI_TEST_EQUALS( textInput.GetWidthExceedPolicy(), EXCEED_POLICIES[epIndex], TEST_LOCATION );