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 const int KEY_A_CODE = 38;
106 const int KEY_D_CODE = 40;
107 const int KEY_WHITE_SPACE_CODE = 65;
109 static bool gTextChangedCallBackCalled;
110 static bool gInputStyleChangedCallbackCalled;
111 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
113 struct CallbackFunctor
115 CallbackFunctor(bool* callbackFlag)
116 : mCallbackFlag( callbackFlag )
122 *mCallbackFlag = true;
127 static void TestTextChangedCallback( TextEditor control )
129 tet_infoline(" TestTextChangedCallback");
131 gTextChangedCallBackCalled = true;
134 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
136 tet_infoline(" TestInputStyleChangedCallback");
138 gInputStyleChangedCallbackCalled = true;
139 gInputStyleMask = mask;
142 // Generate a TapGestureEvent to send to Core.
143 Integration::TapGestureEvent GenerateTap(
144 Gesture::State state,
145 unsigned int numberOfTaps,
146 unsigned int numberOfTouches,
149 Integration::TapGestureEvent tap( state );
151 tap.numberOfTaps = numberOfTaps;
152 tap.numberOfTouches = numberOfTouches;
158 // Generate a KeyEvent to send to Core.
159 Integration::KeyEvent GenerateKey( const std::string& keyName,
160 const std::string& keyString,
163 unsigned long timeStamp,
164 const Integration::KeyEvent::State& keyState )
166 return Integration::KeyEvent( keyName,
174 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
176 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
178 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
180 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
182 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
183 if( NULL != valueSet )
185 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
187 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
193 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
204 int UtcDaliToolkitTextEditorConstructorP(void)
206 ToolkitTestApplication application;
207 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
208 TextEditor textEditor;
209 DALI_TEST_CHECK( !textEditor );
213 int UtcDaliToolkitTextEditorNewP(void)
215 ToolkitTestApplication application;
216 tet_infoline(" UtcDaliToolkitTextEditorNewP");
217 TextEditor textEditor = TextEditor::New();
218 DALI_TEST_CHECK( textEditor );
222 int UtcDaliToolkitTextEditorDownCastP(void)
224 ToolkitTestApplication application;
225 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
226 TextEditor textEditor1 = TextEditor::New();
227 BaseHandle object( textEditor1 );
229 TextEditor textEditor2 = TextEditor::DownCast( object );
230 DALI_TEST_CHECK( textEditor2 );
232 TextEditor textEditor3 = DownCast< TextEditor >( object );
233 DALI_TEST_CHECK( textEditor3 );
237 int UtcDaliToolkitTextEditorDownCastN(void)
239 ToolkitTestApplication application;
240 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
241 BaseHandle uninitializedObject;
242 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
243 DALI_TEST_CHECK( !textEditor1 );
245 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
246 DALI_TEST_CHECK( !textEditor2 );
250 int UtcDaliToolkitTextEditorCopyConstructorP(void)
252 ToolkitTestApplication application;
253 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
254 TextEditor textEditor = TextEditor::New();
255 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
257 TextEditor copy( textEditor );
258 DALI_TEST_CHECK( copy );
259 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
263 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
265 ToolkitTestApplication application;
266 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
267 TextEditor textEditor = TextEditor::New();
268 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
270 TextEditor copy = textEditor;
271 DALI_TEST_CHECK( copy );
272 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
276 int UtcDaliTextEditorNewP(void)
278 ToolkitTestApplication application;
279 tet_infoline(" UtcDaliToolkitTextEditorNewP");
280 TextEditor textEditor = TextEditor::New();
281 DALI_TEST_CHECK( textEditor );
285 // Positive test case for a method
286 int UtcDaliTextEditorGetPropertyP(void)
288 ToolkitTestApplication application;
289 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
290 TextEditor editor = TextEditor::New();
291 DALI_TEST_CHECK( editor );
293 // Check Property Indices are correct
294 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
295 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
296 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
297 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
298 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
299 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
300 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
301 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
302 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
303 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
304 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
305 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
306 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
307 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
308 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
309 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
310 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
311 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
312 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
313 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
314 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
315 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
316 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
317 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
318 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
319 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
320 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
321 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
322 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
323 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
325 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
326 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
327 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
328 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
329 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
330 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
331 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
332 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
333 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
334 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
335 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
336 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
341 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
344 Property::Map imageMap;
345 imageMap[mapKey] =mapValue;
347 editor.SetProperty( property , imageMap );
348 Property::Value propValue = editor.GetProperty( property );
349 Property::Map* resultMap = propValue.GetMap();
351 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
359 // Positive test case for a method
360 int UtcDaliTextEditorSetPropertyP(void)
362 ToolkitTestApplication application;
363 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
364 TextEditor editor = TextEditor::New();
365 DALI_TEST_CHECK( editor );
366 Stage::GetCurrent().Add( editor );
368 // Note - we can't check the defaults since the stylesheets are platform-specific
370 // Check the render backend property.
371 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
372 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
374 // Check text property.
375 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
376 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
378 // Check text's color property
379 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
380 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
382 // Check font properties.
383 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
384 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
386 Property::Map fontStyleMapSet;
387 Property::Map fontStyleMapGet;
388 Property::Value* slantValue = NULL;
390 fontStyleMapSet.Insert( "weight", "bold" );
391 fontStyleMapSet.Insert( "width", "condensed" );
392 fontStyleMapSet.Insert( "slant", "italic" );
394 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
395 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
396 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
397 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
399 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
400 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
403 fontStyleMapSet.Clear();
404 fontStyleMapSet.Insert( "weight", "normal" );
405 fontStyleMapSet.Insert( "slant", "oblique" );
406 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
407 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
408 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
409 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
411 fontStyleMapSet.Clear();
412 fontStyleMapSet.Insert( "slant", "roman" );
413 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
414 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
416 // Replace 'roman' for 'normal'.
417 slantValue = fontStyleMapGet.Find( "slant" );
418 if( NULL != slantValue )
420 if( "normal" == slantValue->Get<std::string>() )
422 fontStyleMapGet["slant"] = "roman";
425 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
426 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
428 fontStyleMapSet.Clear();
430 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
431 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
432 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
433 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
435 // Check that the Alignment properties can be correctly set
436 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
437 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
439 // Check scroll properties.
440 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
441 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
442 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
443 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
445 // Check cursor properties
446 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
447 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
448 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
449 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
451 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
452 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
453 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
454 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
455 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
456 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
457 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
458 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
460 // Check handle images
461 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
462 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
463 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
464 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
465 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
467 // Check handle images
468 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
469 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
470 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
471 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
472 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
473 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
475 // Check the highlight color
476 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
477 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
479 // Decoration bounding box
480 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
481 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
483 // Check the enable markup property.
484 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
485 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
486 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
488 // Check input color property.
489 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
490 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
492 // Check input font properties.
493 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
494 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
496 fontStyleMapSet.Clear();
497 fontStyleMapSet.Insert( "weight", "bold" );
498 fontStyleMapSet.Insert( "width", "condensed" );
499 fontStyleMapSet.Insert( "slant", "italic" );
501 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
502 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
503 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
504 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
506 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
507 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
509 // Reset input font style.
510 fontStyleMapSet.Clear();
511 fontStyleMapSet.Insert( "weight", "normal" );
512 fontStyleMapSet.Insert( "slant", "oblique" );
514 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
515 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
516 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
517 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
519 fontStyleMapSet.Clear();
520 fontStyleMapSet.Insert( "slant", "roman" );
522 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
523 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
525 // Replace 'roman' for 'normal'.
526 slantValue = fontStyleMapGet.Find( "slant" );
527 if( NULL != slantValue )
529 if( "normal" == slantValue->Get<std::string>() )
531 fontStyleMapGet["slant"] = "roman";
534 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
535 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
537 fontStyleMapSet.Clear();
539 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
540 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
541 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
542 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
544 // Check the line spacing property
545 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
546 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
547 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
549 // Check the input line spacing property
550 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
551 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
552 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
554 // Check the underline property
556 Property::Map underlineMapSet;
557 Property::Map underlineMapGet;
559 underlineMapSet.Insert( "enable", "true" );
560 underlineMapSet.Insert( "color", "red" );
561 underlineMapSet.Insert( "height", "1" );
563 editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
565 underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
566 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
567 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
569 // Check the input underline property
570 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
571 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
573 // Check the shadow property
574 Property::Map shadowMapSet;
575 Property::Map shadowMapGet;
577 shadowMapSet.Insert( "color", "green" );
578 shadowMapSet.Insert( "offset", "2 2" );
580 editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
582 shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
583 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
584 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
586 // Check the input shadow property
587 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
588 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
590 // Check the emboss property
591 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
592 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
594 // Check the input emboss property
595 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
596 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
598 // Check the outline property
599 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
600 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
602 // Check the input outline property
603 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
604 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
606 // Check the smooth scroll property
607 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
608 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
609 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
611 // Check the smooth scroll duration property
612 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
613 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
618 // Positive Atlas Text Renderer test
619 int utcDaliTextEditorAtlasRenderP(void)
621 ToolkitTestApplication application;
622 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
623 StyleManager styleManager = StyleManager::Get();
624 styleManager.ApplyDefaultTheme();
625 TextEditor editor = TextEditor::New();
626 DALI_TEST_CHECK( editor );
628 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
630 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
632 Stage::GetCurrent().Add( editor );
636 // Render some text with the shared atlas backend
637 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
638 application.SendNotification();
639 application.Render();
643 tet_result(TET_FAIL);
648 // Positive test for the textChanged signal.
649 int utcDaliTextEditorTextChangedP(void)
651 ToolkitTestApplication application;
652 tet_infoline(" utcDaliTextEditorTextChangedP");
653 TextEditor editor = TextEditor::New();
654 DALI_TEST_CHECK( editor );
656 Stage::GetCurrent().Add( editor );
658 // connect to the text changed signal.
659 ConnectionTracker* testTracker = new ConnectionTracker();
660 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
661 bool textChangedSignal = false;
662 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
664 gTextChangedCallBackCalled = false;
665 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
666 DALI_TEST_CHECK( gTextChangedCallBackCalled );
667 DALI_TEST_CHECK( textChangedSignal );
669 application.SendNotification();
671 editor.SetKeyInputFocus();
673 gTextChangedCallBackCalled = false;
674 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
675 DALI_TEST_CHECK( gTextChangedCallBackCalled );
680 int utcDaliTextEditorInputStyleChanged01(void)
682 ToolkitTestApplication application;
683 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
685 // The text-editor emits signals when the input style changes. These changes of style are
686 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
687 // can't be emitted during the size negotiation as the callbacks may update the UI.
688 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
689 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
690 application.CreateAdaptor();
694 char* pathNamePtr = get_current_dir_name();
695 const std::string pathName( pathNamePtr );
698 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
699 fontClient.SetDpi( 93u, 93u );
701 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
702 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
704 TextEditor editor = TextEditor::New();
705 DALI_TEST_CHECK( editor );
708 editor.SetSize( 300.f, 50.f );
709 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
710 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
712 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
713 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
715 // connect to the text changed signal.
716 ConnectionTracker* testTracker = new ConnectionTracker();
717 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
718 bool inputStyleChangedSignal = false;
719 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
721 Stage::GetCurrent().Add( editor );
724 application.SendNotification();
725 application.Render();
727 // Executes the idle callbacks added by the text control on the change of input style.
728 application.RunIdles();
730 gInputStyleChangedCallbackCalled = false;
731 gInputStyleMask = TextEditor::InputStyle::NONE;
732 inputStyleChangedSignal = false;
734 // Create a tap event to touch the text editor.
735 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
736 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
739 application.SendNotification();
740 application.Render();
742 // Executes the idle callbacks added by the text control on the change of input style.
743 application.RunIdles();
745 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
746 if( gInputStyleChangedCallbackCalled )
748 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
750 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
751 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
753 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
754 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
756 DALI_TEST_CHECK( inputStyleChangedSignal );
758 gInputStyleChangedCallbackCalled = false;
759 gInputStyleMask = TextEditor::InputStyle::NONE;
760 inputStyleChangedSignal = false;
762 // Create a tap event to touch the text editor.
763 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
764 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
767 application.SendNotification();
768 application.Render();
770 // Executes the idle callbacks added by the text control on the change of input style.
771 application.RunIdles();
773 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
774 DALI_TEST_CHECK( !inputStyleChangedSignal );
776 gInputStyleChangedCallbackCalled = false;
777 gInputStyleMask = TextEditor::InputStyle::NONE;
778 inputStyleChangedSignal = false;
780 // Create a tap event to touch the text editor.
781 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
782 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
785 application.SendNotification();
786 application.Render();
788 // Executes the idle callbacks added by the text control on the change of input style.
789 application.RunIdles();
791 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
792 if( gInputStyleChangedCallbackCalled )
794 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
796 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
797 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
799 DALI_TEST_CHECK( inputStyleChangedSignal );
801 gInputStyleChangedCallbackCalled = false;
802 gInputStyleMask = TextEditor::InputStyle::NONE;
803 inputStyleChangedSignal = false;
805 // Create a tap event to touch the text editor.
806 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
807 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
810 application.SendNotification();
811 application.Render();
813 // Executes the idle callbacks added by the text control on the change of input style.
814 application.RunIdles();
816 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
817 if( gInputStyleChangedCallbackCalled )
819 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
821 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
822 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
824 Property::Map fontStyleMapSet;
825 Property::Map fontStyleMapGet;
827 fontStyleMapSet.Insert( "weight", "bold" );
829 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
830 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
831 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
833 DALI_TEST_CHECK( inputStyleChangedSignal );
835 gInputStyleChangedCallbackCalled = false;
836 gInputStyleMask = TextEditor::InputStyle::NONE;
837 inputStyleChangedSignal = false;
839 // Create a tap event to touch the text editor.
840 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
841 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
844 application.SendNotification();
845 application.Render();
847 // Executes the idle callbacks added by the text control on the change of input style.
848 application.RunIdles();
850 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
851 DALI_TEST_CHECK( !inputStyleChangedSignal );
853 gInputStyleChangedCallbackCalled = false;
854 gInputStyleMask = TextEditor::InputStyle::NONE;
855 inputStyleChangedSignal = false;
857 // Create a tap event to touch the text editor.
858 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
859 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
862 application.SendNotification();
863 application.Render();
865 // Executes the idle callbacks added by the text control on the change of input style.
866 application.RunIdles();
868 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
869 if( gInputStyleChangedCallbackCalled )
871 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
873 Property::Map fontStyleMapSet;
874 Property::Map fontStyleMapGet;
876 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
877 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
878 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
880 DALI_TEST_CHECK( inputStyleChangedSignal );
882 gInputStyleChangedCallbackCalled = false;
883 gInputStyleMask = TextEditor::InputStyle::NONE;
884 inputStyleChangedSignal = false;
886 // Create a tap event to touch the text editor.
887 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
888 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
891 application.SendNotification();
892 application.Render();
894 // Executes the idle callbacks added by the text control on the change of input style.
895 application.RunIdles();
897 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
898 DALI_TEST_CHECK( !inputStyleChangedSignal );
903 int utcDaliTextEditorInputStyleChanged02(void)
905 ToolkitTestApplication application;
906 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
908 // The text-editor emits signals when the input style changes. These changes of style are
909 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
910 // can't be emitted during the size negotiation as the callbacks may update the UI.
911 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
912 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
913 application.CreateAdaptor();
917 char* pathNamePtr = get_current_dir_name();
918 const std::string pathName( pathNamePtr );
921 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
922 fontClient.SetDpi( 93u, 93u );
924 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
925 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
927 TextEditor editor = TextEditor::New();
928 DALI_TEST_CHECK( editor );
931 editor.SetSize( 300.f, 50.f );
932 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
933 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
935 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
936 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>" );
938 // connect to the text changed signal.
939 ConnectionTracker* testTracker = new ConnectionTracker();
940 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
941 bool inputStyleChangedSignal = false;
942 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
944 Stage::GetCurrent().Add( editor );
947 application.SendNotification();
948 application.Render();
950 // Executes the idle callbacks added by the text control on the change of input style.
951 application.RunIdles();
953 gInputStyleChangedCallbackCalled = false;
954 gInputStyleMask = TextEditor::InputStyle::NONE;
955 inputStyleChangedSignal = false;
957 // Create a tap event to touch the text editor.
958 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
959 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
960 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
961 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
964 application.SendNotification();
965 application.Render();
967 // Executes the idle callbacks added by the text control on the change of input style.
968 application.RunIdles();
970 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
971 if( gInputStyleChangedCallbackCalled )
973 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
974 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
975 TextEditor::InputStyle::POINT_SIZE |
976 TextEditor::InputStyle::COLOR ),
979 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
980 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
982 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
983 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
985 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
986 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
988 DALI_TEST_CHECK( inputStyleChangedSignal );
990 gInputStyleChangedCallbackCalled = false;
991 gInputStyleMask = TextEditor::InputStyle::NONE;
992 inputStyleChangedSignal = false;
994 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
997 application.SendNotification();
998 application.Render();
1000 // Executes the idle callbacks added by the text control on the change of input style.
1001 application.RunIdles();
1003 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1004 if( gInputStyleChangedCallbackCalled )
1006 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1007 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1010 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1011 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1013 DALI_TEST_CHECK( inputStyleChangedSignal );
1015 gInputStyleChangedCallbackCalled = false;
1016 gInputStyleMask = TextEditor::InputStyle::NONE;
1017 inputStyleChangedSignal = false;
1019 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1021 // Render and notify
1022 application.SendNotification();
1023 application.Render();
1025 // Executes the idle callbacks added by the text control on the change of input style.
1026 application.RunIdles();
1028 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1029 DALI_TEST_CHECK( !inputStyleChangedSignal );
1031 gInputStyleChangedCallbackCalled = false;
1032 gInputStyleMask = TextEditor::InputStyle::NONE;
1033 inputStyleChangedSignal = false;
1035 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1037 // Render and notify
1038 application.SendNotification();
1039 application.Render();
1041 // Executes the idle callbacks added by the text control on the change of input style.
1042 application.RunIdles();
1044 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1045 if( gInputStyleChangedCallbackCalled )
1047 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1048 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1051 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1052 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1054 DALI_TEST_CHECK( inputStyleChangedSignal );
1056 gInputStyleChangedCallbackCalled = false;
1057 gInputStyleMask = TextEditor::InputStyle::NONE;
1058 inputStyleChangedSignal = false;
1060 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1062 Property::Map fontStyleMapSet;
1063 fontStyleMapSet.Insert( "weight", "thin" );
1064 fontStyleMapSet.Insert( "width", "condensed" );
1065 fontStyleMapSet.Insert( "slant", "italic" );
1067 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1068 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1069 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1071 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1072 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1073 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1074 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1076 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1078 // Render and notify
1079 application.SendNotification();
1080 application.Render();
1082 // Executes the idle callbacks added by the text control on the change of input style.
1083 application.RunIdles();
1085 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1086 DALI_TEST_CHECK( !inputStyleChangedSignal );
1088 // Create a tap event to touch the text editor.
1089 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1090 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1092 // Render and notify
1093 application.SendNotification();
1094 application.Render();
1096 // Executes the idle callbacks added by the text control on the change of input style.
1097 application.RunIdles();
1099 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1100 if( gInputStyleChangedCallbackCalled )
1102 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1103 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1104 TextEditor::InputStyle::POINT_SIZE |
1105 TextEditor::InputStyle::FONT_STYLE |
1106 TextEditor::InputStyle::LINE_SPACING |
1107 TextEditor::InputStyle::UNDERLINE |
1108 TextEditor::InputStyle::SHADOW |
1109 TextEditor::InputStyle::EMBOSS |
1110 TextEditor::InputStyle::OUTLINE ),
1113 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1114 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1116 DALI_TEST_CHECK( inputStyleChangedSignal );
1118 gInputStyleChangedCallbackCalled = false;
1119 gInputStyleMask = TextEditor::InputStyle::NONE;
1120 inputStyleChangedSignal = false;
1122 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1124 fontStyleMapSet.Clear();
1125 fontStyleMapSet.Insert( "weight", "black" );
1126 fontStyleMapSet.Insert( "width", "expanded" );
1127 fontStyleMapSet.Insert( "slant", "oblique" );
1129 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1131 // Create a tap event to touch the text editor.
1132 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1133 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1135 // Render and notify
1136 application.SendNotification();
1137 application.Render();
1139 // Executes the idle callbacks added by the text control on the change of input style.
1140 application.RunIdles();
1142 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1143 if( gInputStyleChangedCallbackCalled )
1145 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1146 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1147 TextEditor::InputStyle::POINT_SIZE |
1148 TextEditor::InputStyle::FONT_STYLE ),
1151 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1152 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1154 DALI_TEST_CHECK( inputStyleChangedSignal );
1159 int utcDaliTextEditorEvent01(void)
1161 ToolkitTestApplication application;
1162 tet_infoline(" utcDaliTextEditorEvent01");
1164 // Creates a tap event. After creating a tap event the text editor should
1165 // have the focus and add text with key events should be possible.
1167 TextEditor editor = TextEditor::New();
1168 DALI_TEST_CHECK( editor );
1170 Stage::GetCurrent().Add( editor );
1172 editor.SetSize( 300.f, 50.f );
1173 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1174 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1176 // Avoid a crash when core load gl resources.
1177 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1179 // Render and notify
1180 application.SendNotification();
1181 application.Render();
1183 // Add a key event but as the text editor has not the focus it should do nothing.
1184 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1186 // Render and notify
1187 application.SendNotification();
1188 application.Render();
1190 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1192 // Create a tap event to touch the text editor.
1193 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1194 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1196 // Render and notify
1197 application.SendNotification();
1198 application.Render();
1200 // Now the text editor has the focus, so it can handle the key events.
1201 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1202 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1204 // Render and notify
1205 application.SendNotification();
1206 application.Render();
1208 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1210 // Create a second text editor and send key events to it.
1211 TextEditor editor2 = TextEditor::New();
1213 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1214 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1215 editor2.SetSize( 100.f, 100.f );
1216 editor2.SetPosition( 100.f, 100.f );
1218 Stage::GetCurrent().Add( editor2 );
1220 // Render and notify
1221 application.SendNotification();
1222 application.Render();
1224 // Create a tap event on the second text editor.
1225 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1226 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1228 // Render and notify
1229 application.SendNotification();
1230 application.Render();
1232 // The second text editor has the focus. It should handle the key events.
1233 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1234 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1236 // Render and notify
1237 application.SendNotification();
1238 application.Render();
1240 // Check the text has been added to the second text editor.
1241 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1246 int utcDaliTextEditorEvent02(void)
1248 ToolkitTestApplication application;
1249 tet_infoline(" utcDaliTextEditorEvent02");
1251 // Checks if the right number of actors are created.
1253 TextEditor editor = TextEditor::New();
1254 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1255 DALI_TEST_CHECK( editor );
1257 Stage::GetCurrent().Add( editor );
1259 editor.SetSize( 300.f, 50.f );
1260 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1261 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1263 // Avoid a crash when core load gl resources.
1264 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1266 // Render and notify
1267 application.SendNotification();
1268 application.Render();
1270 // Check there are the expected number of children (the stencil).
1271 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1273 Actor stencil = editor.GetChildAt( 0u );
1275 // Create a tap event to touch the text editor.
1276 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1277 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1279 // Render and notify
1280 application.SendNotification();
1281 application.Render();
1283 Actor layer = editor.GetChildAt( 1u );
1284 DALI_TEST_CHECK( layer.IsLayer() );
1286 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1287 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1289 // Now the text editor has the focus, so it can handle the key events.
1290 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1291 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1293 // Render and notify
1294 application.SendNotification();
1295 application.Render();
1297 // Checks the cursor and the renderer have been created.
1298 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1299 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1301 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1302 DALI_TEST_CHECK( cursor );
1304 // The stencil actor has a container with all the actors which contain the text renderers.
1305 Actor container = stencil.GetChildAt( 0u );
1306 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1308 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1309 DALI_TEST_CHECK( renderer );
1312 // Move the cursor and check the position changes.
1313 Vector3 position1 = cursor.GetCurrentPosition();
1315 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1316 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1318 // Render and notify
1319 application.SendNotification();
1320 application.Render();
1322 Vector3 position2 = cursor.GetCurrentPosition();
1324 DALI_TEST_CHECK( position2.x < position1.x );
1326 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1327 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1329 // Render and notify
1330 application.SendNotification();
1331 application.Render();
1333 Vector3 position3 = cursor.GetCurrentPosition();
1335 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1337 // Send some taps and check the cursor positions.
1339 // Try to tap at the beginning.
1340 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1341 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1343 // Render and notify
1344 application.SendNotification();
1345 application.Render();
1347 // Cursor position should be the same than position1.
1348 Vector3 position4 = cursor.GetCurrentPosition();
1350 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1352 // Tap away from the start position.
1353 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1354 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1356 // Render and notify
1357 application.SendNotification();
1358 application.Render();
1360 Vector3 position5 = cursor.GetCurrentPosition();
1362 DALI_TEST_CHECK( position5.x > position4.x );
1364 // Remove all the text.
1365 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1366 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1367 editor.SetProperty( TextEditor::Property::TEXT, "" );
1369 // Render and notify
1370 application.SendNotification();
1371 application.Render();
1373 // Cursor position should be the same than position2.
1374 Vector3 position6 = cursor.GetCurrentPosition();
1376 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1378 // Should not be a renderer.
1379 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1384 int utcDaliTextEditorEvent03(void)
1386 ToolkitTestApplication application;
1387 tet_infoline(" utcDaliTextEditorEvent03");
1389 // Checks if the highlight actor is created.
1391 TextEditor editor = TextEditor::New();
1392 DALI_TEST_CHECK( editor );
1394 Stage::GetCurrent().Add( editor );
1396 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1397 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1398 editor.SetSize( 30.f, 50.f );
1399 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1400 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1402 // Avoid a crash when core load gl resources.
1403 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1405 // Render and notify
1406 application.SendNotification();
1407 application.Render();
1409 // Send some taps and check text controller with clipboard window
1410 Dali::Clipboard clipboard = Clipboard::Get();
1411 clipboard.ShowClipboard();
1412 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1413 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1414 clipboard.HideClipboard();
1416 // Render and notify
1417 application.SendNotification();
1418 application.Render();
1420 // Tap first to get the focus.
1421 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1422 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1424 // Render and notify
1425 application.SendNotification();
1426 application.Render();
1428 // Double tap to select a word.
1429 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1430 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1432 // Render and notify
1433 application.SendNotification();
1434 application.Render();
1436 // The stencil actor should have two actors: the renderer and the highlight actor.
1437 Actor stencil = editor.GetChildAt( 0u );
1439 // The stencil actor has a container with all the actors which contain the text renderers.
1440 Actor container = stencil.GetChildAt( 0u );
1441 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1443 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1444 DALI_TEST_CHECK( renderer );
1447 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1448 DALI_TEST_CHECK( highlight );
1453 int utcDaliTextEditorEvent04(void)
1455 ToolkitTestApplication application;
1456 tet_infoline(" utcDaliTextEditorEvent04");
1458 // Checks if the highlight actor is created.
1460 TextEditor editor = TextEditor::New();
1461 DALI_TEST_CHECK( editor );
1463 Stage::GetCurrent().Add( editor );
1465 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1466 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1467 editor.SetSize( 100.f, 50.f );
1468 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1469 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1471 // Avoid a crash when core load gl resources.
1472 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1474 // Render and notify
1475 application.SendNotification();
1476 application.Render();
1478 // Tap on the text editor
1479 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1480 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1482 // Render and notify
1483 application.SendNotification();
1484 application.Render();
1486 // Move at the end of the text.
1487 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1488 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1490 // Render and notify
1491 application.SendNotification();
1492 application.Render();
1494 for( unsigned int index = 0u; index < 10u; ++index )
1496 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1497 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1499 // Render and notify
1500 application.SendNotification();
1501 application.Render();
1505 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
1507 // Render and notify
1508 application.SendNotification();
1509 application.Render();
1511 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1513 // Add some key events
1514 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1515 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1517 // Render and notify
1518 application.SendNotification();
1519 application.Render();
1521 for( unsigned int index = 0u; index < 10u; ++index )
1523 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1524 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1526 // Render and notify
1527 application.SendNotification();
1528 application.Render();
1532 application.ProcessEvent( GenerateKey( " ", " ", KEY_WHITE_SPACE_CODE, 0, 0, Integration::KeyEvent::Down ) );
1534 // Render and notify
1535 application.SendNotification();
1536 application.Render();
1538 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1543 int utcDaliTextEditorEvent05(void)
1545 ToolkitTestApplication application;
1546 tet_infoline(" utcDaliTextEditorEvent05");
1548 // Checks if the highlight actor is created.
1550 TextEditor editor = TextEditor::New();
1551 DALI_TEST_CHECK( editor );
1553 Stage::GetCurrent().Add( editor );
1555 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1556 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1557 editor.SetSize( 50.f, 50.f );
1558 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1559 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1560 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1561 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1563 // Avoid a crash when core load gl resources.
1564 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1566 // Render and notify
1567 application.SendNotification();
1568 application.Render();
1570 // Tap on the text editor
1571 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1572 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1574 // Render and notify
1575 application.SendNotification();
1576 application.Render();
1578 // Move at the end of the text.
1579 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1580 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1582 // Render and notify
1583 application.SendNotification();
1584 application.Render();
1586 for( unsigned int index = 0u; index < 10u; ++index )
1589 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
1591 // Render and notify
1592 application.SendNotification();
1593 application.Render();
1595 // Modify duration after scroll is enabled
1596 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1598 // Continuous scroll left to increase coverage
1599 for( unsigned int index = 0u; index < 10u; ++index )
1601 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1603 // Render and notify
1604 application.SendNotification();
1605 application.Render();
1607 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1608 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1610 // Press Escape to increase coverage
1611 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
1612 application.SendNotification();
1613 application.Render();
1615 DALI_TEST_CHECK( !editor.HasKeyInputFocus() );