2 * Copyright (c) 2017 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.
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <toolkit-text-utils.h>
26 #include <dali-toolkit/internal/text/text-controller.h>
27 #include <dali-toolkit/internal/text/text-control-interface.h>
28 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
31 using namespace Toolkit;
37 const char* const OPTION_SELECT_WORD("option-select_word"); // "Select Word" popup option.
38 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
39 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
40 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
41 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
42 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
44 const Size CONTROL_SIZE( 300.f, 60.f );
46 std::string gClipboardText;
47 void ContentSelectedCallback( ClipboardEventNotifier& notifier )
49 gClipboardText = notifier.GetContent();
54 int UtcDaliTextController(void)
56 tet_infoline(" UtcDaliTextController");
57 ToolkitTestApplication application;
59 // Creates a text controller.
60 ControllerPtr controller = Controller::New();
61 DALI_TEST_CHECK( controller );
67 int UtcDaliTextControllerSetGetScrollEnabled(void)
69 tet_infoline(" UtcDaliTextControllerSetGetScrollEnabled");
70 ToolkitTestApplication application;
72 // Creates a text controller.
73 ControllerPtr controller = Controller::New();
74 DALI_TEST_CHECK( controller );
76 // Configures the text controller similarly to the text-editor.
77 ConfigureTextEditor( controller );
79 DALI_TEST_CHECK( !controller->IsHorizontalScrollEnabled() );
80 DALI_TEST_CHECK( controller->IsVerticalScrollEnabled() );
82 // Configures the text controller similarly to the text-field.
83 ConfigureTextField( controller );
85 DALI_TEST_CHECK( controller->IsHorizontalScrollEnabled() );
86 DALI_TEST_CHECK( !controller->IsVerticalScrollEnabled() );
88 // Configures the text controller similarly to the text-label.
89 ConfigureTextLabel( controller );
91 DALI_TEST_CHECK( !controller->IsHorizontalScrollEnabled() );
92 DALI_TEST_CHECK( !controller->IsVerticalScrollEnabled() );
98 int UtcDaliTextControllerSetIsTextElide(void)
100 tet_infoline(" UtcDaliTextControllerSetIsTextElide");
101 ToolkitTestApplication application;
103 // Creates a text controller.
104 ControllerPtr controller = Controller::New();
105 DALI_TEST_CHECK( controller );
107 // Configures the text controller similarly to the text-editor.
108 ConfigureTextEditor( controller );
109 DALI_TEST_EQUALS( false, controller->IsTextElideEnabled(), TEST_LOCATION );
111 controller->SetTextElideEnabled( true );
112 DALI_TEST_EQUALS( true, controller->IsTextElideEnabled(), TEST_LOCATION );
114 // Configures the text controller similarly to the text-field.
115 ConfigureTextField( controller );
116 DALI_TEST_EQUALS( false, controller->IsTextElideEnabled(), TEST_LOCATION );
118 controller->SetTextElideEnabled( true );
119 DALI_TEST_EQUALS( true, controller->IsTextElideEnabled(), TEST_LOCATION );
121 // Configures the text controller similarly to the text-label.
122 ConfigureTextLabel( controller );
123 DALI_TEST_EQUALS( true, controller->IsTextElideEnabled(), TEST_LOCATION );
125 controller->SetTextElideEnabled( false );
126 DALI_TEST_EQUALS( false, controller->IsTextElideEnabled(), TEST_LOCATION );
128 tet_result(TET_PASS);
132 int UtcDaliTextControllerEnableCursorBlinking(void)
134 tet_infoline(" UtcDaliTextControllerEnableCursorBlinking");
135 ToolkitTestApplication application;
137 // Creates a text controller.
138 ControllerPtr controller = Controller::New();
139 DALI_TEST_CHECK( controller );
141 // There is no text input enabled.
142 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
144 // Enable the text input.
145 // Creates a decorator.
146 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
149 // Enables the text input.
150 controller->EnableTextInput( decorator );
152 // Enables the cursor blink.
153 controller->SetEnableCursorBlink( true );
155 DALI_TEST_CHECK( controller->GetEnableCursorBlink() );
157 // Disables the cursor blink.
158 controller->SetEnableCursorBlink( false );
160 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
162 tet_result(TET_PASS);
166 int UtcDaliTextControllerImfEvent(void)
168 tet_infoline(" UtcDaliTextController");
169 ToolkitTestApplication application;
171 // Creates a text controller.
172 ControllerPtr controller = Controller::New();
175 ImfManager::ImfEventData imfEvent;
177 DALI_TEST_CHECK( controller );
179 // Enable the text input.
180 // Creates a decorator.
181 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
184 // Enables the text input.
185 controller->EnableTextInput( decorator );
187 // Creates an ImfManager.
188 ImfManager imfManager = ImfManager::Get();
191 imfEvent = ImfManager::ImfEventData( ImfManager::VOID, "", 0, 0 );
192 controller->OnImfEvent( imfManager, imfEvent );
194 controller->GetText( text );
195 DALI_TEST_CHECK( text.empty() );
197 // Send COMMIT event.
198 imfEvent = ImfManager::ImfEventData( ImfManager::COMMIT, "Hello ", 0, 6 );
199 controller->OnImfEvent( imfManager, imfEvent );
201 // Force to update the model.
202 controller->GetNaturalSize();
204 controller->GetText( text );
205 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
207 // Send PREEDIT event
208 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "w", 6, 1 );
209 controller->OnImfEvent( imfManager, imfEvent );
211 // Force to update the model.
212 controller->GetNaturalSize();
214 controller->GetText( text );
215 DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION );
217 // Send DELETESURROUNDING event
218 imfEvent = ImfManager::ImfEventData( ImfManager::DELETESURROUNDING, "", -1, 1 );
219 controller->OnImfEvent( imfManager, imfEvent );
221 // Force to update the model.
222 controller->GetNaturalSize();
224 controller->GetText( text );
225 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
227 // Send PREEDIT event
228 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "wo", 6, 2 );
229 controller->OnImfEvent( imfManager, imfEvent );
231 // Force to update the model.
232 controller->GetNaturalSize();
234 controller->GetText( text );
235 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
237 // Send GETSURROUNDING event
238 imfEvent = ImfManager::ImfEventData( ImfManager::GETSURROUNDING, "", 0, 0 );
239 controller->OnImfEvent( imfManager, imfEvent );
241 controller->GetText( text );
242 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
244 tet_result(TET_PASS);
248 int UtcDaliTextControllerTextPopupButtonTouched(void)
250 tet_infoline(" UtcDaliTextControllerTextPopupButtonTouched");
251 ToolkitTestApplication application;
253 // Creates a text controller.
254 ControllerPtr controller = Controller::New();
256 DALI_TEST_CHECK( controller );
260 Property::Map attributes;
262 // Enable the text input.
263 // Creates a decorator.
264 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
267 // Enables the text input.
268 controller->EnableTextInput( decorator );
270 // Creates the text's popup.
271 TextSelectionPopupCallbackInterface& callbackInterface = *controller;
272 TextSelectionPopup textPopup = TextSelectionPopup::New( &callbackInterface );
274 Toolkit::TextSelectionPopup::Buttons buttonsToEnable = static_cast<Toolkit::TextSelectionPopup::Buttons>( TextSelectionPopup::CUT |
275 TextSelectionPopup::COPY |
276 TextSelectionPopup::PASTE |
277 TextSelectionPopup::SELECT |
278 TextSelectionPopup::SELECT_ALL |
279 TextSelectionPopup::CLIPBOARD );
281 textPopup.EnableButtons( buttonsToEnable );
282 Stage::GetCurrent().Add( textPopup );
283 textPopup.ShowPopup();
286 application.SendNotification();
287 application.Render();
290 controller->SetText( "Hello world" );
292 // Select the whole text.
293 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
294 DALI_TEST_CHECK( button );
296 button.DoAction( "buttonClick", attributes );
298 // Call relayout to process the input events.
299 controller->Relayout( CONTROL_SIZE );
302 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
303 DALI_TEST_CHECK( button );
305 button.DoAction( "buttonClick", attributes );
307 // Force to update the model.
308 controller->GetNaturalSize();
310 controller->GetText( text );
311 DALI_TEST_CHECK( text.empty() );
314 controller->SetText( "Hello world" );
316 // Select the whole text.
317 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
318 DALI_TEST_CHECK( button );
320 button.DoAction( "buttonClick", attributes );
322 // Call relayout to process the input events.
323 controller->Relayout( CONTROL_SIZE );
325 // Copy to the clipboard.
326 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_COPY ) );
327 DALI_TEST_CHECK( button );
329 button.DoAction( "buttonClick", attributes );
331 // Call relayout to process the input events.
332 controller->Relayout( CONTROL_SIZE );
335 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
336 DALI_TEST_CHECK( button );
338 button.DoAction( "buttonClick", attributes );
340 // Force to update the model.
341 controller->GetNaturalSize();
343 controller->GetText( text );
344 DALI_TEST_CHECK( text.empty() );
346 ClipboardEventNotifier clipboardEventNotifier = ClipboardEventNotifier::Get();
347 clipboardEventNotifier.ContentSelectedSignal().Connect( &ContentSelectedCallback );
350 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_PASTE ) );
351 DALI_TEST_CHECK( button );
353 button.DoAction( "buttonClick", attributes );
355 // Call relayout to process the input events.
356 controller->Relayout( CONTROL_SIZE );
358 DALI_TEST_EQUALS( "Hello world", gClipboardText, TEST_LOCATION );
360 // Show the clipboard.
361 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CLIPBOARD ) );
362 DALI_TEST_CHECK( button );
364 button.DoAction( "buttonClick", attributes );
366 tet_result(TET_PASS);
370 int UtcDaliTextControllerGetInputShadowProperty(void)
372 tet_infoline(" UtcDaliTextControllerGetInputShadowProperty");
373 ToolkitTestApplication application;
375 // Creates a text controller.
376 ControllerPtr controller = Controller::New();
378 DALI_TEST_CHECK( controller );
380 const std::string& shadowProperties = controller->GetInputShadowProperties();
382 DALI_TEST_CHECK( shadowProperties.empty() );
384 tet_result(TET_PASS);
388 int UtcDaliTextControllerGetInputUnderlineProperty(void)
390 tet_infoline(" UtcDaliTextControllerGetInputUnderlineProperty");
391 ToolkitTestApplication application;
393 // Creates a text controller.
394 ControllerPtr controller = Controller::New();
396 DALI_TEST_CHECK( controller );
398 const std::string& underlineProperties = controller->GetInputUnderlineProperties();
400 DALI_TEST_CHECK( underlineProperties.empty() );
402 tet_result(TET_PASS);
406 int UtcDaliTextControllerSetGetAutoScrollEnabled(void)
408 tet_infoline(" UtcDaliTextControllerSetGetAutoScrollEnabled");
409 ToolkitTestApplication application;
411 // Creates a text controller.
412 ControllerPtr controller = Controller::New();
414 DALI_TEST_CHECK( controller );
416 DALI_TEST_CHECK( !controller->IsAutoScrollEnabled() );
418 // The auto scrolling shouldn't be enabled if the multi-line is enabled.
420 // Enable multi-line.
421 controller->SetMultiLineEnabled( true );
423 // Enable text scrolling.
424 controller->SetAutoScrollEnabled( true );
426 DALI_TEST_CHECK( !controller->IsAutoScrollEnabled() );
428 // Disable multi-line.
429 controller->SetMultiLineEnabled( false );
431 // Enable text scrolling.
432 controller->SetAutoScrollEnabled( true );
434 // Should be ebabled now.
435 DALI_TEST_CHECK( controller->IsAutoScrollEnabled() );
437 tet_result(TET_PASS);
441 int UtcDaliTextControllerSetGetCheckProperty(void)
443 tet_infoline(" UtcDaliTextControllerSetGetCheckProperty");
444 ToolkitTestApplication application;
446 // Creates a text controller.
447 ControllerPtr controller = Controller::New();
449 DALI_TEST_CHECK( controller );
451 // Enable the text input.
452 // Creates a decorator.
453 Text::DecoratorPtr decorator = Text::Decorator::New( *controller, *controller );
455 // Enables the text input.
456 controller->EnableTextInput( decorator );
458 DALI_TEST_CHECK( !controller->IsInputModePassword() );
460 // Set the text input to password.
461 controller->SetInputModePassword( true );
463 DALI_TEST_CHECK( controller->IsInputModePassword() );
465 // Unset the text input to password.
466 controller->SetInputModePassword( false );
468 DALI_TEST_CHECK( !controller->IsInputModePassword() );
470 tet_result(TET_PASS);