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";
90 const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR = "enableScrollBar";
91 const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION = "scrollBarShowDuration";
92 const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION = "scrollBarFadeDuration";
94 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
96 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
98 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
99 const float TO_MILLISECONDS = 1000.f;
100 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
102 const float SCROLL_THRESHOLD = 10.f;
103 const float SCROLL_SPEED = 300.f;
105 const unsigned int DEFAULT_FONT_SIZE = 1152u;
106 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
108 static bool gTextChangedCallBackCalled;
109 static bool gInputStyleChangedCallbackCalled;
110 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
112 struct CallbackFunctor
114 CallbackFunctor(bool* callbackFlag)
115 : mCallbackFlag( callbackFlag )
121 *mCallbackFlag = true;
126 static void TestTextChangedCallback( TextEditor control )
128 tet_infoline(" TestTextChangedCallback");
130 gTextChangedCallBackCalled = true;
133 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
135 tet_infoline(" TestInputStyleChangedCallback");
137 gInputStyleChangedCallbackCalled = true;
138 gInputStyleMask = mask;
141 // Generate a TapGestureEvent to send to Core.
142 Integration::TapGestureEvent GenerateTap(
143 Gesture::State state,
144 unsigned int numberOfTaps,
145 unsigned int numberOfTouches,
148 Integration::TapGestureEvent tap( state );
150 tap.numberOfTaps = numberOfTaps;
151 tap.numberOfTouches = numberOfTouches;
157 // Generate a KeyEvent to send to Core.
158 Integration::KeyEvent GenerateKey( const std::string& keyName,
159 const std::string& keyString,
162 unsigned long timeStamp,
163 const Integration::KeyEvent::State& keyState )
165 return Integration::KeyEvent( keyName,
173 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
175 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
177 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
179 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
181 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
182 if( NULL != valueSet )
184 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
186 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
192 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
203 int UtcDaliToolkitTextEditorConstructorP(void)
205 ToolkitTestApplication application;
206 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
207 TextEditor textEditor;
208 DALI_TEST_CHECK( !textEditor );
212 int UtcDaliToolkitTextEditorNewP(void)
214 ToolkitTestApplication application;
215 tet_infoline(" UtcDaliToolkitTextEditorNewP");
216 TextEditor textEditor = TextEditor::New();
217 DALI_TEST_CHECK( textEditor );
221 int UtcDaliToolkitTextEditorDownCastP(void)
223 ToolkitTestApplication application;
224 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
225 TextEditor textEditor1 = TextEditor::New();
226 BaseHandle object( textEditor1 );
228 TextEditor textEditor2 = TextEditor::DownCast( object );
229 DALI_TEST_CHECK( textEditor2 );
231 TextEditor textEditor3 = DownCast< TextEditor >( object );
232 DALI_TEST_CHECK( textEditor3 );
236 int UtcDaliToolkitTextEditorDownCastN(void)
238 ToolkitTestApplication application;
239 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
240 BaseHandle uninitializedObject;
241 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
242 DALI_TEST_CHECK( !textEditor1 );
244 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
245 DALI_TEST_CHECK( !textEditor2 );
249 int UtcDaliToolkitTextEditorCopyConstructorP(void)
251 ToolkitTestApplication application;
252 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
253 TextEditor textEditor = TextEditor::New();
254 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
256 TextEditor copy( textEditor );
257 DALI_TEST_CHECK( copy );
258 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
262 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
264 ToolkitTestApplication application;
265 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
266 TextEditor textEditor = TextEditor::New();
267 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
269 TextEditor copy = textEditor;
270 DALI_TEST_CHECK( copy );
271 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
275 int UtcDaliTextEditorNewP(void)
277 ToolkitTestApplication application;
278 tet_infoline(" UtcDaliToolkitTextEditorNewP");
279 TextEditor textEditor = TextEditor::New();
280 DALI_TEST_CHECK( textEditor );
284 // Positive test case for a method
285 int UtcDaliTextEditorGetPropertyP(void)
287 ToolkitTestApplication application;
288 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
289 TextEditor editor = TextEditor::New();
290 DALI_TEST_CHECK( editor );
292 // Check Property Indices are correct
293 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
294 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
295 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
296 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
297 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
298 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
299 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
300 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
301 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
302 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
303 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
304 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
305 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
306 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
307 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
308 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
309 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
310 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
311 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
312 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
313 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
314 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
315 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
316 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
317 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
318 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
319 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
320 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
321 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
322 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
324 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
325 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
326 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
327 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
328 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
329 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
330 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
331 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
332 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
333 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
334 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
335 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
336 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SCROLL_BAR ) == DevelTextEditor::Property::ENABLE_SCROLL_BAR );
337 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
338 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
343 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
346 Property::Map imageMap;
347 imageMap[mapKey] =mapValue;
349 editor.SetProperty( property , imageMap );
350 Property::Value propValue = editor.GetProperty( property );
351 Property::Map* resultMap = propValue.GetMap();
353 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
361 // Positive test case for a method
362 int UtcDaliTextEditorSetPropertyP(void)
364 ToolkitTestApplication application;
365 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
366 TextEditor editor = TextEditor::New();
367 DALI_TEST_CHECK( editor );
368 Stage::GetCurrent().Add( editor );
370 // Note - we can't check the defaults since the stylesheets are platform-specific
372 // Check the render backend property.
373 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
374 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
376 // Check text property.
377 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
378 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
380 // Check text's color property
381 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
382 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
384 // Check font properties.
385 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
386 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
388 Property::Map fontStyleMapSet;
389 Property::Map fontStyleMapGet;
390 Property::Value* slantValue = NULL;
392 fontStyleMapSet.Insert( "weight", "bold" );
393 fontStyleMapSet.Insert( "width", "condensed" );
394 fontStyleMapSet.Insert( "slant", "italic" );
396 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
397 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
398 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
399 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
401 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
402 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
405 fontStyleMapSet.Clear();
406 fontStyleMapSet.Insert( "weight", "normal" );
407 fontStyleMapSet.Insert( "slant", "oblique" );
408 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
409 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
410 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
411 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
413 fontStyleMapSet.Clear();
414 fontStyleMapSet.Insert( "slant", "roman" );
415 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
416 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
418 // Replace 'roman' for 'normal'.
419 slantValue = fontStyleMapGet.Find( "slant" );
420 if( NULL != slantValue )
422 if( "normal" == slantValue->Get<std::string>() )
424 fontStyleMapGet["slant"] = "roman";
427 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
428 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
430 fontStyleMapSet.Clear();
432 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
433 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
434 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
435 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
437 // Check that the Alignment properties can be correctly set
438 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
439 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
441 // Check scroll properties.
442 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
443 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
444 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
445 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
447 // Check cursor properties
448 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
449 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
450 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
451 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
453 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
454 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
455 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
456 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
457 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
458 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
459 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
460 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
462 // Check handle images
463 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
464 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
465 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
466 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
467 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
469 // Check handle images
470 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
471 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
472 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
473 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
474 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
475 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
477 // Check the highlight color
478 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
479 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
481 // Decoration bounding box
482 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
483 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
485 // Check the enable markup property.
486 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
487 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
488 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
490 // Check input color property.
491 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
492 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
494 // Check input font properties.
495 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
496 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
498 fontStyleMapSet.Clear();
499 fontStyleMapSet.Insert( "weight", "bold" );
500 fontStyleMapSet.Insert( "width", "condensed" );
501 fontStyleMapSet.Insert( "slant", "italic" );
503 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
504 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
505 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
506 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
508 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
509 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
511 // Reset input font style.
512 fontStyleMapSet.Clear();
513 fontStyleMapSet.Insert( "weight", "normal" );
514 fontStyleMapSet.Insert( "slant", "oblique" );
516 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
517 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
518 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
519 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
521 fontStyleMapSet.Clear();
522 fontStyleMapSet.Insert( "slant", "roman" );
524 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
525 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
527 // Replace 'roman' for 'normal'.
528 slantValue = fontStyleMapGet.Find( "slant" );
529 if( NULL != slantValue )
531 if( "normal" == slantValue->Get<std::string>() )
533 fontStyleMapGet["slant"] = "roman";
536 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
537 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
539 fontStyleMapSet.Clear();
541 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
542 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
543 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
544 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
546 // Check the line spacing property
547 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
548 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
549 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
551 // Check the input line spacing property
552 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
553 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
554 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
556 // Check the underline property
558 Property::Map underlineMapSet;
559 Property::Map underlineMapGet;
561 underlineMapSet.Insert( "enable", "true" );
562 underlineMapSet.Insert( "color", "red" );
563 underlineMapSet.Insert( "height", "1" );
565 editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
567 underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
568 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
569 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
571 // Check the input underline property
572 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
573 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
575 // Check the shadow property
576 Property::Map shadowMapSet;
577 Property::Map shadowMapGet;
579 shadowMapSet.Insert( "color", "green" );
580 shadowMapSet.Insert( "offset", "2 2" );
582 editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
584 shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
585 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
586 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
588 // Check the input shadow property
589 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
590 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
592 // Check the emboss property
593 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
594 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
596 // Check the input emboss property
597 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
598 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
600 // Check the outline property
601 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
602 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
604 // Check the input outline property
605 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
606 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
608 // Check the smooth scroll property
609 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
610 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
611 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
613 // Check the smooth scroll duration property
614 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
615 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
617 // Check the scroll bar property
618 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), false, TEST_LOCATION );
619 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
620 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
622 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
623 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
624 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
625 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
630 // Positive Atlas Text Renderer test
631 int utcDaliTextEditorAtlasRenderP(void)
633 ToolkitTestApplication application;
634 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
635 StyleManager styleManager = StyleManager::Get();
636 styleManager.ApplyDefaultTheme();
637 TextEditor editor = TextEditor::New();
638 DALI_TEST_CHECK( editor );
640 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
642 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
644 Stage::GetCurrent().Add( editor );
648 // Render some text with the shared atlas backend
649 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
650 application.SendNotification();
651 application.Render();
655 tet_result(TET_FAIL);
660 // Positive test for the textChanged signal.
661 int utcDaliTextEditorTextChangedP(void)
663 ToolkitTestApplication application;
664 tet_infoline(" utcDaliTextEditorTextChangedP");
665 TextEditor editor = TextEditor::New();
666 DALI_TEST_CHECK( editor );
668 Stage::GetCurrent().Add( editor );
670 // connect to the text changed signal.
671 ConnectionTracker* testTracker = new ConnectionTracker();
672 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
673 bool textChangedSignal = false;
674 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
676 gTextChangedCallBackCalled = false;
677 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
678 DALI_TEST_CHECK( gTextChangedCallBackCalled );
679 DALI_TEST_CHECK( textChangedSignal );
681 application.SendNotification();
683 editor.SetKeyInputFocus();
685 gTextChangedCallBackCalled = false;
686 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
687 DALI_TEST_CHECK( gTextChangedCallBackCalled );
692 int utcDaliTextEditorInputStyleChanged01(void)
694 ToolkitTestApplication application;
695 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
697 // The text-editor emits signals when the input style changes. These changes of style are
698 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
699 // can't be emitted during the size negotiation as the callbacks may update the UI.
700 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
701 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
702 application.CreateAdaptor();
706 char* pathNamePtr = get_current_dir_name();
707 const std::string pathName( pathNamePtr );
710 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
711 fontClient.SetDpi( 93u, 93u );
713 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
714 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
716 TextEditor editor = TextEditor::New();
717 DALI_TEST_CHECK( editor );
720 editor.SetSize( 300.f, 50.f );
721 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
722 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
724 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
725 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
727 // connect to the text changed signal.
728 ConnectionTracker* testTracker = new ConnectionTracker();
729 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
730 bool inputStyleChangedSignal = false;
731 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
733 Stage::GetCurrent().Add( editor );
736 application.SendNotification();
737 application.Render();
739 // Executes the idle callbacks added by the text control on the change of input style.
740 application.RunIdles();
742 gInputStyleChangedCallbackCalled = false;
743 gInputStyleMask = TextEditor::InputStyle::NONE;
744 inputStyleChangedSignal = false;
746 // Create a tap event to touch the text editor.
747 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
748 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
751 application.SendNotification();
752 application.Render();
754 // Executes the idle callbacks added by the text control on the change of input style.
755 application.RunIdles();
757 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
758 if( gInputStyleChangedCallbackCalled )
760 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
762 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
763 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
765 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
766 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
768 DALI_TEST_CHECK( inputStyleChangedSignal );
770 gInputStyleChangedCallbackCalled = false;
771 gInputStyleMask = TextEditor::InputStyle::NONE;
772 inputStyleChangedSignal = false;
774 // Create a tap event to touch the text editor.
775 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
776 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
779 application.SendNotification();
780 application.Render();
782 // Executes the idle callbacks added by the text control on the change of input style.
783 application.RunIdles();
785 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
786 DALI_TEST_CHECK( !inputStyleChangedSignal );
788 gInputStyleChangedCallbackCalled = false;
789 gInputStyleMask = TextEditor::InputStyle::NONE;
790 inputStyleChangedSignal = false;
792 // Create a tap event to touch the text editor.
793 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
794 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
797 application.SendNotification();
798 application.Render();
800 // Executes the idle callbacks added by the text control on the change of input style.
801 application.RunIdles();
803 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
804 if( gInputStyleChangedCallbackCalled )
806 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
808 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
809 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
811 DALI_TEST_CHECK( inputStyleChangedSignal );
813 gInputStyleChangedCallbackCalled = false;
814 gInputStyleMask = TextEditor::InputStyle::NONE;
815 inputStyleChangedSignal = false;
817 // Create a tap event to touch the text editor.
818 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
819 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
822 application.SendNotification();
823 application.Render();
825 // Executes the idle callbacks added by the text control on the change of input style.
826 application.RunIdles();
828 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
829 if( gInputStyleChangedCallbackCalled )
831 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
833 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
834 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
836 Property::Map fontStyleMapSet;
837 Property::Map fontStyleMapGet;
839 fontStyleMapSet.Insert( "weight", "bold" );
841 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
842 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
843 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
845 DALI_TEST_CHECK( inputStyleChangedSignal );
847 gInputStyleChangedCallbackCalled = false;
848 gInputStyleMask = TextEditor::InputStyle::NONE;
849 inputStyleChangedSignal = false;
851 // Create a tap event to touch the text editor.
852 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
853 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
856 application.SendNotification();
857 application.Render();
859 // Executes the idle callbacks added by the text control on the change of input style.
860 application.RunIdles();
862 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
863 DALI_TEST_CHECK( !inputStyleChangedSignal );
865 gInputStyleChangedCallbackCalled = false;
866 gInputStyleMask = TextEditor::InputStyle::NONE;
867 inputStyleChangedSignal = false;
869 // Create a tap event to touch the text editor.
870 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
871 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
874 application.SendNotification();
875 application.Render();
877 // Executes the idle callbacks added by the text control on the change of input style.
878 application.RunIdles();
880 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
881 if( gInputStyleChangedCallbackCalled )
883 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
885 Property::Map fontStyleMapSet;
886 Property::Map fontStyleMapGet;
888 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
889 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
890 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
892 DALI_TEST_CHECK( inputStyleChangedSignal );
894 gInputStyleChangedCallbackCalled = false;
895 gInputStyleMask = TextEditor::InputStyle::NONE;
896 inputStyleChangedSignal = false;
898 // Create a tap event to touch the text editor.
899 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
900 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
903 application.SendNotification();
904 application.Render();
906 // Executes the idle callbacks added by the text control on the change of input style.
907 application.RunIdles();
909 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
910 DALI_TEST_CHECK( !inputStyleChangedSignal );
915 int utcDaliTextEditorInputStyleChanged02(void)
917 ToolkitTestApplication application;
918 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
920 // The text-editor emits signals when the input style changes. These changes of style are
921 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
922 // can't be emitted during the size negotiation as the callbacks may update the UI.
923 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
924 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
925 application.CreateAdaptor();
929 char* pathNamePtr = get_current_dir_name();
930 const std::string pathName( pathNamePtr );
933 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
934 fontClient.SetDpi( 93u, 93u );
936 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
937 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
939 TextEditor editor = TextEditor::New();
940 DALI_TEST_CHECK( editor );
943 editor.SetSize( 300.f, 50.f );
944 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
945 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
947 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
948 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>" );
950 // connect to the text changed signal.
951 ConnectionTracker* testTracker = new ConnectionTracker();
952 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
953 bool inputStyleChangedSignal = false;
954 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
956 Stage::GetCurrent().Add( editor );
959 application.SendNotification();
960 application.Render();
962 // Executes the idle callbacks added by the text control on the change of input style.
963 application.RunIdles();
965 gInputStyleChangedCallbackCalled = false;
966 gInputStyleMask = TextEditor::InputStyle::NONE;
967 inputStyleChangedSignal = false;
969 // Create a tap event to touch the text editor.
970 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
971 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
972 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
973 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
976 application.SendNotification();
977 application.Render();
979 // Executes the idle callbacks added by the text control on the change of input style.
980 application.RunIdles();
982 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
983 if( gInputStyleChangedCallbackCalled )
985 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
986 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
987 TextEditor::InputStyle::POINT_SIZE |
988 TextEditor::InputStyle::COLOR ),
991 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
992 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
994 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
995 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
997 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
998 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1000 DALI_TEST_CHECK( inputStyleChangedSignal );
1002 gInputStyleChangedCallbackCalled = false;
1003 gInputStyleMask = TextEditor::InputStyle::NONE;
1004 inputStyleChangedSignal = false;
1006 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1008 // Render and notify
1009 application.SendNotification();
1010 application.Render();
1012 // Executes the idle callbacks added by the text control on the change of input style.
1013 application.RunIdles();
1015 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1016 if( gInputStyleChangedCallbackCalled )
1018 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1019 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1022 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1023 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
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 DALI_TEST_CHECK( !inputStyleChangedSignal );
1043 gInputStyleChangedCallbackCalled = false;
1044 gInputStyleMask = TextEditor::InputStyle::NONE;
1045 inputStyleChangedSignal = false;
1047 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1049 // Render and notify
1050 application.SendNotification();
1051 application.Render();
1053 // Executes the idle callbacks added by the text control on the change of input style.
1054 application.RunIdles();
1056 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1057 if( gInputStyleChangedCallbackCalled )
1059 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1060 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1063 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1064 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1066 DALI_TEST_CHECK( inputStyleChangedSignal );
1068 gInputStyleChangedCallbackCalled = false;
1069 gInputStyleMask = TextEditor::InputStyle::NONE;
1070 inputStyleChangedSignal = false;
1072 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1074 Property::Map fontStyleMapSet;
1075 fontStyleMapSet.Insert( "weight", "thin" );
1076 fontStyleMapSet.Insert( "width", "condensed" );
1077 fontStyleMapSet.Insert( "slant", "italic" );
1079 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1080 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1081 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1083 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1084 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1085 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1086 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1088 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1090 // Render and notify
1091 application.SendNotification();
1092 application.Render();
1094 // Executes the idle callbacks added by the text control on the change of input style.
1095 application.RunIdles();
1097 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1098 DALI_TEST_CHECK( !inputStyleChangedSignal );
1100 // Create a tap event to touch the text editor.
1101 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1102 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1104 // Render and notify
1105 application.SendNotification();
1106 application.Render();
1108 // Executes the idle callbacks added by the text control on the change of input style.
1109 application.RunIdles();
1111 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1112 if( gInputStyleChangedCallbackCalled )
1114 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1115 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1116 TextEditor::InputStyle::POINT_SIZE |
1117 TextEditor::InputStyle::FONT_STYLE |
1118 TextEditor::InputStyle::LINE_SPACING |
1119 TextEditor::InputStyle::UNDERLINE |
1120 TextEditor::InputStyle::SHADOW |
1121 TextEditor::InputStyle::EMBOSS |
1122 TextEditor::InputStyle::OUTLINE ),
1125 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1126 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1128 DALI_TEST_CHECK( inputStyleChangedSignal );
1130 gInputStyleChangedCallbackCalled = false;
1131 gInputStyleMask = TextEditor::InputStyle::NONE;
1132 inputStyleChangedSignal = false;
1134 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1136 fontStyleMapSet.Clear();
1137 fontStyleMapSet.Insert( "weight", "black" );
1138 fontStyleMapSet.Insert( "width", "expanded" );
1139 fontStyleMapSet.Insert( "slant", "oblique" );
1141 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1143 // Create a tap event to touch the text editor.
1144 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1145 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1147 // Render and notify
1148 application.SendNotification();
1149 application.Render();
1151 // Executes the idle callbacks added by the text control on the change of input style.
1152 application.RunIdles();
1154 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1155 if( gInputStyleChangedCallbackCalled )
1157 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1158 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1159 TextEditor::InputStyle::POINT_SIZE |
1160 TextEditor::InputStyle::FONT_STYLE ),
1163 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1164 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1166 DALI_TEST_CHECK( inputStyleChangedSignal );
1171 int utcDaliTextEditorEvent01(void)
1173 ToolkitTestApplication application;
1174 tet_infoline(" utcDaliTextEditorEvent01");
1176 // Creates a tap event. After creating a tap event the text editor should
1177 // have the focus and add text with key events should be possible.
1179 TextEditor editor = TextEditor::New();
1180 DALI_TEST_CHECK( editor );
1182 Stage::GetCurrent().Add( editor );
1184 editor.SetSize( 300.f, 50.f );
1185 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1186 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1188 // Avoid a crash when core load gl resources.
1189 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1191 // Render and notify
1192 application.SendNotification();
1193 application.Render();
1195 // Add a key event but as the text editor has not the focus it should do nothing.
1196 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1198 // Render and notify
1199 application.SendNotification();
1200 application.Render();
1202 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1204 // Create a tap event to touch the text editor.
1205 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1206 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1208 // Render and notify
1209 application.SendNotification();
1210 application.Render();
1212 // Now the text editor has the focus, so it can handle the key events.
1213 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1214 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1216 // Render and notify
1217 application.SendNotification();
1218 application.Render();
1220 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1222 // Create a second text editor and send key events to it.
1223 TextEditor editor2 = TextEditor::New();
1225 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1226 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1227 editor2.SetSize( 100.f, 100.f );
1228 editor2.SetPosition( 100.f, 100.f );
1230 Stage::GetCurrent().Add( editor2 );
1232 // Render and notify
1233 application.SendNotification();
1234 application.Render();
1236 // Create a tap event on the second text editor.
1237 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1238 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1240 // Render and notify
1241 application.SendNotification();
1242 application.Render();
1244 // The second text editor has the focus. It should handle the key events.
1245 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1246 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1248 // Render and notify
1249 application.SendNotification();
1250 application.Render();
1252 // Check the text has been added to the second text editor.
1253 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1258 int utcDaliTextEditorEvent02(void)
1260 ToolkitTestApplication application;
1261 tet_infoline(" utcDaliTextEditorEvent02");
1263 // Checks if the right number of actors are created.
1265 TextEditor editor = TextEditor::New();
1266 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1267 DALI_TEST_CHECK( editor );
1269 Stage::GetCurrent().Add( editor );
1271 editor.SetSize( 300.f, 50.f );
1272 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1273 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1275 // Avoid a crash when core load gl resources.
1276 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1278 // Render and notify
1279 application.SendNotification();
1280 application.Render();
1282 // Check there are the expected number of children (the stencil).
1283 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1285 Actor stencil = editor.GetChildAt( 0u );
1287 // Create a tap event to touch the text editor.
1288 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1289 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1291 // Render and notify
1292 application.SendNotification();
1293 application.Render();
1295 Actor layer = editor.GetChildAt( 1u );
1296 DALI_TEST_CHECK( layer.IsLayer() );
1298 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1299 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1301 // Now the text editor has the focus, so it can handle the key events.
1302 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1303 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1305 // Render and notify
1306 application.SendNotification();
1307 application.Render();
1309 // Checks the cursor and the renderer have been created.
1310 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1311 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1313 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1314 DALI_TEST_CHECK( cursor );
1316 // The stencil actor has a container with all the actors which contain the text renderers.
1317 Actor container = stencil.GetChildAt( 0u );
1318 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1320 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1321 DALI_TEST_CHECK( renderer );
1324 // Move the cursor and check the position changes.
1325 Vector3 position1 = cursor.GetCurrentPosition();
1327 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1328 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1330 // Render and notify
1331 application.SendNotification();
1332 application.Render();
1334 Vector3 position2 = cursor.GetCurrentPosition();
1336 DALI_TEST_CHECK( position2.x < position1.x );
1338 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1339 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1341 // Render and notify
1342 application.SendNotification();
1343 application.Render();
1345 Vector3 position3 = cursor.GetCurrentPosition();
1347 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1349 // Send some taps and check the cursor positions.
1351 // Try to tap at the beginning.
1352 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1353 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1355 // Render and notify
1356 application.SendNotification();
1357 application.Render();
1359 // Cursor position should be the same than position1.
1360 Vector3 position4 = cursor.GetCurrentPosition();
1362 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1364 // Tap away from the start position.
1365 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1366 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1368 // Render and notify
1369 application.SendNotification();
1370 application.Render();
1372 Vector3 position5 = cursor.GetCurrentPosition();
1374 DALI_TEST_CHECK( position5.x > position4.x );
1376 // Remove all the text.
1377 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1378 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1379 editor.SetProperty( TextEditor::Property::TEXT, "" );
1381 // Render and notify
1382 application.SendNotification();
1383 application.Render();
1385 // Cursor position should be the same than position2.
1386 Vector3 position6 = cursor.GetCurrentPosition();
1388 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1390 // Should not be a renderer.
1391 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1396 int utcDaliTextEditorEvent03(void)
1398 ToolkitTestApplication application;
1399 tet_infoline(" utcDaliTextEditorEvent03");
1401 // Checks if the highlight actor is created.
1403 TextEditor editor = TextEditor::New();
1404 DALI_TEST_CHECK( editor );
1406 Stage::GetCurrent().Add( editor );
1408 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1409 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1410 editor.SetSize( 30.f, 50.f );
1411 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1412 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1414 // Avoid a crash when core load gl resources.
1415 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1417 // Render and notify
1418 application.SendNotification();
1419 application.Render();
1421 // Send some taps and check text controller with clipboard window
1422 Dali::Clipboard clipboard = Clipboard::Get();
1423 clipboard.ShowClipboard();
1424 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1425 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1426 clipboard.HideClipboard();
1428 // Render and notify
1429 application.SendNotification();
1430 application.Render();
1432 // Tap first to get the focus.
1433 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1434 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1436 // Render and notify
1437 application.SendNotification();
1438 application.Render();
1440 // Double tap to select a word.
1441 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1442 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1444 // Render and notify
1445 application.SendNotification();
1446 application.Render();
1448 // The stencil actor should have two actors: the renderer and the highlight actor.
1449 Actor stencil = editor.GetChildAt( 0u );
1451 // The stencil actor has a container with all the actors which contain the text renderers.
1452 Actor container = stencil.GetChildAt( 0u );
1453 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1455 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1456 DALI_TEST_CHECK( renderer );
1459 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1460 DALI_TEST_CHECK( highlight );
1465 int utcDaliTextEditorEvent04(void)
1467 ToolkitTestApplication application;
1468 tet_infoline(" utcDaliTextEditorEvent04");
1470 // Checks if the highlight actor is created.
1472 TextEditor editor = TextEditor::New();
1473 DALI_TEST_CHECK( editor );
1475 Stage::GetCurrent().Add( editor );
1477 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1478 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1479 editor.SetSize( 100.f, 50.f );
1480 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1481 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1483 // Avoid a crash when core load gl resources.
1484 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1486 // Render and notify
1487 application.SendNotification();
1488 application.Render();
1490 // Tap on the text editor
1491 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1492 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1494 // Render and notify
1495 application.SendNotification();
1496 application.Render();
1498 // Move at the end of the text.
1499 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1500 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1502 // Render and notify
1503 application.SendNotification();
1504 application.Render();
1506 for( unsigned int index = 0u; index < 10u; ++index )
1508 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1509 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1511 // Render and notify
1512 application.SendNotification();
1513 application.Render();
1517 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
1519 // Render and notify
1520 application.SendNotification();
1521 application.Render();
1523 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1525 // Add some key events
1526 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1527 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down ) );
1529 // Render and notify
1530 application.SendNotification();
1531 application.Render();
1533 for( unsigned int index = 0u; index < 10u; ++index )
1535 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1536 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1538 // Render and notify
1539 application.SendNotification();
1540 application.Render();
1544 application.ProcessEvent( GenerateKey( " ", " ", 0, 0, 0, Integration::KeyEvent::Down ) );
1546 // Render and notify
1547 application.SendNotification();
1548 application.Render();
1550 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1555 int utcDaliTextEditorEvent05(void)
1557 ToolkitTestApplication application;
1558 tet_infoline(" utcDaliTextEditorEvent05");
1560 // Checks if the highlight actor is created.
1562 TextEditor editor = TextEditor::New();
1563 DALI_TEST_CHECK( editor );
1565 Stage::GetCurrent().Add( editor );
1567 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1568 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1569 editor.SetSize( 50.f, 50.f );
1570 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1571 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1572 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1573 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1574 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
1575 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
1576 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
1578 // Avoid a crash when core load gl resources.
1579 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1581 // Render and notify
1582 application.SendNotification();
1583 application.Render();
1585 // Tap on the text editor
1586 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1587 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1589 // Render and notify
1590 application.SendNotification();
1591 application.Render();
1593 // Move at the end of the text.
1594 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1595 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down ) );
1597 // Render and notify
1598 application.SendNotification();
1599 application.Render();
1601 for( unsigned int index = 0u; index < 10u; ++index )
1604 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
1606 // Render and notify
1607 application.SendNotification();
1608 application.Render();
1610 // Modify duration after scroll is enabled
1611 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1613 // Continuous scroll left to increase coverage
1614 for( unsigned int index = 0u; index < 10u; ++index )
1616 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1618 // Render and notify
1619 application.SendNotification();
1620 application.Render();
1622 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1623 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1624 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
1625 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1626 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1628 // Press Escape to increase coverage
1629 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
1630 application.SendNotification();
1631 application.Render();
1633 DALI_TEST_CHECK( !editor.HasKeyInputFocus() );