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.
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/devel-api/adaptor-framework/clipboard.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali-toolkit-test-suite-utils.h>
27 #include <dali-toolkit/dali-toolkit.h>
28 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
31 using namespace Toolkit;
33 void dali_texteditor_startup(void)
35 test_return_value = TET_UNDEF;
38 void dali_texteditor_cleanup(void)
40 test_return_value = TET_PASS;
46 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
47 const char* const PROPERTY_NAME_TEXT = "text";
48 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
49 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
50 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
51 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
52 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
53 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
54 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
55 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
56 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
57 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
58 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
59 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
60 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
61 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
62 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
68 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
69 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
70 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
71 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
72 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
73 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
74 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
75 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
77 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
78 const char* const PROPERTY_NAME_INPUT_LINE_SPACING = "inputLineSpacing";
79 const char* const PROPERTY_NAME_UNDERLINE = "underline";
80 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
81 const char* const PROPERTY_NAME_SHADOW = "shadow";
82 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
83 const char* const PROPERTY_NAME_EMBOSS = "emboss";
84 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
85 const char* const PROPERTY_NAME_OUTLINE = "outline";
86 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
88 const char* const PROPERTY_NAME_SMOOTH_SCROLL = "smoothScroll";
89 const char* const PROPERTY_NAME_SMOOTH_SCROLL_DURATION = "smoothScrollDuration";
91 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
93 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
95 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
96 const float TO_MILLISECONDS = 1000.f;
97 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
99 const float SCROLL_THRESHOLD = 10.f;
100 const float SCROLL_SPEED = 300.f;
102 const unsigned int DEFAULT_FONT_SIZE = 1152u;
103 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
105 static bool gTextChangedCallBackCalled;
106 static bool gInputStyleChangedCallbackCalled;
107 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
109 struct CallbackFunctor
111 CallbackFunctor(bool* callbackFlag)
112 : mCallbackFlag( callbackFlag )
118 *mCallbackFlag = true;
123 static void TestTextChangedCallback( TextEditor control )
125 tet_infoline(" TestTextChangedCallback");
127 gTextChangedCallBackCalled = true;
130 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
132 tet_infoline(" TestInputStyleChangedCallback");
134 gInputStyleChangedCallbackCalled = true;
135 gInputStyleMask = mask;
138 // Generate a TapGestureEvent to send to Core.
139 Integration::TapGestureEvent GenerateTap(
140 Gesture::State state,
141 unsigned int numberOfTaps,
142 unsigned int numberOfTouches,
145 Integration::TapGestureEvent tap( state );
147 tap.numberOfTaps = numberOfTaps;
148 tap.numberOfTouches = numberOfTouches;
154 // Generate a KeyEvent to send to Core.
155 Integration::KeyEvent GenerateKey( const std::string& keyName,
156 const std::string& keyString,
159 unsigned long timeStamp,
160 const Integration::KeyEvent::State& keyState )
162 return Integration::KeyEvent( keyName,
170 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
172 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
174 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
176 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
178 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
179 if( NULL != valueSet )
181 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
183 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
189 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
200 int UtcDaliToolkitTextEditorConstructorP(void)
202 ToolkitTestApplication application;
203 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
204 TextEditor textEditor;
205 DALI_TEST_CHECK( !textEditor );
209 int UtcDaliToolkitTextEditorNewP(void)
211 ToolkitTestApplication application;
212 tet_infoline(" UtcDaliToolkitTextEditorNewP");
213 TextEditor textEditor = TextEditor::New();
214 DALI_TEST_CHECK( textEditor );
218 int UtcDaliToolkitTextEditorDownCastP(void)
220 ToolkitTestApplication application;
221 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
222 TextEditor textEditor1 = TextEditor::New();
223 BaseHandle object( textEditor1 );
225 TextEditor textEditor2 = TextEditor::DownCast( object );
226 DALI_TEST_CHECK( textEditor2 );
228 TextEditor textEditor3 = DownCast< TextEditor >( object );
229 DALI_TEST_CHECK( textEditor3 );
233 int UtcDaliToolkitTextEditorDownCastN(void)
235 ToolkitTestApplication application;
236 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
237 BaseHandle uninitializedObject;
238 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
239 DALI_TEST_CHECK( !textEditor1 );
241 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
242 DALI_TEST_CHECK( !textEditor2 );
246 int UtcDaliToolkitTextEditorCopyConstructorP(void)
248 ToolkitTestApplication application;
249 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
250 TextEditor textEditor = TextEditor::New();
251 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
253 TextEditor copy( textEditor );
254 DALI_TEST_CHECK( copy );
255 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
259 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
261 ToolkitTestApplication application;
262 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
263 TextEditor textEditor = TextEditor::New();
264 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
266 TextEditor copy = textEditor;
267 DALI_TEST_CHECK( copy );
268 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
272 int UtcDaliTextEditorNewP(void)
274 ToolkitTestApplication application;
275 tet_infoline(" UtcDaliToolkitTextEditorNewP");
276 TextEditor textEditor = TextEditor::New();
277 DALI_TEST_CHECK( textEditor );
281 // Positive test case for a method
282 int UtcDaliTextEditorGetPropertyP(void)
284 ToolkitTestApplication application;
285 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
286 TextEditor editor = TextEditor::New();
287 DALI_TEST_CHECK( editor );
289 // Check Property Indices are correct
290 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
291 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
292 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
293 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
294 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
295 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
296 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
297 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
298 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
299 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
300 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
301 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
302 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
303 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
304 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
305 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
306 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
307 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
308 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
309 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
310 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
311 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
312 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
313 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
314 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
315 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
316 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
317 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
318 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
319 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
321 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
322 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
323 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
324 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
325 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
326 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
327 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
328 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
329 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
330 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
331 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
332 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
337 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
340 Property::Map imageMap;
341 imageMap[mapKey] =mapValue;
343 editor.SetProperty( property , imageMap );
344 Property::Value propValue = editor.GetProperty( property );
345 Property::Map* resultMap = propValue.GetMap();
347 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
355 // Positive test case for a method
356 int UtcDaliTextEditorSetPropertyP(void)
358 ToolkitTestApplication application;
359 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
360 TextEditor editor = TextEditor::New();
361 DALI_TEST_CHECK( editor );
362 Stage::GetCurrent().Add( editor );
364 // Note - we can't check the defaults since the stylesheets are platform-specific
366 // Check the render backend property.
367 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
368 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
370 // Check text property.
371 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
372 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
374 // Check text's color property
375 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
376 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
378 // Check font properties.
379 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
380 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
382 Property::Map fontStyleMapSet;
383 Property::Map fontStyleMapGet;
384 Property::Value* slantValue = NULL;
386 fontStyleMapSet.Insert( "weight", "bold" );
387 fontStyleMapSet.Insert( "width", "condensed" );
388 fontStyleMapSet.Insert( "slant", "italic" );
390 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
391 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
392 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
393 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
395 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
396 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
399 fontStyleMapSet.Clear();
400 fontStyleMapSet.Insert( "weight", "normal" );
401 fontStyleMapSet.Insert( "slant", "oblique" );
402 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
403 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
404 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
405 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
407 fontStyleMapSet.Clear();
408 fontStyleMapSet.Insert( "slant", "roman" );
409 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
410 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
412 // Replace 'roman' for 'normal'.
413 slantValue = fontStyleMapGet.Find( "slant" );
414 if( NULL != slantValue )
416 if( "normal" == slantValue->Get<std::string>() )
418 fontStyleMapGet["slant"] = "roman";
421 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
422 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
424 fontStyleMapSet.Clear();
426 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
427 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
428 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
429 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
431 // Check that the Alignment properties can be correctly set
432 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
433 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
435 // Check scroll properties.
436 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
437 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
438 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
439 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
441 // Check cursor properties
442 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
443 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
444 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
445 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
447 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
448 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
449 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
450 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
451 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
452 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
453 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
454 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
456 // Check handle images
457 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
458 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
459 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
460 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
461 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
463 // Check handle images
464 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
465 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
466 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
467 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
468 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
469 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
471 // Check the highlight color
472 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
473 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
475 // Decoration bounding box
476 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
477 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
479 // Check the enable markup property.
480 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
481 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
482 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
484 // Check input color property.
485 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
486 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
488 // Check input font properties.
489 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
490 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
492 fontStyleMapSet.Clear();
493 fontStyleMapSet.Insert( "weight", "bold" );
494 fontStyleMapSet.Insert( "width", "condensed" );
495 fontStyleMapSet.Insert( "slant", "italic" );
497 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
498 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
499 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
500 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
502 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
503 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
505 // Reset input font style.
506 fontStyleMapSet.Clear();
507 fontStyleMapSet.Insert( "weight", "normal" );
508 fontStyleMapSet.Insert( "slant", "oblique" );
510 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
511 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
512 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
513 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
515 fontStyleMapSet.Clear();
516 fontStyleMapSet.Insert( "slant", "roman" );
518 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
519 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
521 // Replace 'roman' for 'normal'.
522 slantValue = fontStyleMapGet.Find( "slant" );
523 if( NULL != slantValue )
525 if( "normal" == slantValue->Get<std::string>() )
527 fontStyleMapGet["slant"] = "roman";
530 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
531 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
533 fontStyleMapSet.Clear();
535 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
536 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
537 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
538 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
540 // Check the line spacing property
541 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
542 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
543 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
545 // Check the input line spacing property
546 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
547 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
548 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
550 // Check the underline property
552 Property::Map underlineMapSet;
553 Property::Map underlineMapGet;
555 underlineMapSet.Insert( "enable", "true" );
556 underlineMapSet.Insert( "color", "red" );
557 underlineMapSet.Insert( "height", "1" );
559 editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
561 underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
562 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
563 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
565 // Check the input underline property
566 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
567 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
569 // Check the shadow property
570 Property::Map shadowMapSet;
571 Property::Map shadowMapGet;
573 shadowMapSet.Insert( "color", "green" );
574 shadowMapSet.Insert( "offset", "2 2" );
576 editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
578 shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
579 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
580 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
582 // Check the input shadow property
583 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
584 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
586 // Check the emboss property
587 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
588 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
590 // Check the input emboss property
591 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
592 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
594 // Check the outline property
595 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
596 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
598 // Check the input outline property
599 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
600 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
602 // Check the smooth scroll property
603 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
604 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
605 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
607 // Check the smooth scroll duration property
608 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
609 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
614 // Positive Atlas Text Renderer test
615 int utcDaliTextEditorAtlasRenderP(void)
617 ToolkitTestApplication application;
618 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
619 StyleManager styleManager = StyleManager::Get();
620 styleManager.ApplyDefaultTheme();
621 TextEditor editor = TextEditor::New();
622 DALI_TEST_CHECK( editor );
624 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
626 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
628 Stage::GetCurrent().Add( editor );
632 // Render some text with the shared atlas backend
633 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
634 application.SendNotification();
635 application.Render();
639 tet_result(TET_FAIL);
644 // Positive test for the textChanged signal.
645 int utcDaliTextEditorTextChangedP(void)
647 ToolkitTestApplication application;
648 tet_infoline(" utcDaliTextEditorTextChangedP");
649 TextEditor editor = TextEditor::New();
650 DALI_TEST_CHECK( editor );
652 Stage::GetCurrent().Add( editor );
654 // connect to the text changed signal.
655 ConnectionTracker* testTracker = new ConnectionTracker();
656 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
657 bool textChangedSignal = false;
658 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
660 gTextChangedCallBackCalled = false;
661 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
662 DALI_TEST_CHECK( gTextChangedCallBackCalled );
663 DALI_TEST_CHECK( textChangedSignal );
665 application.SendNotification();
667 editor.SetKeyInputFocus();
669 gTextChangedCallBackCalled = false;
670 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
671 DALI_TEST_CHECK( gTextChangedCallBackCalled );
676 int utcDaliTextEditorInputStyleChanged01(void)
678 ToolkitTestApplication application;
679 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
681 // The text-editor emits signals when the input style changes. These changes of style are
682 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
683 // can't be emitted during the size negotiation as the callbacks may update the UI.
684 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
685 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
686 application.CreateAdaptor();
690 char* pathNamePtr = get_current_dir_name();
691 const std::string pathName( pathNamePtr );
694 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
695 fontClient.SetDpi( 93u, 93u );
697 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
698 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
700 TextEditor editor = TextEditor::New();
701 DALI_TEST_CHECK( editor );
704 editor.SetSize( 300.f, 50.f );
705 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
706 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
708 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
709 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
711 // connect to the text changed signal.
712 ConnectionTracker* testTracker = new ConnectionTracker();
713 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
714 bool inputStyleChangedSignal = false;
715 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
717 Stage::GetCurrent().Add( editor );
720 application.SendNotification();
721 application.Render();
723 // Executes the idle callbacks added by the text control on the change of input style.
724 application.RunIdles();
726 gInputStyleChangedCallbackCalled = false;
727 gInputStyleMask = TextEditor::InputStyle::NONE;
728 inputStyleChangedSignal = false;
730 // Create a tap event to touch the text editor.
731 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
732 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
735 application.SendNotification();
736 application.Render();
738 // Executes the idle callbacks added by the text control on the change of input style.
739 application.RunIdles();
741 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
742 if( gInputStyleChangedCallbackCalled )
744 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
746 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
747 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
749 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
750 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
752 DALI_TEST_CHECK( inputStyleChangedSignal );
754 gInputStyleChangedCallbackCalled = false;
755 gInputStyleMask = TextEditor::InputStyle::NONE;
756 inputStyleChangedSignal = false;
758 // Create a tap event to touch the text editor.
759 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
760 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
763 application.SendNotification();
764 application.Render();
766 // Executes the idle callbacks added by the text control on the change of input style.
767 application.RunIdles();
769 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
770 DALI_TEST_CHECK( !inputStyleChangedSignal );
772 gInputStyleChangedCallbackCalled = false;
773 gInputStyleMask = TextEditor::InputStyle::NONE;
774 inputStyleChangedSignal = false;
776 // Create a tap event to touch the text editor.
777 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
778 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
781 application.SendNotification();
782 application.Render();
784 // Executes the idle callbacks added by the text control on the change of input style.
785 application.RunIdles();
787 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
788 if( gInputStyleChangedCallbackCalled )
790 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
792 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
793 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
795 DALI_TEST_CHECK( inputStyleChangedSignal );
797 gInputStyleChangedCallbackCalled = false;
798 gInputStyleMask = TextEditor::InputStyle::NONE;
799 inputStyleChangedSignal = false;
801 // Create a tap event to touch the text editor.
802 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
803 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
806 application.SendNotification();
807 application.Render();
809 // Executes the idle callbacks added by the text control on the change of input style.
810 application.RunIdles();
812 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
813 if( gInputStyleChangedCallbackCalled )
815 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
817 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
818 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
820 Property::Map fontStyleMapSet;
821 Property::Map fontStyleMapGet;
823 fontStyleMapSet.Insert( "weight", "bold" );
825 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
826 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
827 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
829 DALI_TEST_CHECK( inputStyleChangedSignal );
831 gInputStyleChangedCallbackCalled = false;
832 gInputStyleMask = TextEditor::InputStyle::NONE;
833 inputStyleChangedSignal = false;
835 // Create a tap event to touch the text editor.
836 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
837 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
840 application.SendNotification();
841 application.Render();
843 // Executes the idle callbacks added by the text control on the change of input style.
844 application.RunIdles();
846 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
847 DALI_TEST_CHECK( !inputStyleChangedSignal );
849 gInputStyleChangedCallbackCalled = false;
850 gInputStyleMask = TextEditor::InputStyle::NONE;
851 inputStyleChangedSignal = false;
853 // Create a tap event to touch the text editor.
854 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
855 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
858 application.SendNotification();
859 application.Render();
861 // Executes the idle callbacks added by the text control on the change of input style.
862 application.RunIdles();
864 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
865 if( gInputStyleChangedCallbackCalled )
867 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
869 Property::Map fontStyleMapSet;
870 Property::Map fontStyleMapGet;
872 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
873 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
874 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
876 DALI_TEST_CHECK( inputStyleChangedSignal );
878 gInputStyleChangedCallbackCalled = false;
879 gInputStyleMask = TextEditor::InputStyle::NONE;
880 inputStyleChangedSignal = false;
882 // Create a tap event to touch the text editor.
883 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
884 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
887 application.SendNotification();
888 application.Render();
890 // Executes the idle callbacks added by the text control on the change of input style.
891 application.RunIdles();
893 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
894 DALI_TEST_CHECK( !inputStyleChangedSignal );
899 int utcDaliTextEditorInputStyleChanged02(void)
901 ToolkitTestApplication application;
902 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
904 // The text-editor emits signals when the input style changes. These changes of style are
905 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
906 // can't be emitted during the size negotiation as the callbacks may update the UI.
907 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
908 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
909 application.CreateAdaptor();
913 char* pathNamePtr = get_current_dir_name();
914 const std::string pathName( pathNamePtr );
917 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
918 fontClient.SetDpi( 93u, 93u );
920 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
921 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
923 TextEditor editor = TextEditor::New();
924 DALI_TEST_CHECK( editor );
927 editor.SetSize( 300.f, 50.f );
928 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
929 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
931 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
932 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='blue'> l</color><color value='green'>lo</color> <font weight='bold'>world</font> demo</font>" );
934 // connect to the text changed signal.
935 ConnectionTracker* testTracker = new ConnectionTracker();
936 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
937 bool inputStyleChangedSignal = false;
938 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
940 Stage::GetCurrent().Add( editor );
943 application.SendNotification();
944 application.Render();
946 // Executes the idle callbacks added by the text control on the change of input style.
947 application.RunIdles();
949 gInputStyleChangedCallbackCalled = false;
950 gInputStyleMask = TextEditor::InputStyle::NONE;
951 inputStyleChangedSignal = false;
953 // Create a tap event to touch the text editor.
954 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
955 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
956 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
957 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
960 application.SendNotification();
961 application.Render();
963 // Executes the idle callbacks added by the text control on the change of input style.
964 application.RunIdles();
966 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
967 if( gInputStyleChangedCallbackCalled )
969 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
970 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
971 TextEditor::InputStyle::POINT_SIZE |
972 TextEditor::InputStyle::COLOR ),
975 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
976 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
978 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
979 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
981 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
982 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
984 DALI_TEST_CHECK( inputStyleChangedSignal );
986 gInputStyleChangedCallbackCalled = false;
987 gInputStyleMask = TextEditor::InputStyle::NONE;
988 inputStyleChangedSignal = false;
990 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
993 application.SendNotification();
994 application.Render();
996 // Executes the idle callbacks added by the text control on the change of input style.
997 application.RunIdles();
999 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1000 if( gInputStyleChangedCallbackCalled )
1002 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1003 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1006 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1007 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1009 DALI_TEST_CHECK( inputStyleChangedSignal );
1011 gInputStyleChangedCallbackCalled = false;
1012 gInputStyleMask = TextEditor::InputStyle::NONE;
1013 inputStyleChangedSignal = false;
1015 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1017 // Render and notify
1018 application.SendNotification();
1019 application.Render();
1021 // Executes the idle callbacks added by the text control on the change of input style.
1022 application.RunIdles();
1024 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1025 DALI_TEST_CHECK( !inputStyleChangedSignal );
1027 gInputStyleChangedCallbackCalled = false;
1028 gInputStyleMask = TextEditor::InputStyle::NONE;
1029 inputStyleChangedSignal = false;
1031 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1033 // Render and notify
1034 application.SendNotification();
1035 application.Render();
1037 // Executes the idle callbacks added by the text control on the change of input style.
1038 application.RunIdles();
1040 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1041 if( gInputStyleChangedCallbackCalled )
1043 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1044 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1047 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1048 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1050 DALI_TEST_CHECK( inputStyleChangedSignal );
1052 gInputStyleChangedCallbackCalled = false;
1053 gInputStyleMask = TextEditor::InputStyle::NONE;
1054 inputStyleChangedSignal = false;
1056 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1058 Property::Map fontStyleMapSet;
1059 fontStyleMapSet.Insert( "weight", "thin" );
1060 fontStyleMapSet.Insert( "width", "condensed" );
1061 fontStyleMapSet.Insert( "slant", "italic" );
1063 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1064 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1065 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1067 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1068 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1069 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1070 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1072 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1074 // Render and notify
1075 application.SendNotification();
1076 application.Render();
1078 // Executes the idle callbacks added by the text control on the change of input style.
1079 application.RunIdles();
1081 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1082 DALI_TEST_CHECK( !inputStyleChangedSignal );
1084 // Create a tap event to touch the text editor.
1085 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1086 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1088 // Render and notify
1089 application.SendNotification();
1090 application.Render();
1092 // Executes the idle callbacks added by the text control on the change of input style.
1093 application.RunIdles();
1095 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1096 if( gInputStyleChangedCallbackCalled )
1098 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1099 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1100 TextEditor::InputStyle::POINT_SIZE |
1101 TextEditor::InputStyle::FONT_STYLE |
1102 TextEditor::InputStyle::LINE_SPACING |
1103 TextEditor::InputStyle::UNDERLINE |
1104 TextEditor::InputStyle::SHADOW |
1105 TextEditor::InputStyle::EMBOSS |
1106 TextEditor::InputStyle::OUTLINE ),
1109 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1110 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1112 DALI_TEST_CHECK( inputStyleChangedSignal );
1114 gInputStyleChangedCallbackCalled = false;
1115 gInputStyleMask = TextEditor::InputStyle::NONE;
1116 inputStyleChangedSignal = false;
1118 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1120 fontStyleMapSet.Clear();
1121 fontStyleMapSet.Insert( "weight", "black" );
1122 fontStyleMapSet.Insert( "width", "expanded" );
1123 fontStyleMapSet.Insert( "slant", "oblique" );
1125 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1127 // Create a tap event to touch the text editor.
1128 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1129 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1131 // Render and notify
1132 application.SendNotification();
1133 application.Render();
1135 // Executes the idle callbacks added by the text control on the change of input style.
1136 application.RunIdles();
1138 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1139 if( gInputStyleChangedCallbackCalled )
1141 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1142 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1143 TextEditor::InputStyle::POINT_SIZE |
1144 TextEditor::InputStyle::FONT_STYLE ),
1147 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1148 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1150 DALI_TEST_CHECK( inputStyleChangedSignal );
1155 int utcDaliTextEditorEvent01(void)
1157 ToolkitTestApplication application;
1158 tet_infoline(" utcDaliTextEditorEvent01");
1160 // Creates a tap event. After creating a tap event the text editor should
1161 // have the focus and add text with key events should be possible.
1163 TextEditor editor = TextEditor::New();
1164 DALI_TEST_CHECK( editor );
1166 Stage::GetCurrent().Add( editor );
1168 editor.SetSize( 300.f, 50.f );
1169 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1170 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1172 // Avoid a crash when core load gl resources.
1173 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1175 // Render and notify
1176 application.SendNotification();
1177 application.Render();
1179 // Add a key event but as the text editor has not the focus it should do nothing.
1180 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1182 // Render and notify
1183 application.SendNotification();
1184 application.Render();
1186 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1188 // Create a tap event to touch the text editor.
1189 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1190 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1192 // Render and notify
1193 application.SendNotification();
1194 application.Render();
1196 // Now the text editor has the focus, so it can handle the key events.
1197 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1198 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1200 // Render and notify
1201 application.SendNotification();
1202 application.Render();
1204 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1206 // Create a second text editor and send key events to it.
1207 TextEditor editor2 = TextEditor::New();
1209 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1210 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1211 editor2.SetSize( 100.f, 100.f );
1212 editor2.SetPosition( 100.f, 100.f );
1214 Stage::GetCurrent().Add( editor2 );
1216 // Render and notify
1217 application.SendNotification();
1218 application.Render();
1220 // Create a tap event on the second text editor.
1221 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1222 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1224 // Render and notify
1225 application.SendNotification();
1226 application.Render();
1228 // The second text editor has the focus. It should handle the key events.
1229 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1230 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1232 // Render and notify
1233 application.SendNotification();
1234 application.Render();
1236 // Check the text has been added to the second text editor.
1237 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1242 int utcDaliTextEditorEvent02(void)
1244 ToolkitTestApplication application;
1245 tet_infoline(" utcDaliTextEditorEvent02");
1247 // Checks if the right number of actors are created.
1249 TextEditor editor = TextEditor::New();
1250 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1251 DALI_TEST_CHECK( editor );
1253 Stage::GetCurrent().Add( editor );
1255 editor.SetSize( 300.f, 50.f );
1256 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1257 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1259 // Avoid a crash when core load gl resources.
1260 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1262 // Render and notify
1263 application.SendNotification();
1264 application.Render();
1266 // Check there are the expected number of children (the stencil).
1267 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1269 Actor stencil = editor.GetChildAt( 0u );
1271 // Create a tap event to touch the text editor.
1272 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1273 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1275 // Render and notify
1276 application.SendNotification();
1277 application.Render();
1279 Actor layer = editor.GetChildAt( 1u );
1280 DALI_TEST_CHECK( layer.IsLayer() );
1282 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1283 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1285 // Now the text editor has the focus, so it can handle the key events.
1286 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1287 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1289 // Render and notify
1290 application.SendNotification();
1291 application.Render();
1293 // Checks the cursor and the renderer have been created.
1294 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1295 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1297 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1298 DALI_TEST_CHECK( cursor );
1300 // The stencil actor has a container with all the actors which contain the text renderers.
1301 Actor container = stencil.GetChildAt( 0u );
1302 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1304 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1305 DALI_TEST_CHECK( renderer );
1308 // Move the cursor and check the position changes.
1309 Vector3 position1 = cursor.GetCurrentPosition();
1311 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1312 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1314 // Render and notify
1315 application.SendNotification();
1316 application.Render();
1318 Vector3 position2 = cursor.GetCurrentPosition();
1320 DALI_TEST_CHECK( position2.x < position1.x );
1322 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1323 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1325 // Render and notify
1326 application.SendNotification();
1327 application.Render();
1329 Vector3 position3 = cursor.GetCurrentPosition();
1331 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1333 // Send some taps and check the cursor positions.
1335 // Try to tap at the beginning.
1336 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1337 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1339 // Render and notify
1340 application.SendNotification();
1341 application.Render();
1343 // Cursor position should be the same than position1.
1344 Vector3 position4 = cursor.GetCurrentPosition();
1346 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1348 // Tap away from the start position.
1349 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1350 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1352 // Render and notify
1353 application.SendNotification();
1354 application.Render();
1356 Vector3 position5 = cursor.GetCurrentPosition();
1358 DALI_TEST_CHECK( position5.x > position4.x );
1360 // Remove all the text.
1361 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1362 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1363 editor.SetProperty( TextEditor::Property::TEXT, "" );
1365 // Render and notify
1366 application.SendNotification();
1367 application.Render();
1369 // Cursor position should be the same than position2.
1370 Vector3 position6 = cursor.GetCurrentPosition();
1372 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1374 // Should not be a renderer.
1375 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1380 int utcDaliTextEditorEvent03(void)
1382 ToolkitTestApplication application;
1383 tet_infoline(" utcDaliTextEditorEvent03");
1385 // Checks if the highlight actor is created.
1387 TextEditor editor = TextEditor::New();
1388 DALI_TEST_CHECK( editor );
1390 Stage::GetCurrent().Add( editor );
1392 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1393 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1394 editor.SetSize( 30.f, 50.f );
1395 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1396 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1398 // Avoid a crash when core load gl resources.
1399 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1401 // Render and notify
1402 application.SendNotification();
1403 application.Render();
1405 // Send some taps and check text controller with clipboard window
1406 Dali::Clipboard clipboard = Clipboard::Get();
1407 clipboard.ShowClipboard();
1408 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1409 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1410 clipboard.HideClipboard();
1412 // Render and notify
1413 application.SendNotification();
1414 application.Render();
1416 // Tap first to get the focus.
1417 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1418 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1420 // Render and notify
1421 application.SendNotification();
1422 application.Render();
1424 // Double tap to select a word.
1425 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1426 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1428 // Render and notify
1429 application.SendNotification();
1430 application.Render();
1432 // The stencil actor should have two actors: the renderer and the highlight actor.
1433 Actor stencil = editor.GetChildAt( 0u );
1435 // The stencil actor has a container with all the actors which contain the text renderers.
1436 Actor container = stencil.GetChildAt( 0u );
1437 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1439 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1440 DALI_TEST_CHECK( renderer );
1443 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1444 DALI_TEST_CHECK( highlight );
1449 int utcDaliTextEditorEvent04(void)
1451 ToolkitTestApplication application;
1452 tet_infoline(" utcDaliTextEditorEvent04");
1454 // Checks if the highlight actor is created.
1456 TextEditor editor = TextEditor::New();
1457 DALI_TEST_CHECK( editor );
1459 Stage::GetCurrent().Add( editor );
1461 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1462 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1463 editor.SetSize( 100.f, 50.f );
1464 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1465 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1467 // Avoid a crash when core load gl resources.
1468 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1470 // Render and notify
1471 application.SendNotification();
1472 application.Render();
1474 // Tap on the text editor
1475 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1476 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1478 // Render and notify
1479 application.SendNotification();
1480 application.Render();
1482 // Move at the end of the text.
1483 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1484 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1486 // Render and notify
1487 application.SendNotification();
1488 application.Render();
1490 for( unsigned int index = 0u; index < 10u; ++index )
1492 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1493 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1495 // Render and notify
1496 application.SendNotification();
1497 application.Render();
1501 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
1503 // Render and notify
1504 application.SendNotification();
1505 application.Render();
1507 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1509 // Add some key events
1510 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1511 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1513 // Render and notify
1514 application.SendNotification();
1515 application.Render();
1517 for( unsigned int index = 0u; index < 10u; ++index )
1519 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1520 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1522 // Render and notify
1523 application.SendNotification();
1524 application.Render();
1528 application.ProcessEvent( GenerateKey( " ", " ", 0, 0, 0, Integration::KeyEvent::Down ) );
1530 // Render and notify
1531 application.SendNotification();
1532 application.Render();
1534 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1539 int utcDaliTextEditorEvent05(void)
1541 ToolkitTestApplication application;
1542 tet_infoline(" utcDaliTextEditorEvent05");
1544 // Checks if the highlight actor is created.
1546 TextEditor editor = TextEditor::New();
1547 DALI_TEST_CHECK( editor );
1549 Stage::GetCurrent().Add( editor );
1551 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1552 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1553 editor.SetSize( 50.f, 50.f );
1554 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1555 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1556 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1557 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1559 // Avoid a crash when core load gl resources.
1560 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1562 // Render and notify
1563 application.SendNotification();
1564 application.Render();
1566 // Tap on the text editor
1567 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1568 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1570 // Render and notify
1571 application.SendNotification();
1572 application.Render();
1574 // Move at the end of the text.
1575 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1576 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1578 // Render and notify
1579 application.SendNotification();
1580 application.Render();
1582 for( unsigned int index = 0u; index < 10u; ++index )
1585 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
1587 // Render and notify
1588 application.SendNotification();
1589 application.Render();
1591 // Modify duration after scroll is enabled
1592 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1594 // Continuous scroll left to increase coverage
1595 for( unsigned int index = 0u; index < 10u; ++index )
1597 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1599 // Render and notify
1600 application.SendNotification();
1601 application.Render();
1603 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1604 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );