2 * Copyright (c) 2016 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.
24 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
26 #include <toolkit-text-utils.h>
27 #include <dali-toolkit/internal/text/text-controller.h>
28 #include <dali-toolkit/internal/text/text-control-interface.h>
29 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
32 using namespace Toolkit;
38 const char* const OPTION_SELECT_WORD("option-select_word"); // "Select Word" popup option.
39 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
40 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
41 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
42 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
43 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
45 const Size CONTROL_SIZE( 300.f, 60.f );
47 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
49 std::string gClipboardText;
50 void ContentSelectedCallback( ClipboardEventNotifier& notifier )
52 gClipboardText = notifier.GetContent();
57 int UtcDaliTextController(void)
59 tet_infoline(" UtcDaliTextController");
60 ToolkitTestApplication application;
62 // Creates a text controller.
63 ControllerPtr controller = Controller::New();
64 DALI_TEST_CHECK( controller );
70 int UtcDaliTextControllerSetGetScrollEnabled(void)
72 tet_infoline(" UtcDaliTextControllerSetGetScrollEnabled");
73 ToolkitTestApplication application;
75 // Creates a text controller.
76 ControllerPtr controller = Controller::New();
77 DALI_TEST_CHECK( controller );
79 // Configures the text controller similarly to the text-editor.
80 ConfigureTextEditor( controller );
82 DALI_TEST_CHECK( !controller->IsHorizontalScrollEnabled() );
83 DALI_TEST_CHECK( controller->IsVerticalScrollEnabled() );
85 // Configures the text controller similarly to the text-field.
86 ConfigureTextField( controller );
88 DALI_TEST_CHECK( controller->IsHorizontalScrollEnabled() );
89 DALI_TEST_CHECK( !controller->IsVerticalScrollEnabled() );
91 // Configures the text controller similarly to the text-label.
92 ConfigureTextLabel( controller );
94 DALI_TEST_CHECK( !controller->IsHorizontalScrollEnabled() );
95 DALI_TEST_CHECK( !controller->IsVerticalScrollEnabled() );
101 int UtcDaliTextControllerSetIsTextElide(void)
103 tet_infoline(" UtcDaliTextControllerSetIsTextElide");
104 ToolkitTestApplication application;
106 // Creates a text controller.
107 ControllerPtr controller = Controller::New();
108 DALI_TEST_CHECK( controller );
110 // Configures the text controller similarly to the text-editor.
111 ConfigureTextEditor( controller );
112 DALI_TEST_EQUALS( false, controller->IsTextElideEnabled(), TEST_LOCATION );
114 controller->SetTextElideEnabled( true );
115 DALI_TEST_EQUALS( true, controller->IsTextElideEnabled(), TEST_LOCATION );
117 // Configures the text controller similarly to the text-field.
118 ConfigureTextField( controller );
119 DALI_TEST_EQUALS( false, controller->IsTextElideEnabled(), TEST_LOCATION );
121 controller->SetTextElideEnabled( true );
122 DALI_TEST_EQUALS( true, controller->IsTextElideEnabled(), TEST_LOCATION );
124 // Configures the text controller similarly to the text-label.
125 ConfigureTextLabel( controller );
126 DALI_TEST_EQUALS( true, controller->IsTextElideEnabled(), TEST_LOCATION );
128 controller->SetTextElideEnabled( false );
129 DALI_TEST_EQUALS( false, controller->IsTextElideEnabled(), TEST_LOCATION );
131 tet_result(TET_PASS);
135 int UtcDaliTextControllerEnableCursorBlinking(void)
137 tet_infoline(" UtcDaliTextControllerEnableCursorBlinking");
138 ToolkitTestApplication application;
140 // Creates a text controller.
141 ControllerPtr controller = Controller::New();
142 DALI_TEST_CHECK( controller );
144 // There is no text input enabled.
145 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
147 // Enable the text input.
148 // Creates a decorator.
149 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
152 // Enables the text input.
153 controller->EnableTextInput( decorator );
155 // Enables the cursor blink.
156 controller->SetEnableCursorBlink( true );
158 DALI_TEST_CHECK( controller->GetEnableCursorBlink() );
160 // Disables the cursor blink.
161 controller->SetEnableCursorBlink( false );
163 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
165 tet_result(TET_PASS);
169 int UtcDaliTextControllerImfEvent(void)
171 tet_infoline(" UtcDaliTextController");
172 ToolkitTestApplication application;
174 // Creates a text controller.
175 ControllerPtr controller = Controller::New();
178 ImfManager::ImfEventData imfEvent;
180 DALI_TEST_CHECK( controller );
182 // Enable the text input.
183 // Creates a decorator.
184 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
187 // Enables the text input.
188 controller->EnableTextInput( decorator );
190 // Creates an ImfManager.
191 ImfManager imfManager = ImfManager::Get();
194 imfEvent = ImfManager::ImfEventData( ImfManager::VOID, "", 0, 0 );
195 controller->OnImfEvent( imfManager, imfEvent );
197 controller->GetText( text );
198 DALI_TEST_CHECK( text.empty() );
200 // Send COMMIT event.
201 imfEvent = ImfManager::ImfEventData( ImfManager::COMMIT, "Hello ", 0, 6 );
202 controller->OnImfEvent( imfManager, imfEvent );
204 // Force to update the model.
205 controller->GetNaturalSize();
207 controller->GetText( text );
208 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
210 // Send PREEDIT event
211 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "w", 6, 1 );
212 controller->OnImfEvent( imfManager, imfEvent );
214 // Force to update the model.
215 controller->GetNaturalSize();
217 controller->GetText( text );
218 DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION );
220 // Send DELETESURROUNDING event
221 imfEvent = ImfManager::ImfEventData( ImfManager::DELETESURROUNDING, "", -1, 1 );
222 controller->OnImfEvent( imfManager, imfEvent );
224 // Force to update the model.
225 controller->GetNaturalSize();
227 controller->GetText( text );
228 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
230 // Send PREEDIT event
231 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "wo", 6, 2 );
232 controller->OnImfEvent( imfManager, imfEvent );
234 // Force to update the model.
235 controller->GetNaturalSize();
237 controller->GetText( text );
238 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
240 // Send GETSURROUNDING event
241 imfEvent = ImfManager::ImfEventData( ImfManager::GETSURROUNDING, "", 0, 0 );
242 controller->OnImfEvent( imfManager, imfEvent );
244 controller->GetText( text );
245 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
247 tet_result(TET_PASS);
251 int UtcDaliTextControllerTextPopupButtonTouched(void)
253 tet_infoline(" UtcDaliTextControllerTextPopupButtonTouched");
254 ToolkitTestApplication application;
256 // Creates a text controller.
257 ControllerPtr controller = Controller::New();
259 DALI_TEST_CHECK( controller );
263 Property::Map attributes;
265 // Enable the text input.
266 // Creates a decorator.
267 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
270 // Enables the text input.
271 controller->EnableTextInput( decorator );
273 // Creates the text's popup.
274 TextSelectionPopupCallbackInterface& callbackInterface = *controller;
275 TextSelectionPopup textPopup = TextSelectionPopup::New( &callbackInterface );
277 Toolkit::TextSelectionPopup::Buttons buttonsToEnable = static_cast<Toolkit::TextSelectionPopup::Buttons>( TextSelectionPopup::CUT |
278 TextSelectionPopup::COPY |
279 TextSelectionPopup::PASTE |
280 TextSelectionPopup::SELECT |
281 TextSelectionPopup::SELECT_ALL |
282 TextSelectionPopup::CLIPBOARD );
284 textPopup.EnableButtons( buttonsToEnable );
285 Stage::GetCurrent().Add( textPopup );
286 textPopup.ShowPopup();
289 application.SendNotification();
290 application.Render();
293 controller->SetText( "Hello world" );
295 // Select the whole text.
296 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
297 DALI_TEST_CHECK( button );
299 button.DoAction( "buttonClick", attributes );
301 // Call relayout to process the input events.
302 controller->Relayout( CONTROL_SIZE );
305 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
306 DALI_TEST_CHECK( button );
308 button.DoAction( "buttonClick", attributes );
310 // Force to update the model.
311 controller->GetNaturalSize();
313 controller->GetText( text );
314 DALI_TEST_CHECK( text.empty() );
317 controller->SetText( "Hello world" );
319 // Select the whole text.
320 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
321 DALI_TEST_CHECK( button );
323 button.DoAction( "buttonClick", attributes );
325 // Call relayout to process the input events.
326 controller->Relayout( CONTROL_SIZE );
328 // Copy to the clipboard.
329 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_COPY ) );
330 DALI_TEST_CHECK( button );
332 button.DoAction( "buttonClick", attributes );
334 // Call relayout to process the input events.
335 controller->Relayout( CONTROL_SIZE );
338 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
339 DALI_TEST_CHECK( button );
341 button.DoAction( "buttonClick", attributes );
343 // Force to update the model.
344 controller->GetNaturalSize();
346 controller->GetText( text );
347 DALI_TEST_CHECK( text.empty() );
349 ClipboardEventNotifier clipboardEventNotifier = ClipboardEventNotifier::Get();
350 clipboardEventNotifier.ContentSelectedSignal().Connect( &ContentSelectedCallback );
353 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_PASTE ) );
354 DALI_TEST_CHECK( button );
356 button.DoAction( "buttonClick", attributes );
358 // Call relayout to process the input events.
359 controller->Relayout( CONTROL_SIZE );
361 DALI_TEST_EQUALS( "Hello world", gClipboardText, TEST_LOCATION );
363 // Show the clipboard.
364 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CLIPBOARD ) );
365 DALI_TEST_CHECK( button );
367 button.DoAction( "buttonClick", attributes );
369 tet_result(TET_PASS);
373 int UtcDaliTextControllerGetInputShadowProperty(void)
375 tet_infoline(" UtcDaliTextControllerGetInputShadowProperty");
376 ToolkitTestApplication application;
378 // Creates a text controller.
379 ControllerPtr controller = Controller::New();
381 DALI_TEST_CHECK( controller );
383 const std::string& shadowProperties = controller->GetInputShadowProperties();
385 DALI_TEST_CHECK( shadowProperties.empty() );
387 tet_result(TET_PASS);
391 int UtcDaliTextControllerGetInputUnderlineProperty(void)
393 tet_infoline(" UtcDaliTextControllerGetInputUnderlineProperty");
394 ToolkitTestApplication application;
396 // Creates a text controller.
397 ControllerPtr controller = Controller::New();
399 DALI_TEST_CHECK( controller );
401 const std::string& underlineProperties = controller->GetInputUnderlineProperties();
403 DALI_TEST_CHECK( underlineProperties.empty() );
405 tet_result(TET_PASS);
409 int UtcDaliTextControllerSetGetAutoScrollEnabled(void)
411 tet_infoline(" UtcDaliTextControllerSetGetAutoScrollEnabled");
412 ToolkitTestApplication application;
414 // Creates a text controller.
415 ControllerPtr controller = Controller::New();
417 DALI_TEST_CHECK( controller );
419 DALI_TEST_CHECK( !controller->IsAutoScrollEnabled() );
421 // The auto scrolling shouldn't be enabled if the multi-line is enabled.
423 // Enable multi-line.
424 controller->SetMultiLineEnabled( true );
426 // Enable text scrolling.
427 controller->SetAutoScrollEnabled( true );
429 DALI_TEST_CHECK( !controller->IsAutoScrollEnabled() );
431 // Disable multi-line.
432 controller->SetMultiLineEnabled( false );
434 // Enable text scrolling.
435 controller->SetAutoScrollEnabled( true );
437 // Should be ebabled now.
438 DALI_TEST_CHECK( controller->IsAutoScrollEnabled() );
440 tet_result(TET_PASS);