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 <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 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
48 class ControlImpl : public ControlInterface, public Text::EditableControlInterface
55 virtual ~ControlImpl()
58 virtual void AddDecoration( Actor& actor, bool needsClipping )
61 virtual void RequestTextRelayout()
64 virtual void TextChanged()
67 virtual void MaxLengthReached()
70 virtual void InputStyleChanged( InputStyle::Mask inputStyleMask )
74 std::string gClipboardText;
75 void ContentSelectedCallback( ClipboardEventNotifier& notifier )
77 gClipboardText = notifier.GetContent();
82 int UtcDaliTextController(void)
84 tet_infoline(" UtcDaliTextController");
85 ToolkitTestApplication application;
87 // Creates a text controller.
88 ControllerPtr controller = Controller::New();
90 DALI_TEST_CHECK( controller );
96 int UtcDaliTextControllerEnableCursorBlinking(void)
98 tet_infoline(" UtcDaliTextControllerEnableCursorBlinking");
99 ToolkitTestApplication application;
101 // Creates a text controller.
102 ControllerPtr controller = Controller::New();
104 DALI_TEST_CHECK( controller );
106 // There is no text input enabled.
107 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
109 // Enable the text input.
110 // Creates a decorator.
111 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
114 // Enables the text input.
115 controller->EnableTextInput( decorator );
117 // Enables the cursor blink.
118 controller->SetEnableCursorBlink( true );
120 DALI_TEST_CHECK( controller->GetEnableCursorBlink() );
122 // Disables the cursor blink.
123 controller->SetEnableCursorBlink( false );
125 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
127 tet_result(TET_PASS);
131 int UtcDaliTextControllerImfEvent(void)
133 tet_infoline(" UtcDaliTextController");
134 ToolkitTestApplication application;
136 // Creates a text controller.
137 ControllerPtr controller = Controller::New();
140 ImfManager::ImfEventData imfEvent;
142 DALI_TEST_CHECK( controller );
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 // Creates an ImfManager.
153 ImfManager imfManager = ImfManager::Get();
156 imfEvent = ImfManager::ImfEventData( ImfManager::VOID, "", 0, 0 );
157 controller->OnImfEvent( imfManager, imfEvent );
159 controller->GetText( text );
160 DALI_TEST_CHECK( text.empty() );
162 // Send COMMIT event.
163 imfEvent = ImfManager::ImfEventData( ImfManager::COMMIT, "Hello ", 0, 6 );
164 controller->OnImfEvent( imfManager, imfEvent );
166 // Force to update the model.
167 controller->GetNaturalSize();
169 controller->GetText( text );
170 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
172 // Send PREEDIT event
173 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "w", 6, 1 );
174 controller->OnImfEvent( imfManager, imfEvent );
176 // Force to update the model.
177 controller->GetNaturalSize();
179 controller->GetText( text );
180 DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION );
182 // Send DELETESURROUNDING event
183 imfEvent = ImfManager::ImfEventData( ImfManager::DELETESURROUNDING, "", -1, 1 );
184 controller->OnImfEvent( imfManager, imfEvent );
186 // Force to update the model.
187 controller->GetNaturalSize();
189 controller->GetText( text );
190 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
192 // Send PREEDIT event
193 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "wo", 6, 2 );
194 controller->OnImfEvent( imfManager, imfEvent );
196 // Force to update the model.
197 controller->GetNaturalSize();
199 controller->GetText( text );
200 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
202 // Send GETSURROUNDING event
203 imfEvent = ImfManager::ImfEventData( ImfManager::GETSURROUNDING, "", 0, 0 );
204 controller->OnImfEvent( imfManager, imfEvent );
206 controller->GetText( text );
207 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
209 tet_result(TET_PASS);
213 int UtcDaliTextControllerTextPopupButtonTouched(void)
215 tet_infoline(" UtcDaliTextControllerTextPopupButtonTouched");
216 ToolkitTestApplication application;
218 // Creates a text controller.
219 ControllerPtr controller = Controller::New();
221 DALI_TEST_CHECK( controller );
225 Property::Map attributes;
227 // Enable the text input.
228 // Creates a decorator.
229 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
232 // Enables the text input.
233 controller->EnableTextInput( decorator );
235 // Creates the text's popup.
236 TextSelectionPopupCallbackInterface& callbackInterface = *controller;
237 TextSelectionPopup textPopup = TextSelectionPopup::New( &callbackInterface );
239 Toolkit::TextSelectionPopup::Buttons buttonsToEnable = static_cast<Toolkit::TextSelectionPopup::Buttons>( TextSelectionPopup::CUT |
240 TextSelectionPopup::COPY |
241 TextSelectionPopup::PASTE |
242 TextSelectionPopup::SELECT |
243 TextSelectionPopup::SELECT_ALL |
244 TextSelectionPopup::CLIPBOARD );
246 textPopup.EnableButtons( buttonsToEnable );
247 Stage::GetCurrent().Add( textPopup );
248 textPopup.ShowPopup();
251 application.SendNotification();
252 application.Render();
255 controller->SetText( "Hello world" );
257 // Select the whole text.
258 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
259 DALI_TEST_CHECK( button );
261 button.DoAction( "buttonClick", attributes );
263 // Call relayout to process the input events.
264 controller->Relayout( CONTROL_SIZE );
267 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
268 DALI_TEST_CHECK( button );
270 button.DoAction( "buttonClick", attributes );
272 // Force to update the model.
273 controller->GetNaturalSize();
275 controller->GetText( text );
276 DALI_TEST_CHECK( text.empty() );
279 controller->SetText( "Hello world" );
281 // Select the whole text.
282 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
283 DALI_TEST_CHECK( button );
285 button.DoAction( "buttonClick", attributes );
287 // Call relayout to process the input events.
288 controller->Relayout( CONTROL_SIZE );
290 // Copy to the clipboard.
291 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_COPY ) );
292 DALI_TEST_CHECK( button );
294 button.DoAction( "buttonClick", attributes );
296 // Call relayout to process the input events.
297 controller->Relayout( CONTROL_SIZE );
300 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
301 DALI_TEST_CHECK( button );
303 button.DoAction( "buttonClick", attributes );
305 // Force to update the model.
306 controller->GetNaturalSize();
308 controller->GetText( text );
309 DALI_TEST_CHECK( text.empty() );
311 ClipboardEventNotifier clipboardEventNotifier = ClipboardEventNotifier::Get();
312 clipboardEventNotifier.ContentSelectedSignal().Connect( &ContentSelectedCallback );
315 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_PASTE ) );
316 DALI_TEST_CHECK( button );
318 button.DoAction( "buttonClick", attributes );
320 // Call relayout to process the input events.
321 controller->Relayout( CONTROL_SIZE );
323 DALI_TEST_EQUALS( "Hello world", gClipboardText, TEST_LOCATION );
325 // Show the clipboard.
326 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CLIPBOARD ) );
327 DALI_TEST_CHECK( button );
329 button.DoAction( "buttonClick", attributes );
331 tet_result(TET_PASS);
335 int UtcDaliTextControllerGetInputShadowProperty(void)
337 tet_infoline(" UtcDaliTextControllerGetInputShadowProperty");
338 ToolkitTestApplication application;
340 // Creates a text controller.
341 ControllerPtr controller = Controller::New();
343 DALI_TEST_CHECK( controller );
345 const std::string& shadowProperties = controller->GetInputShadowProperties();
347 DALI_TEST_CHECK( shadowProperties.empty() );
349 tet_result(TET_PASS);
353 int UtcDaliTextControllerGetInputUnderlineProperty(void)
355 tet_infoline(" UtcDaliTextControllerGetInputUnderlineProperty");
356 ToolkitTestApplication application;
358 // Creates a text controller.
359 ControllerPtr controller = Controller::New();
361 DALI_TEST_CHECK( controller );
363 const std::string& underlineProperties = controller->GetInputUnderlineProperties();
365 DALI_TEST_CHECK( underlineProperties.empty() );
367 tet_result(TET_PASS);
371 int UtcDaliTextControllerSetGetAutoScrollEnabled(void)
373 tet_infoline(" UtcDaliTextControllerSetGetAutoScrollEnabled");
374 ToolkitTestApplication application;
376 // Creates a text controller.
377 ControllerPtr controller = Controller::New();
379 DALI_TEST_CHECK( controller );
381 DALI_TEST_CHECK( !controller->IsAutoScrollEnabled() );
383 // The auto scrolling shouldn't be enabled if the multi-line is enabled.
385 // Enable multi-line.
386 controller->SetMultiLineEnabled( true );
388 // Enable text scrolling.
389 controller->SetAutoScrollEnabled( true );
391 DALI_TEST_CHECK( !controller->IsAutoScrollEnabled() );
393 // Disable multi-line.
394 controller->SetMultiLineEnabled( false );
396 // Enable text scrolling.
397 controller->SetAutoScrollEnabled( true );
399 // Should be ebabled now.
400 DALI_TEST_CHECK( controller->IsAutoScrollEnabled() );
402 tet_result(TET_PASS);