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>
28 using namespace Toolkit;
34 const char* const OPTION_SELECT_WORD("option-select_word"); // "Select Word" popup option.
35 const char* const OPTION_SELECT_ALL("option-select_all"); // "Select All" popup option.
36 const char* const OPTION_CUT("optionCut"); // "Cut" popup option.
37 const char* const OPTION_COPY("optionCopy"); // "Copy" popup option.
38 const char* const OPTION_PASTE("optionPaste"); // "Paste" popup option.
39 const char* const OPTION_CLIPBOARD("optionClipboard"); // "Clipboard" popup option.
41 const Size CONTROL_SIZE( 300.f, 60.f );
43 class ControlImpl : public ControlInterface
50 virtual ~ControlImpl()
53 virtual void AddDecoration( Actor& actor, bool needsClipping )
56 virtual void RequestTextRelayout()
59 virtual void TextChanged()
62 virtual void MaxLengthReached()
65 virtual void InputStyleChanged( InputStyle::Mask inputStyleMask )
69 std::string gClipboardText;
70 void ContentSelectedCallback( ClipboardEventNotifier& notifier )
72 gClipboardText = notifier.GetContent();
77 int UtcDaliTextController(void)
79 tet_infoline(" UtcDaliTextController");
80 ToolkitTestApplication application;
82 // Creates a text controller.
83 ControlImpl controlImpl;
84 ControllerPtr controller = Controller::New( controlImpl );
86 DALI_TEST_CHECK( controller );
92 int UtcDaliTextControllerEnableCursorBlinking(void)
94 tet_infoline(" UtcDaliTextControllerEnableCursorBlinking");
95 ToolkitTestApplication application;
97 // Creates a text controller.
98 ControlImpl controlImpl;
99 ControllerPtr controller = Controller::New( controlImpl );
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 ControlImpl controlImpl;
135 ControllerPtr controller = Controller::New( controlImpl );
138 ImfManager::ImfEventData imfEvent;
140 DALI_TEST_CHECK( controller );
142 // Enable the text input.
143 // Creates a decorator.
144 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
147 // Enables the text input.
148 controller->EnableTextInput( decorator );
150 // Creates an ImfManager.
151 ImfManager imfManager = ImfManager::Get();
154 imfEvent = ImfManager::ImfEventData( ImfManager::VOID, "", 0, 0 );
155 controller->OnImfEvent( imfManager, imfEvent );
157 controller->GetText( text );
158 DALI_TEST_CHECK( text.empty() );
160 // Send COMMIT event.
161 imfEvent = ImfManager::ImfEventData( ImfManager::COMMIT, "Hello ", 0, 6 );
162 controller->OnImfEvent( imfManager, imfEvent );
164 // Force to update the model.
165 controller->GetNaturalSize();
167 controller->GetText( text );
168 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
170 // Send PREEDIT event
171 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "w", 6, 1 );
172 controller->OnImfEvent( imfManager, imfEvent );
174 // Force to update the model.
175 controller->GetNaturalSize();
177 controller->GetText( text );
178 DALI_TEST_EQUALS( "Hello w", text, TEST_LOCATION );
180 // Send DELETESURROUNDING event
181 imfEvent = ImfManager::ImfEventData( ImfManager::DELETESURROUNDING, "", -1, 1 );
182 controller->OnImfEvent( imfManager, imfEvent );
184 // Force to update the model.
185 controller->GetNaturalSize();
187 controller->GetText( text );
188 DALI_TEST_EQUALS( "Hello ", text, TEST_LOCATION );
190 // Send PREEDIT event
191 imfEvent = ImfManager::ImfEventData( ImfManager::PREEDIT, "wo", 6, 2 );
192 controller->OnImfEvent( imfManager, imfEvent );
194 // Force to update the model.
195 controller->GetNaturalSize();
197 controller->GetText( text );
198 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
200 // Send GETSURROUNDING event
201 imfEvent = ImfManager::ImfEventData( ImfManager::GETSURROUNDING, "", 0, 0 );
202 controller->OnImfEvent( imfManager, imfEvent );
204 controller->GetText( text );
205 DALI_TEST_EQUALS( "Hello wo", text, TEST_LOCATION );
207 tet_result(TET_PASS);
211 int UtcDaliTextControllerTextPopupButtonTouched(void)
213 tet_infoline(" UtcDaliTextControllerTextPopupButtonTouched");
214 ToolkitTestApplication application;
216 // Creates a text controller.
217 ControlImpl controlImpl;
218 ControllerPtr controller = Controller::New( controlImpl );
220 DALI_TEST_CHECK( controller );
224 Property::Map attributes;
226 // Enable the text input.
227 // Creates a decorator.
228 Text::DecoratorPtr decorator = Text::Decorator::New( *controller,
231 // Enables the text input.
232 controller->EnableTextInput( decorator );
234 // Creates the text's popup.
235 TextSelectionPopupCallbackInterface& callbackInterface = *controller;
236 TextSelectionPopup textPopup = TextSelectionPopup::New( &callbackInterface );
238 Toolkit::TextSelectionPopup::Buttons buttonsToEnable = static_cast<Toolkit::TextSelectionPopup::Buttons>( TextSelectionPopup::CUT |
239 TextSelectionPopup::COPY |
240 TextSelectionPopup::PASTE |
241 TextSelectionPopup::SELECT |
242 TextSelectionPopup::SELECT_ALL |
243 TextSelectionPopup::CLIPBOARD );
245 textPopup.EnableButtons( buttonsToEnable );
246 Stage::GetCurrent().Add( textPopup );
247 textPopup.ShowPopup();
250 application.SendNotification();
251 application.Render();
254 controller->SetText( "Hello world" );
256 // Select the whole text.
257 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
258 DALI_TEST_CHECK( button );
260 button.DoAction( "buttonClick", attributes );
262 // Call relayout to process the input events.
263 controller->Relayout( CONTROL_SIZE );
266 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
267 DALI_TEST_CHECK( button );
269 button.DoAction( "buttonClick", attributes );
271 // Force to update the model.
272 controller->GetNaturalSize();
274 controller->GetText( text );
275 DALI_TEST_CHECK( text.empty() );
278 controller->SetText( "Hello world" );
280 // Select the whole text.
281 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_SELECT_ALL ) );
282 DALI_TEST_CHECK( button );
284 button.DoAction( "buttonClick", attributes );
286 // Call relayout to process the input events.
287 controller->Relayout( CONTROL_SIZE );
289 // Copy to the clipboard.
290 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_COPY ) );
291 DALI_TEST_CHECK( button );
293 button.DoAction( "buttonClick", attributes );
295 // Call relayout to process the input events.
296 controller->Relayout( CONTROL_SIZE );
299 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CUT ) );
300 DALI_TEST_CHECK( button );
302 button.DoAction( "buttonClick", attributes );
304 // Force to update the model.
305 controller->GetNaturalSize();
307 controller->GetText( text );
308 DALI_TEST_CHECK( text.empty() );
310 ClipboardEventNotifier clipboardEventNotifier = ClipboardEventNotifier::Get();
311 clipboardEventNotifier.ContentSelectedSignal().Connect( &ContentSelectedCallback );
314 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_PASTE ) );
315 DALI_TEST_CHECK( button );
317 button.DoAction( "buttonClick", attributes );
319 // Call relayout to process the input events.
320 controller->Relayout( CONTROL_SIZE );
322 DALI_TEST_EQUALS( "Hello world", gClipboardText, TEST_LOCATION );
324 // Show the clipboard.
325 button = PushButton::DownCast( textPopup.FindChildByName( OPTION_CLIPBOARD ) );
326 DALI_TEST_CHECK( button );
328 button.DoAction( "buttonClick", attributes );
330 tet_result(TET_PASS);