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.
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/internal/text/text-controller.h>
26 #include <dali-toolkit/internal/text/text-control-interface.h>
27 #include <dali-toolkit/internal/text/text-editable-control-interface.h>
30 using namespace Toolkit;
36 const char* const OPTION_SELECT_WORD("option-select_word"); // "Select Word" popup option.
37 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
38 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
39 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
40 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
41 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
43 const Size CONTROL_SIZE( 300.f, 60.f );
45 class ControlImpl : public ControlInterface, public Text::EditableControlInterface
52 virtual ~ControlImpl()
55 virtual void AddDecoration( Actor& actor, bool needsClipping )
58 virtual void RequestTextRelayout()
61 virtual void TextChanged()
64 virtual void MaxLengthReached()
67 virtual void InputStyleChanged( InputStyle::Mask inputStyleMask )
71 std::string gClipboardText;
72 void ContentSelectedCallback( ClipboardEventNotifier& notifier )
74 gClipboardText = notifier.GetContent();
79 int UtcDaliTextController(void)
81 tet_infoline(" UtcDaliTextController");
82 ToolkitTestApplication application;
84 // Creates a text controller.
85 ControllerPtr controller = Controller::New();
87 DALI_TEST_CHECK( controller );
93 int UtcDaliTextControllerEnableCursorBlinking(void)
95 tet_infoline(" UtcDaliTextControllerEnableCursorBlinking");
96 ToolkitTestApplication application;
98 // Creates a text controller.
99 ControllerPtr controller = Controller::New();
101 DALI_TEST_CHECK( controller );
103 // There is no text input enabled.
104 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
106 // Enable the text input.
107 // Creates a decorator.
108 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
111 // Enables the text input.
112 controller->EnableTextInput( decorator );
114 // Enables the cursor blink.
115 controller->SetEnableCursorBlink( true );
117 DALI_TEST_CHECK( controller->GetEnableCursorBlink() );
119 // Disables the cursor blink.
120 controller->SetEnableCursorBlink( false );
122 DALI_TEST_CHECK( !controller->GetEnableCursorBlink() );
124 tet_result(TET_PASS);
128 int UtcDaliTextControllerImfEvent(void)
130 tet_infoline(" UtcDaliTextController");
131 ToolkitTestApplication application;
133 // Creates a text controller.
134 ControllerPtr controller = Controller::New();
137 ImfManager::ImfEventData imfEvent;
139 DALI_TEST_CHECK( controller );
141 // Enable the text input.
142 // Creates a decorator.
143 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
146 // Enables the text input.
147 controller->EnableTextInput( decorator );
149 // Creates an ImfManager.
150 ImfManager imfManager = ImfManager::Get();
153 imfEvent = ImfManager::ImfEventData( ImfManager::VOID, "", 0, 0 );
154 controller->OnImfEvent( imfManager, imfEvent );
156 controller->GetText( text );
157 DALI_TEST_CHECK( text.empty() );
159 // Send COMMIT event.
160 imfEvent = ImfManager::ImfEventData( ImfManager::COMMIT, "Hello ", 0, 6 );
161 controller->OnImfEvent( imfManager, imfEvent );
163 // Force to update the model.
164 controller->GetNaturalSize();
166 controller->GetText( text );
167 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
169 // Send PREEDIT event
170 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "w", 6, 1 );
171 controller->OnImfEvent( imfManager, imfEvent );
173 // Force to update the model.
174 controller->GetNaturalSize();
176 controller->GetText( text );
177 DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION );
179 // Send DELETESURROUNDING event
180 imfEvent = ImfManager::ImfEventData( ImfManager::DELETESURROUNDING, "", -1, 1 );
181 controller->OnImfEvent( imfManager, imfEvent );
183 // Force to update the model.
184 controller->GetNaturalSize();
186 controller->GetText( text );
187 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
189 // Send PREEDIT event
190 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "wo", 6, 2 );
191 controller->OnImfEvent( imfManager, imfEvent );
193 // Force to update the model.
194 controller->GetNaturalSize();
196 controller->GetText( text );
197 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
199 // Send GETSURROUNDING event
200 imfEvent = ImfManager::ImfEventData( ImfManager::GETSURROUNDING, "", 0, 0 );
201 controller->OnImfEvent( imfManager, imfEvent );
203 controller->GetText( text );
204 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
206 tet_result(TET_PASS);
210 int UtcDaliTextControllerTextPopupButtonTouched(void)
212 tet_infoline(" UtcDaliTextControllerTextPopupButtonTouched");
213 ToolkitTestApplication application;
215 // Creates a text controller.
216 ControllerPtr controller = Controller::New();
218 DALI_TEST_CHECK( controller );
222 Property::Map attributes;
224 // Enable the text input.
225 // Creates a decorator.
226 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
229 // Enables the text input.
230 controller->EnableTextInput( decorator );
232 // Creates the text's popup.
233 TextSelectionPopupCallbackInterface& callbackInterface = *controller;
234 TextSelectionPopup textPopup = TextSelectionPopup::New( &callbackInterface );
236 Toolkit::TextSelectionPopup::Buttons buttonsToEnable = static_cast<Toolkit::TextSelectionPopup::Buttons>( TextSelectionPopup::CUT |
237 TextSelectionPopup::COPY |
238 TextSelectionPopup::PASTE |
239 TextSelectionPopup::SELECT |
240 TextSelectionPopup::SELECT_ALL |
241 TextSelectionPopup::CLIPBOARD );
243 textPopup.EnableButtons( buttonsToEnable );
244 Stage::GetCurrent().Add( textPopup );
245 textPopup.ShowPopup();
248 application.SendNotification();
249 application.Render();
252 controller->SetText( "Hello world" );
254 // Select the whole text.
255 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
256 DALI_TEST_CHECK( button );
258 button.DoAction( "buttonClick", attributes );
260 // Call relayout to process the input events.
261 controller->Relayout( CONTROL_SIZE );
264 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
265 DALI_TEST_CHECK( button );
267 button.DoAction( "buttonClick", attributes );
269 // Force to update the model.
270 controller->GetNaturalSize();
272 controller->GetText( text );
273 DALI_TEST_CHECK( text.empty() );
276 controller->SetText( "Hello world" );
278 // Select the whole text.
279 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
280 DALI_TEST_CHECK( button );
282 button.DoAction( "buttonClick", attributes );
284 // Call relayout to process the input events.
285 controller->Relayout( CONTROL_SIZE );
287 // Copy to the clipboard.
288 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_COPY ) );
289 DALI_TEST_CHECK( button );
291 button.DoAction( "buttonClick", attributes );
293 // Call relayout to process the input events.
294 controller->Relayout( CONTROL_SIZE );
297 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
298 DALI_TEST_CHECK( button );
300 button.DoAction( "buttonClick", attributes );
302 // Force to update the model.
303 controller->GetNaturalSize();
305 controller->GetText( text );
306 DALI_TEST_CHECK( text.empty() );
308 ClipboardEventNotifier clipboardEventNotifier = ClipboardEventNotifier::Get();
309 clipboardEventNotifier.ContentSelectedSignal().Connect( &ContentSelectedCallback );
312 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_PASTE ) );
313 DALI_TEST_CHECK( button );
315 button.DoAction( "buttonClick", attributes );
317 // Call relayout to process the input events.
318 controller->Relayout( CONTROL_SIZE );
320 DALI_TEST_EQUALS( "Hello world", gClipboardText, TEST_LOCATION );
322 // Show the clipboard.
323 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CLIPBOARD ) );
324 DALI_TEST_CHECK( button );
326 button.DoAction( "buttonClick", attributes );
328 tet_result(TET_PASS);
332 int UtcDaliTextControllerGetInputShadowProperty(void)
334 tet_infoline(" UtcDaliTextControllerGetInputShadowProperty");
335 ToolkitTestApplication application;
337 // Creates a text controller.
338 ControllerPtr controller = Controller::New();
340 DALI_TEST_CHECK( controller );
342 const std::string& shadowProperties = controller->GetInputShadowProperties();
344 DALI_TEST_CHECK( shadowProperties.empty() );
346 tet_result(TET_PASS);
350 int UtcDaliTextControllerGetInputUnderlineProperty(void)
352 tet_infoline(" UtcDaliTextControllerGetInputUnderlineProperty");
353 ToolkitTestApplication application;
355 // Creates a text controller.
356 ControllerPtr controller = Controller::New();
358 DALI_TEST_CHECK( controller );
360 const std::string& underlineProperties = controller->GetInputUnderlineProperties();
362 DALI_TEST_CHECK( underlineProperties.empty() );
364 tet_result(TET_PASS);