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.
20 #include <dali/devel-api/rendering/renderer.h>
21 #include <dali/integration-api/events/key-event-integ.h>
22 #include <dali/integration-api/events/tap-gesture-event.h>
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit/devel-api/controls/text-controls/text-editor.h> ///< @todo to be removed when text-editor is added to the dali-toolkit.h
26 #include <dali-toolkit/devel-api/styling/style-manager.h>
29 using namespace Toolkit;
31 void dali_texteditor_startup(void)
33 test_return_value = TET_UNDEF;
36 void dali_texteditor_cleanup(void)
38 test_return_value = TET_PASS;
44 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
45 const char* const PROPERTY_NAME_TEXT = "text";
46 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
47 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
48 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
49 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
50 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
51 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
52 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
53 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
54 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
55 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
56 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
57 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
58 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
59 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
60 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
61 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
62 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
68 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
69 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
70 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
71 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
72 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
73 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
75 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
77 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
79 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
80 const float TO_MILLISECONDS = 1000.f;
81 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
83 const float SCROLL_THRESHOLD = 10.f;
84 const float SCROLL_SPEED = 300.f;
86 static bool gTextChangedCallBackCalled;
88 static void TestTextChangedCallback( TextEditor control )
90 tet_infoline(" TestTextChangedCallback");
92 gTextChangedCallBackCalled = true;
95 // Generate a TapGestureEvent to send to Core.
96 Integration::TapGestureEvent GenerateTap(
98 unsigned int numberOfTaps,
99 unsigned int numberOfTouches,
102 Integration::TapGestureEvent tap( state );
104 tap.numberOfTaps = numberOfTaps;
105 tap.numberOfTouches = numberOfTouches;
111 // Generate a KeyEvent to send to Core.
112 Integration::KeyEvent GenerateKey( const std::string& keyName,
113 const std::string& keyString,
116 unsigned long timeStamp,
117 const Integration::KeyEvent::State& keyState )
119 return Integration::KeyEvent( keyName,
129 int UtcDaliToolkitTextEditorConstructorP(void)
131 ToolkitTestApplication application;
132 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
133 TextEditor textEditor;
134 DALI_TEST_CHECK( !textEditor );
138 int UtcDaliToolkitTextEditorNewP(void)
140 ToolkitTestApplication application;
141 tet_infoline(" UtcDaliToolkitTextEditorNewP");
142 TextEditor textEditor = TextEditor::New();
143 DALI_TEST_CHECK( textEditor );
147 int UtcDaliToolkitTextEditorDownCastP(void)
149 ToolkitTestApplication application;
150 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
151 TextEditor textEditor1 = TextEditor::New();
152 BaseHandle object( textEditor1 );
154 TextEditor textEditor2 = TextEditor::DownCast( object );
155 DALI_TEST_CHECK( textEditor2 );
157 TextEditor textEditor3 = DownCast< TextEditor >( object );
158 DALI_TEST_CHECK( textEditor3 );
162 int UtcDaliToolkitTextEditorDownCastN(void)
164 ToolkitTestApplication application;
165 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
166 BaseHandle uninitializedObject;
167 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
168 DALI_TEST_CHECK( !textEditor1 );
170 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
171 DALI_TEST_CHECK( !textEditor2 );
175 int UtcDaliToolkitTextEditorCopyConstructorP(void)
177 ToolkitTestApplication application;
178 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
179 TextEditor textEditor = TextEditor::New();
180 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
182 TextEditor copy( textEditor );
183 DALI_TEST_CHECK( copy );
184 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textEditor.GetProperty<std::string>( TextLabel::Property::TEXT ) );
188 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
190 ToolkitTestApplication application;
191 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
192 TextEditor textEditor = TextEditor::New();
193 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
195 TextEditor copy = textEditor;
196 DALI_TEST_CHECK( copy );
197 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
201 int UtcDaliTextEditorNewP(void)
203 ToolkitTestApplication application;
204 tet_infoline(" UtcDaliToolkitTextEditorNewP");
205 TextEditor textEditor = TextEditor::New();
206 DALI_TEST_CHECK( textEditor );
210 // Positive test case for a method
211 int UtcDaliTextEditorGetPropertyP(void)
213 ToolkitTestApplication application;
214 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
215 TextEditor editor = TextEditor::New();
216 DALI_TEST_CHECK( editor );
218 // Check Property Indices are correct
219 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
220 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
221 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
222 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
223 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
224 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
225 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
226 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
227 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
228 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
229 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
230 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
231 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
232 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
233 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
234 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
235 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
236 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
237 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
238 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
239 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
240 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
241 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
242 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
243 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
244 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
245 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
246 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
247 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
248 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
252 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
255 Property::Map imageMap;
256 imageMap[mapKey] =mapValue;
258 editor.SetProperty( property , imageMap );
259 Property::Value propValue = editor.GetProperty( property );
260 Property::Map* resultMap = propValue.GetMap();
262 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
270 // Positive test case for a method
271 int UtcDaliTextEditorSetPropertyP(void)
273 ToolkitTestApplication application;
274 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
275 TextEditor editor = TextEditor::New();
276 DALI_TEST_CHECK( editor );
277 Stage::GetCurrent().Add( editor );
279 // Note - we can't check the defaults since the stylesheets are platform-specific
281 // Check the render backend property.
282 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
283 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
285 // Check text property.
286 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
287 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
289 // Check text's color property
290 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
291 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
293 // Check font properties.
294 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
295 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
296 editor.SetProperty( TextEditor::Property::FONT_STYLE, "Setting font style" );
297 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("Setting font style"), TEST_LOCATION );
298 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
299 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
301 // Check that the Alignment properties can be correctly set
302 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
303 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
305 // Check scroll properties.
306 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
307 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
308 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
309 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
311 // Check cursor properties
312 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
313 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
314 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
315 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
317 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
318 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
319 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
320 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
321 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
322 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
323 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
324 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
326 // Check handle images
327 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
328 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
329 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
330 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
331 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
333 // Check handle images
334 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
335 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
336 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
337 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
338 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
339 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
341 // Check the highlight color
342 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
343 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
345 // Decoration bounding box
346 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
347 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
349 // Check the enable markup property.
350 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
351 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
352 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
354 // Check input color property.
355 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
356 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
358 // Check input font properties.
359 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
360 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
361 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "Setting input font style" );
362 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "Setting input font style", TEST_LOCATION );
363 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
364 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
369 // Positive Atlas Text Renderer test
370 int utcDaliTextEditorAtlasRenderP(void)
372 ToolkitTestApplication application;
373 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
374 StyleManager styleManager = StyleManager::Get();
375 styleManager.RequestDefaultTheme();
376 TextEditor editor = TextEditor::New();
377 DALI_TEST_CHECK( editor );
379 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
381 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
383 Stage::GetCurrent().Add( editor );
387 // Render some text with the shared atlas backend
388 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
389 application.SendNotification();
390 application.Render();
394 tet_result(TET_FAIL);
399 // Positive test for the textChanged signal.
400 int utcDaliTextEditorTextChangedP(void)
402 ToolkitTestApplication application;
403 tet_infoline(" utcDaliTextEditorTextChangedP");
404 TextEditor editor = TextEditor::New();
405 DALI_TEST_CHECK( editor );
407 Stage::GetCurrent().Add( editor );
409 editor.TextChangedSignal().Connect(&TestTextChangedCallback);
411 gTextChangedCallBackCalled = false;
412 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
413 DALI_TEST_CHECK( gTextChangedCallBackCalled );
415 application.SendNotification();
417 editor.SetKeyInputFocus();
419 gTextChangedCallBackCalled = false;
420 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
421 DALI_TEST_CHECK( gTextChangedCallBackCalled );
426 int utcDaliTextEditorEvent01(void)
428 ToolkitTestApplication application;
429 tet_infoline(" utcDaliTextEditorEvent01");
431 // Creates a tap event. After creating a tap event the text editor should
432 // have the focus and add text with key events should be possible.
434 TextEditor editor = TextEditor::New();
435 DALI_TEST_CHECK( editor );
437 Stage::GetCurrent().Add( editor );
439 editor.SetSize( 300.f, 50.f );
440 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
441 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
443 // Avoid a crash when core load gl resources.
444 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
447 application.SendNotification();
448 application.Render();
450 // Add a key event but as the text editor has not the focus it should do nothing.
451 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
454 application.SendNotification();
455 application.Render();
457 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
459 // Create a tap event to touch the text editor.
460 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
461 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
464 application.SendNotification();
465 application.Render();
467 // Now the text editor has the focus, so it can handle the key events.
468 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
469 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
472 application.SendNotification();
473 application.Render();
475 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
477 // Create a second text editor and send key events to it.
478 TextEditor editor2 = TextEditor::New();
480 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
481 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
482 editor2.SetSize( 100.f, 100.f );
483 editor2.SetPosition( 100.f, 100.f );
485 Stage::GetCurrent().Add( editor2 );
488 application.SendNotification();
489 application.Render();
491 // Create a tap event on the second text editor.
492 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
493 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
496 application.SendNotification();
497 application.Render();
499 // The second text editor has the focus. It should handle the key events.
500 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
501 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
504 application.SendNotification();
505 application.Render();
507 // Check the text has been added to the second text editor.
508 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
513 int utcDaliTextEditorEvent02(void)
515 ToolkitTestApplication application;
516 tet_infoline(" utcDaliTextEditorEvent02");
518 // Checks if the right number of actors are created.
520 TextEditor editor = TextEditor::New();
521 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
522 DALI_TEST_CHECK( editor );
524 Stage::GetCurrent().Add( editor );
526 editor.SetSize( 300.f, 50.f );
527 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
528 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
530 // Avoid a crash when core load gl resources.
531 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
534 application.SendNotification();
535 application.Render();
537 // Check there are the expected number of children ( active layer, offscreen root actor, and the offscreen image actor
538 DALI_TEST_EQUALS( editor.GetChildCount(), 3u, TEST_LOCATION );
540 Actor layer = editor.GetChildAt( 0u );
541 DALI_TEST_CHECK( layer.IsLayer() );
543 Actor offscreenRoot = editor.GetChildAt( 1u );
544 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
545 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
547 Actor offscreenImage = editor.GetChildAt( 2u );
548 DALI_TEST_CHECK( offscreenImage );
550 // Create a tap event to touch the text editor.
551 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
552 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
555 application.SendNotification();
556 application.Render();
558 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
559 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
561 // Now the text editor has the focus, so it can handle the key events.
562 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
563 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
566 application.SendNotification();
567 application.Render();
569 // Checks the cursor and the renderer have been created.
570 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
571 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
573 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
574 DALI_TEST_CHECK( cursor );
576 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
577 DALI_TEST_CHECK( camera );
579 Renderer renderer = offscreenRoot.GetChildAt( 1u ).GetRendererAt( 0u );
580 DALI_TEST_CHECK( renderer );
582 // Move the cursor and check the position changes.
583 Vector3 position1 = cursor.GetCurrentPosition();
585 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
586 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
589 application.SendNotification();
590 application.Render();
592 Vector3 position2 = cursor.GetCurrentPosition();
594 DALI_TEST_CHECK( position2.x < position1.x );
596 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
597 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
600 application.SendNotification();
601 application.Render();
603 Vector3 position3 = cursor.GetCurrentPosition();
605 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
607 // Send some taps and check the cursor positions.
609 // Try to tap at the beginning.
610 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
611 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
614 application.SendNotification();
615 application.Render();
617 // Cursor position should be the same than position1.
618 Vector3 position4 = cursor.GetCurrentPosition();
620 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
622 // Tap away from the start position.
623 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
624 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
627 application.SendNotification();
628 application.Render();
630 Vector3 position5 = cursor.GetCurrentPosition();
632 DALI_TEST_CHECK( position5.x > position4.x );
634 // Remove all the text.
635 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
636 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
637 editor.SetProperty( TextEditor::Property::TEXT, "" );
640 application.SendNotification();
641 application.Render();
643 // Cursor position should be the same than position2.
644 Vector3 position6 = cursor.GetCurrentPosition();
646 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
648 // Should not be a renderer.
649 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
654 int utcDaliTextEditorEvent03(void)
656 ToolkitTestApplication application;
657 tet_infoline(" utcDaliTextEditorEvent03");
659 // Checks if the highlight actor is created.
661 TextEditor editor = TextEditor::New();
662 DALI_TEST_CHECK( editor );
664 Stage::GetCurrent().Add( editor );
666 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
667 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
668 editor.SetSize( 30.f, 50.f );
669 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
670 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
672 // Avoid a crash when core load gl resources.
673 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
676 application.SendNotification();
677 application.Render();
679 // Tap first to get the focus.
680 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
681 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
684 application.SendNotification();
685 application.Render();
687 // Double tap to select a word.
688 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
689 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
692 application.SendNotification();
693 application.Render();
695 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
696 Actor offscreenRoot = editor.GetChildAt( 1u );
697 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
699 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
700 DALI_TEST_CHECK( camera );
702 Renderer renderer = offscreenRoot.GetChildAt( 1u ).GetRendererAt( 0u );
703 DALI_TEST_CHECK( renderer );
705 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
706 DALI_TEST_CHECK( highlight );