2 * Copyright (c) 2017 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/touch-event-integ.h>
26 #include <dali/integration-api/events/tap-gesture-event.h>
27 #include <dali/integration-api/events/pan-gesture-event.h>
28 #include <dali-toolkit-test-suite-utils.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
33 using namespace Toolkit;
35 void dali_texteditor_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_texteditor_cleanup(void)
42 test_return_value = TET_PASS;
48 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
49 const char* const PROPERTY_NAME_TEXT = "text";
50 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
51 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
52 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
53 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
54 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
55 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
56 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
57 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
58 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
59 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
60 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
61 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
62 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
63 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
64 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
68 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
69 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
70 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
71 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
72 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
73 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
74 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
75 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
76 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
77 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
79 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
80 const char* const PROPERTY_NAME_INPUT_LINE_SPACING = "inputLineSpacing";
81 const char* const PROPERTY_NAME_UNDERLINE = "underline";
82 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
83 const char* const PROPERTY_NAME_SHADOW = "shadow";
84 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
85 const char* const PROPERTY_NAME_EMBOSS = "emboss";
86 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
87 const char* const PROPERTY_NAME_OUTLINE = "outline";
88 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
90 const char* const PROPERTY_NAME_SMOOTH_SCROLL = "smoothScroll";
91 const char* const PROPERTY_NAME_SMOOTH_SCROLL_DURATION = "smoothScrollDuration";
92 const char* const PROPERTY_NAME_ENABLE_SCROLL_BAR = "enableScrollBar";
93 const char* const PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION = "scrollBarShowDuration";
94 const char* const PROPERTY_NAME_SCROLL_BAR_FADE_DURATION = "scrollBarFadeDuration";
96 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
98 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
100 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
101 const float TO_MILLISECONDS = 1000.f;
102 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
103 const float RENDER_FRAME_INTERVAL = 16.66f;
105 const float SCROLL_THRESHOLD = 10.f;
106 const float SCROLL_SPEED = 300.f;
108 const unsigned int DEFAULT_FONT_SIZE = 1152u;
109 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
111 const int KEY_A_CODE = 38;
112 const int KEY_D_CODE = 40;
113 const int KEY_WHITE_SPACE_CODE = 65;
115 const char* HANDLE_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/insertpoint-icon.png";
117 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
119 static bool gTextChangedCallBackCalled;
120 static bool gInputStyleChangedCallbackCalled;
121 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
123 struct CallbackFunctor
125 CallbackFunctor(bool* callbackFlag)
126 : mCallbackFlag( callbackFlag )
132 *mCallbackFlag = true;
137 static void TestTextChangedCallback( TextEditor control )
139 tet_infoline(" TestTextChangedCallback");
141 gTextChangedCallBackCalled = true;
144 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
146 tet_infoline(" TestInputStyleChangedCallback");
148 gInputStyleChangedCallbackCalled = true;
149 gInputStyleMask = mask;
152 // Generate a TapGestureEvent to send to Core.
153 Integration::TapGestureEvent GenerateTap(
154 Gesture::State state,
155 unsigned int numberOfTaps,
156 unsigned int numberOfTouches,
159 Integration::TapGestureEvent tap( state );
161 tap.numberOfTaps = numberOfTaps;
162 tap.numberOfTouches = numberOfTouches;
168 // Generate a PanGestureEvent to send to Core
169 Integration::PanGestureEvent GeneratePan( Gesture::State state,
170 const Vector2& previousPosition,
171 const Vector2& currentPosition,
172 unsigned long timeDelta,
173 unsigned int numberOfTouches = 1u )
175 Integration::PanGestureEvent pan(state);
177 pan.previousPosition = previousPosition;
178 pan.currentPosition = currentPosition;
179 pan.timeDelta = timeDelta;
180 pan.numberOfTouches = numberOfTouches;
185 // Generate a KeyEvent to send to Core.
186 Integration::KeyEvent GenerateKey( const std::string& keyName,
187 const std::string& keyString,
190 unsigned long timeStamp,
191 const Integration::KeyEvent::State& keyState,
192 const std::string& deviceName )
194 return Integration::KeyEvent( keyName,
204 * Helper to generate PanGestureEvent
206 * @param[in] application Application instance
207 * @param[in] state The Gesture State
208 * @param[in] pos The current position of touch.
210 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
214 if( (state == Gesture::Started) ||
215 (state == Gesture::Possible) )
221 application.ProcessEvent( GeneratePan( state, last, pos, 16 ) );
228 * Simulate time passed by.
230 * @note this will always process at least 1 frame (1/60 sec)
232 * @param application Test application instance
233 * @param duration Time to pass in milliseconds.
234 * @return The actual time passed in milliseconds
236 static int Wait(ToolkitTestApplication& application, int duration = 0)
240 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
242 application.SendNotification();
243 application.Render(RENDER_FRAME_INTERVAL);
244 time += RENDER_FRAME_INTERVAL;
250 Dali::Integration::Point GetPointDownInside( Vector2& pos )
252 Dali::Integration::Point point;
253 point.SetState( PointState::DOWN );
254 point.SetScreenPosition( pos );
258 Dali::Integration::Point GetPointUpInside( Vector2& pos )
260 Dali::Integration::Point point;
261 point.SetState( PointState::UP );
262 point.SetScreenPosition( pos );
266 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
268 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
270 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
272 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
274 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
275 if( NULL != valueSet )
277 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
279 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
285 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
296 int UtcDaliToolkitTextEditorConstructorP(void)
298 ToolkitTestApplication application;
299 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
300 TextEditor textEditor;
301 DALI_TEST_CHECK( !textEditor );
305 int UtcDaliToolkitTextEditorNewP(void)
307 ToolkitTestApplication application;
308 tet_infoline(" UtcDaliToolkitTextEditorNewP");
309 TextEditor textEditor = TextEditor::New();
310 DALI_TEST_CHECK( textEditor );
314 int UtcDaliToolkitTextEditorDownCastP(void)
316 ToolkitTestApplication application;
317 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
318 TextEditor textEditor1 = TextEditor::New();
319 BaseHandle object( textEditor1 );
321 TextEditor textEditor2 = TextEditor::DownCast( object );
322 DALI_TEST_CHECK( textEditor2 );
324 TextEditor textEditor3 = DownCast< TextEditor >( object );
325 DALI_TEST_CHECK( textEditor3 );
329 int UtcDaliToolkitTextEditorDownCastN(void)
331 ToolkitTestApplication application;
332 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
333 BaseHandle uninitializedObject;
334 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
335 DALI_TEST_CHECK( !textEditor1 );
337 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
338 DALI_TEST_CHECK( !textEditor2 );
342 int UtcDaliToolkitTextEditorCopyConstructorP(void)
344 ToolkitTestApplication application;
345 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
346 TextEditor textEditor = TextEditor::New();
347 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
349 TextEditor copy( textEditor );
350 DALI_TEST_CHECK( copy );
351 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
355 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
357 ToolkitTestApplication application;
358 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
359 TextEditor textEditor = TextEditor::New();
360 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
362 TextEditor copy = textEditor;
363 DALI_TEST_CHECK( copy );
364 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
368 int UtcDaliTextEditorNewP(void)
370 ToolkitTestApplication application;
371 tet_infoline(" UtcDaliToolkitTextEditorNewP");
372 TextEditor textEditor = TextEditor::New();
373 DALI_TEST_CHECK( textEditor );
377 // Positive test case for a method
378 int UtcDaliTextEditorGetPropertyP(void)
380 ToolkitTestApplication application;
381 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
382 TextEditor editor = TextEditor::New();
383 DALI_TEST_CHECK( editor );
385 // Check Property Indices are correct
386 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
387 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
388 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
389 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
390 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
391 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
392 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
393 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
394 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
395 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
396 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
397 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
398 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
399 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
400 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
401 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
402 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
403 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
404 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
405 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
406 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
407 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
408 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
409 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
410 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
411 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
412 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
413 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
414 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
415 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
417 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
418 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
419 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
420 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
421 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
422 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
423 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
424 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
425 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
426 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
427 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL ) == DevelTextEditor::Property::SMOOTH_SCROLL );
428 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SMOOTH_SCROLL_DURATION ) == DevelTextEditor::Property::SMOOTH_SCROLL_DURATION );
429 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SCROLL_BAR ) == DevelTextEditor::Property::ENABLE_SCROLL_BAR );
430 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_SHOW_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION );
431 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_BAR_FADE_DURATION ) == DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION );
436 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
439 Property::Map imageMap;
440 imageMap[mapKey] =mapValue;
442 editor.SetProperty( property , imageMap );
443 Property::Value propValue = editor.GetProperty( property );
444 Property::Map* resultMap = propValue.GetMap();
446 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
454 // Positive test case for a method
455 int UtcDaliTextEditorSetPropertyP(void)
457 ToolkitTestApplication application;
458 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
459 TextEditor editor = TextEditor::New();
460 DALI_TEST_CHECK( editor );
461 Stage::GetCurrent().Add( editor );
463 // Note - we can't check the defaults since the stylesheets are platform-specific
465 // Check the render backend property.
466 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
467 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
469 // Check text property.
470 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
471 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
473 // Check text's color property
474 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
475 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
477 // Check font properties.
478 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
479 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
481 Property::Map fontStyleMapSet;
482 Property::Map fontStyleMapGet;
483 Property::Value* slantValue = NULL;
485 fontStyleMapSet.Insert( "weight", "bold" );
486 fontStyleMapSet.Insert( "width", "condensed" );
487 fontStyleMapSet.Insert( "slant", "italic" );
489 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
490 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
491 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
492 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
494 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
495 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
498 fontStyleMapSet.Clear();
499 fontStyleMapSet.Insert( "weight", "normal" );
500 fontStyleMapSet.Insert( "slant", "oblique" );
501 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
502 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
503 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
504 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
506 fontStyleMapSet.Clear();
507 fontStyleMapSet.Insert( "slant", "roman" );
508 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
509 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
511 // Replace 'roman' for 'normal'.
512 slantValue = fontStyleMapGet.Find( "slant" );
513 if( NULL != slantValue )
515 if( "normal" == slantValue->Get<std::string>() )
517 fontStyleMapGet["slant"] = "roman";
520 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
521 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
523 fontStyleMapSet.Clear();
525 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
526 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
527 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
528 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
530 // Check that the Alignment properties can be correctly set
531 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
532 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
534 // Check scroll properties.
535 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
536 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
537 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
538 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
540 // Check cursor properties
541 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
542 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
543 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
544 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
546 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
547 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
548 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
549 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
550 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
551 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
552 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
553 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
555 // Check handle images
556 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
557 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
558 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
559 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
560 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
562 // Check handle images
563 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
564 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
565 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
566 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
567 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
568 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
570 // Check the highlight color
571 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
572 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
574 // Decoration bounding box
575 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
576 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
578 // Check the enable markup property.
579 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
580 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
581 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
583 // Check input color property.
584 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
585 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
587 // Check input font properties.
588 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
589 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
591 fontStyleMapSet.Clear();
592 fontStyleMapSet.Insert( "weight", "bold" );
593 fontStyleMapSet.Insert( "width", "condensed" );
594 fontStyleMapSet.Insert( "slant", "italic" );
596 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
597 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
598 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
599 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
601 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
602 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
604 // Reset input font style.
605 fontStyleMapSet.Clear();
606 fontStyleMapSet.Insert( "weight", "normal" );
607 fontStyleMapSet.Insert( "slant", "oblique" );
609 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
610 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
611 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
612 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
614 fontStyleMapSet.Clear();
615 fontStyleMapSet.Insert( "slant", "roman" );
617 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
618 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
620 // Replace 'roman' for 'normal'.
621 slantValue = fontStyleMapGet.Find( "slant" );
622 if( NULL != slantValue )
624 if( "normal" == slantValue->Get<std::string>() )
626 fontStyleMapGet["slant"] = "roman";
629 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
630 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
632 fontStyleMapSet.Clear();
634 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
635 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
636 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
637 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
639 // Check the line spacing property
640 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
641 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
642 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
644 // Check the input line spacing property
645 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
646 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
647 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
649 // Check the underline property
651 Property::Map underlineMapSet;
652 Property::Map underlineMapGet;
654 underlineMapSet.Insert( "enable", "true" );
655 underlineMapSet.Insert( "color", "red" );
656 underlineMapSet.Insert( "height", "1" );
658 editor.SetProperty( TextEditor::Property::UNDERLINE, underlineMapSet );
660 underlineMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::UNDERLINE );
661 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
662 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
664 // Check the input underline property
665 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
666 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
668 // Check the shadow property
669 Property::Map shadowMapSet;
670 Property::Map shadowMapGet;
672 shadowMapSet.Insert( "color", "green" );
673 shadowMapSet.Insert( "offset", "2 2" );
675 editor.SetProperty( TextEditor::Property::SHADOW, shadowMapSet );
677 shadowMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::SHADOW );
678 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
679 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
681 // Check the input shadow property
682 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
683 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
685 // Check the emboss property
686 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
687 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
689 // Check the input emboss property
690 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
691 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
693 // Check the outline property
694 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
695 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
697 // Check the input outline property
698 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
699 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
701 // Check the smooth scroll property
702 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), false, TEST_LOCATION );
703 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
704 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
706 // Check the smooth scroll duration property
707 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
708 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
710 // Check the scroll bar property
711 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), false, TEST_LOCATION );
712 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
713 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
715 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
716 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
717 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
718 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
723 // Positive Atlas Text Renderer test
724 int utcDaliTextEditorAtlasRenderP(void)
726 ToolkitTestApplication application;
727 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
728 StyleManager styleManager = StyleManager::Get();
729 styleManager.ApplyDefaultTheme();
730 TextEditor editor = TextEditor::New();
731 DALI_TEST_CHECK( editor );
733 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
735 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
737 Stage::GetCurrent().Add( editor );
741 // Render some text with the shared atlas backend
742 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
743 application.SendNotification();
744 application.Render();
748 tet_result(TET_FAIL);
753 // Positive test for the textChanged signal.
754 int utcDaliTextEditorTextChangedP(void)
756 ToolkitTestApplication application;
757 tet_infoline(" utcDaliTextEditorTextChangedP");
758 TextEditor editor = TextEditor::New();
759 DALI_TEST_CHECK( editor );
761 Stage::GetCurrent().Add( editor );
763 // connect to the text changed signal.
764 ConnectionTracker* testTracker = new ConnectionTracker();
765 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
766 bool textChangedSignal = false;
767 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
769 gTextChangedCallBackCalled = false;
770 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
771 DALI_TEST_CHECK( gTextChangedCallBackCalled );
772 DALI_TEST_CHECK( textChangedSignal );
774 application.SendNotification();
776 editor.SetKeyInputFocus();
778 gTextChangedCallBackCalled = false;
779 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
780 DALI_TEST_CHECK( gTextChangedCallBackCalled );
785 int utcDaliTextEditorInputStyleChanged01(void)
787 ToolkitTestApplication application;
788 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
790 // The text-editor emits signals when the input style changes. These changes of style are
791 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
792 // can't be emitted during the size negotiation as the callbacks may update the UI.
793 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
794 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
795 application.CreateAdaptor();
799 char* pathNamePtr = get_current_dir_name();
800 const std::string pathName( pathNamePtr );
803 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
804 fontClient.SetDpi( 93u, 93u );
806 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
807 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
809 TextEditor editor = TextEditor::New();
810 DALI_TEST_CHECK( editor );
813 editor.SetSize( 300.f, 50.f );
814 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
815 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
817 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
818 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
820 // connect to the text changed signal.
821 ConnectionTracker* testTracker = new ConnectionTracker();
822 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
823 bool inputStyleChangedSignal = false;
824 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
826 Stage::GetCurrent().Add( editor );
829 application.SendNotification();
830 application.Render();
832 // Executes the idle callbacks added by the text control on the change of input style.
833 application.RunIdles();
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( 18.f, 25.f ) ) );
841 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.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 if( gInputStyleChangedCallbackCalled )
853 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
855 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
856 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
858 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
859 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
861 DALI_TEST_CHECK( inputStyleChangedSignal );
863 gInputStyleChangedCallbackCalled = false;
864 gInputStyleMask = TextEditor::InputStyle::NONE;
865 inputStyleChangedSignal = false;
867 // Create a tap event to touch the text editor.
868 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
869 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
872 application.SendNotification();
873 application.Render();
875 // Executes the idle callbacks added by the text control on the change of input style.
876 application.RunIdles();
878 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
879 DALI_TEST_CHECK( !inputStyleChangedSignal );
881 gInputStyleChangedCallbackCalled = false;
882 gInputStyleMask = TextEditor::InputStyle::NONE;
883 inputStyleChangedSignal = false;
885 // Create a tap event to touch the text editor.
886 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
887 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
890 application.SendNotification();
891 application.Render();
893 // Executes the idle callbacks added by the text control on the change of input style.
894 application.RunIdles();
896 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
897 if( gInputStyleChangedCallbackCalled )
899 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
901 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
902 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
904 DALI_TEST_CHECK( inputStyleChangedSignal );
906 gInputStyleChangedCallbackCalled = false;
907 gInputStyleMask = TextEditor::InputStyle::NONE;
908 inputStyleChangedSignal = false;
910 // Create a tap event to touch the text editor.
911 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
912 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
915 application.SendNotification();
916 application.Render();
918 // Executes the idle callbacks added by the text control on the change of input style.
919 application.RunIdles();
921 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
922 if( gInputStyleChangedCallbackCalled )
924 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
926 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
927 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
929 Property::Map fontStyleMapSet;
930 Property::Map fontStyleMapGet;
932 fontStyleMapSet.Insert( "weight", "bold" );
934 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
935 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
936 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
938 DALI_TEST_CHECK( inputStyleChangedSignal );
940 gInputStyleChangedCallbackCalled = false;
941 gInputStyleMask = TextEditor::InputStyle::NONE;
942 inputStyleChangedSignal = false;
944 // Create a tap event to touch the text editor.
945 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
946 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
949 application.SendNotification();
950 application.Render();
952 // Executes the idle callbacks added by the text control on the change of input style.
953 application.RunIdles();
955 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
956 DALI_TEST_CHECK( !inputStyleChangedSignal );
958 gInputStyleChangedCallbackCalled = false;
959 gInputStyleMask = TextEditor::InputStyle::NONE;
960 inputStyleChangedSignal = false;
962 // Create a tap event to touch the text editor.
963 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
964 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
967 application.SendNotification();
968 application.Render();
970 // Executes the idle callbacks added by the text control on the change of input style.
971 application.RunIdles();
973 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
974 if( gInputStyleChangedCallbackCalled )
976 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
978 Property::Map fontStyleMapSet;
979 Property::Map fontStyleMapGet;
981 fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
982 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
983 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
985 DALI_TEST_CHECK( inputStyleChangedSignal );
987 gInputStyleChangedCallbackCalled = false;
988 gInputStyleMask = TextEditor::InputStyle::NONE;
989 inputStyleChangedSignal = false;
991 // Create a tap event to touch the text editor.
992 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
993 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
996 application.SendNotification();
997 application.Render();
999 // Executes the idle callbacks added by the text control on the change of input style.
1000 application.RunIdles();
1002 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1003 DALI_TEST_CHECK( !inputStyleChangedSignal );
1008 int utcDaliTextEditorInputStyleChanged02(void)
1010 ToolkitTestApplication application;
1011 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
1013 // The text-editor emits signals when the input style changes. These changes of style are
1014 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1015 // can't be emitted during the size negotiation as the callbacks may update the UI.
1016 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
1017 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1018 application.CreateAdaptor();
1022 char* pathNamePtr = get_current_dir_name();
1023 const std::string pathName( pathNamePtr );
1024 free( pathNamePtr );
1026 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1027 fontClient.SetDpi( 93u, 93u );
1029 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1030 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1032 TextEditor editor = TextEditor::New();
1033 DALI_TEST_CHECK( editor );
1036 editor.SetSize( 300.f, 50.f );
1037 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1038 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1040 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
1041 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>" );
1043 // connect to the text changed signal.
1044 ConnectionTracker* testTracker = new ConnectionTracker();
1045 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1046 bool inputStyleChangedSignal = false;
1047 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1049 Stage::GetCurrent().Add( editor );
1051 // Render and notify
1052 application.SendNotification();
1053 application.Render();
1055 // Executes the idle callbacks added by the text control on the change of input style.
1056 application.RunIdles();
1058 gInputStyleChangedCallbackCalled = false;
1059 gInputStyleMask = TextEditor::InputStyle::NONE;
1060 inputStyleChangedSignal = false;
1062 // Create a tap event to touch the text editor.
1063 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1064 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1065 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1066 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1068 // Render and notify
1069 application.SendNotification();
1070 application.Render();
1072 // Executes the idle callbacks added by the text control on the change of input style.
1073 application.RunIdles();
1075 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1076 if( gInputStyleChangedCallbackCalled )
1078 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1079 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
1080 TextEditor::InputStyle::POINT_SIZE |
1081 TextEditor::InputStyle::COLOR ),
1084 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1085 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1087 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1088 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1090 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
1091 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1093 DALI_TEST_CHECK( inputStyleChangedSignal );
1095 gInputStyleChangedCallbackCalled = false;
1096 gInputStyleMask = TextEditor::InputStyle::NONE;
1097 inputStyleChangedSignal = false;
1099 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1101 // Render and notify
1102 application.SendNotification();
1103 application.Render();
1105 // Executes the idle callbacks added by the text control on the change of input style.
1106 application.RunIdles();
1108 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1109 if( gInputStyleChangedCallbackCalled )
1111 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1112 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1115 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1116 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1118 DALI_TEST_CHECK( inputStyleChangedSignal );
1120 gInputStyleChangedCallbackCalled = false;
1121 gInputStyleMask = TextEditor::InputStyle::NONE;
1122 inputStyleChangedSignal = false;
1124 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1126 // Render and notify
1127 application.SendNotification();
1128 application.Render();
1130 // Executes the idle callbacks added by the text control on the change of input style.
1131 application.RunIdles();
1133 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1134 DALI_TEST_CHECK( !inputStyleChangedSignal );
1136 gInputStyleChangedCallbackCalled = false;
1137 gInputStyleMask = TextEditor::InputStyle::NONE;
1138 inputStyleChangedSignal = false;
1140 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1142 // Render and notify
1143 application.SendNotification();
1144 application.Render();
1146 // Executes the idle callbacks added by the text control on the change of input style.
1147 application.RunIdles();
1149 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1150 if( gInputStyleChangedCallbackCalled )
1152 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1153 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1156 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1157 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1159 DALI_TEST_CHECK( inputStyleChangedSignal );
1161 gInputStyleChangedCallbackCalled = false;
1162 gInputStyleMask = TextEditor::InputStyle::NONE;
1163 inputStyleChangedSignal = false;
1165 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1167 Property::Map fontStyleMapSet;
1168 fontStyleMapSet.Insert( "weight", "thin" );
1169 fontStyleMapSet.Insert( "width", "condensed" );
1170 fontStyleMapSet.Insert( "slant", "italic" );
1172 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1173 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1174 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1176 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1177 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1178 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1179 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1181 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1183 // Render and notify
1184 application.SendNotification();
1185 application.Render();
1187 // Executes the idle callbacks added by the text control on the change of input style.
1188 application.RunIdles();
1190 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1191 DALI_TEST_CHECK( !inputStyleChangedSignal );
1193 // Create a tap event to touch the text editor.
1194 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1195 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1197 // Render and notify
1198 application.SendNotification();
1199 application.Render();
1201 // Executes the idle callbacks added by the text control on the change of input style.
1202 application.RunIdles();
1204 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1205 if( gInputStyleChangedCallbackCalled )
1207 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1208 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1209 TextEditor::InputStyle::POINT_SIZE |
1210 TextEditor::InputStyle::FONT_STYLE |
1211 TextEditor::InputStyle::LINE_SPACING |
1212 TextEditor::InputStyle::UNDERLINE |
1213 TextEditor::InputStyle::SHADOW |
1214 TextEditor::InputStyle::EMBOSS |
1215 TextEditor::InputStyle::OUTLINE ),
1218 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1219 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1221 DALI_TEST_CHECK( inputStyleChangedSignal );
1223 gInputStyleChangedCallbackCalled = false;
1224 gInputStyleMask = TextEditor::InputStyle::NONE;
1225 inputStyleChangedSignal = false;
1227 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1229 fontStyleMapSet.Clear();
1230 fontStyleMapSet.Insert( "weight", "black" );
1231 fontStyleMapSet.Insert( "width", "expanded" );
1232 fontStyleMapSet.Insert( "slant", "oblique" );
1234 editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1236 // Create a tap event to touch the text editor.
1237 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1238 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1240 // Render and notify
1241 application.SendNotification();
1242 application.Render();
1244 // Executes the idle callbacks added by the text control on the change of input style.
1245 application.RunIdles();
1247 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1248 if( gInputStyleChangedCallbackCalled )
1250 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1251 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1252 TextEditor::InputStyle::POINT_SIZE |
1253 TextEditor::InputStyle::FONT_STYLE ),
1256 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1257 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1259 DALI_TEST_CHECK( inputStyleChangedSignal );
1264 int utcDaliTextEditorEvent01(void)
1266 ToolkitTestApplication application;
1267 tet_infoline(" utcDaliTextEditorEvent01");
1269 // Creates a tap event. After creating a tap event the text editor should
1270 // have the focus and add text with key events should be possible.
1272 TextEditor editor = TextEditor::New();
1273 DALI_TEST_CHECK( editor );
1275 Stage::GetCurrent().Add( editor );
1277 editor.SetSize( 300.f, 50.f );
1278 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1279 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1281 // Avoid a crash when core load gl resources.
1282 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1284 // Render and notify
1285 application.SendNotification();
1286 application.Render();
1288 // Add a key event but as the text editor has not the focus it should do nothing.
1289 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1291 // Render and notify
1292 application.SendNotification();
1293 application.Render();
1295 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1297 // Create a tap event to touch the text editor.
1298 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1299 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1301 // Render and notify
1302 application.SendNotification();
1303 application.Render();
1305 // Now the text editor has the focus, so it can handle the key events.
1306 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1307 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1309 // Render and notify
1310 application.SendNotification();
1311 application.Render();
1313 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1315 // Create a second text editor and send key events to it.
1316 TextEditor editor2 = TextEditor::New();
1318 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1319 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1320 editor2.SetSize( 100.f, 100.f );
1321 editor2.SetPosition( 100.f, 100.f );
1323 Stage::GetCurrent().Add( editor2 );
1325 // Render and notify
1326 application.SendNotification();
1327 application.Render();
1329 // Create a tap event on the second text editor.
1330 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1331 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1333 // Render and notify
1334 application.SendNotification();
1335 application.Render();
1337 // The second text editor has the focus. It should handle the key events.
1338 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1339 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1341 // Render and notify
1342 application.SendNotification();
1343 application.Render();
1345 // Check the text has been added to the second text editor.
1346 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1351 int utcDaliTextEditorEvent02(void)
1353 ToolkitTestApplication application;
1354 tet_infoline(" utcDaliTextEditorEvent02");
1356 // Checks if the right number of actors are created.
1358 TextEditor editor = TextEditor::New();
1359 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1360 DALI_TEST_CHECK( editor );
1362 Stage::GetCurrent().Add( editor );
1364 editor.SetSize( 300.f, 50.f );
1365 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1366 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1368 // Avoid a crash when core load gl resources.
1369 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1371 // Render and notify
1372 application.SendNotification();
1373 application.Render();
1375 // Check there are the expected number of children (the stencil).
1376 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1378 Actor stencil = editor.GetChildAt( 0u );
1380 // Create a tap event to touch the text editor.
1381 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1382 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1384 // Render and notify
1385 application.SendNotification();
1386 application.Render();
1388 Actor layer = editor.GetChildAt( 1u );
1389 DALI_TEST_CHECK( layer.IsLayer() );
1391 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1392 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1394 // Now the text editor has the focus, so it can handle the key events.
1395 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1396 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1398 // Render and notify
1399 application.SendNotification();
1400 application.Render();
1402 // Checks the cursor and the renderer have been created.
1403 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1404 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1406 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1407 DALI_TEST_CHECK( cursor );
1409 // The stencil actor has a container with all the actors which contain the text renderers.
1410 Actor container = stencil.GetChildAt( 0u );
1411 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1413 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1414 DALI_TEST_CHECK( renderer );
1417 // Move the cursor and check the position changes.
1418 Vector3 position1 = cursor.GetCurrentPosition();
1420 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1421 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1423 // Render and notify
1424 application.SendNotification();
1425 application.Render();
1427 Vector3 position2 = cursor.GetCurrentPosition();
1429 DALI_TEST_CHECK( position2.x < position1.x );
1431 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1432 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1434 // Render and notify
1435 application.SendNotification();
1436 application.Render();
1438 Vector3 position3 = cursor.GetCurrentPosition();
1440 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1442 // Send some taps and check the cursor positions.
1444 // Try to tap at the beginning.
1445 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1446 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1448 // Render and notify
1449 application.SendNotification();
1450 application.Render();
1452 // Cursor position should be the same than position1.
1453 Vector3 position4 = cursor.GetCurrentPosition();
1455 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1457 // Tap away from the start position.
1458 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1459 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1461 // Render and notify
1462 application.SendNotification();
1463 application.Render();
1465 Vector3 position5 = cursor.GetCurrentPosition();
1467 DALI_TEST_CHECK( position5.x > position4.x );
1469 // Remove all the text.
1470 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1471 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1472 editor.SetProperty( TextEditor::Property::TEXT, "" );
1474 // Render and notify
1475 application.SendNotification();
1476 application.Render();
1478 // Cursor position should be the same than position2.
1479 Vector3 position6 = cursor.GetCurrentPosition();
1481 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1483 // Should not be a renderer.
1484 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1489 int utcDaliTextEditorEvent03(void)
1491 ToolkitTestApplication application;
1492 tet_infoline(" utcDaliTextEditorEvent03");
1494 // Checks if the highlight actor is created.
1496 TextEditor editor = TextEditor::New();
1497 DALI_TEST_CHECK( editor );
1499 Stage::GetCurrent().Add( editor );
1501 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1502 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1503 editor.SetSize( 30.f, 50.f );
1504 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1505 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1507 // Avoid a crash when core load gl resources.
1508 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1510 // Render and notify
1511 application.SendNotification();
1512 application.Render();
1514 // Send some taps and check text controller with clipboard window
1515 Dali::Clipboard clipboard = Clipboard::Get();
1516 clipboard.ShowClipboard();
1517 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1518 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1519 clipboard.HideClipboard();
1521 // Render and notify
1522 application.SendNotification();
1523 application.Render();
1525 // Tap first to get the focus.
1526 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1527 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1529 // Render and notify
1530 application.SendNotification();
1531 application.Render();
1533 // Double tap to select a word.
1534 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1535 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1537 // Render and notify
1538 application.SendNotification();
1539 application.Render();
1541 // The stencil actor should have two actors: the renderer and the highlight actor.
1542 Actor stencil = editor.GetChildAt( 0u );
1544 // The stencil actor has a container with all the actors which contain the text renderers.
1545 Actor container = stencil.GetChildAt( 0u );
1546 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1548 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1549 DALI_TEST_CHECK( renderer );
1552 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1553 DALI_TEST_CHECK( highlight );
1555 // Double tap out of bounds
1556 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1557 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 29.f, 25.0f ) ) );
1559 // Render and notify
1560 application.SendNotification();
1561 application.Render();
1563 // The stencil actor should have one actors: the renderer actor.
1564 stencil = editor.GetChildAt( 0u );
1566 // The stencil actor has a container with all the actors which contain the text renderers.
1567 container = stencil.GetChildAt( 0u );
1568 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1570 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1571 DALI_TEST_CHECK( renderer );
1577 int utcDaliTextEditorEvent04(void)
1579 ToolkitTestApplication application;
1580 tet_infoline(" utcDaliTextEditorEvent04");
1582 // Checks if the highlight actor is created.
1584 TextEditor editor = TextEditor::New();
1585 DALI_TEST_CHECK( editor );
1587 Stage::GetCurrent().Add( editor );
1589 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1590 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1591 editor.SetSize( 100.f, 50.f );
1592 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1593 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1595 // Avoid a crash when core load gl resources.
1596 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1598 // Render and notify
1599 application.SendNotification();
1600 application.Render();
1602 // Tap on the text editor
1603 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1604 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1606 // Render and notify
1607 application.SendNotification();
1608 application.Render();
1610 // Move at the end of the text.
1611 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1612 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1614 // Render and notify
1615 application.SendNotification();
1616 application.Render();
1618 for( unsigned int index = 0u; index < 10u; ++index )
1620 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1621 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1623 // Render and notify
1624 application.SendNotification();
1625 application.Render();
1629 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1631 // Render and notify
1632 application.SendNotification();
1633 application.Render();
1635 DALI_TEST_EQUALS( "Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1637 // Add some key events
1638 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1639 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_UP, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1641 // Render and notify
1642 application.SendNotification();
1643 application.Render();
1645 for( unsigned int index = 0u; index < 10u; ++index )
1647 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1648 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1650 // Render and notify
1651 application.SendNotification();
1652 application.Render();
1656 application.ProcessEvent( GenerateKey( " ", " ", KEY_WHITE_SPACE_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1658 // Render and notify
1659 application.SendNotification();
1660 application.Render();
1662 DALI_TEST_EQUALS( " Hello\nworld", editor.GetProperty<std::string>( TextEditor::Property::TEXT ), TEST_LOCATION );
1667 int utcDaliTextEditorEvent05(void)
1669 ToolkitTestApplication application;
1670 tet_infoline(" utcDaliTextEditorEvent05");
1672 // Checks if the highlight actor is created.
1674 TextEditor editor = TextEditor::New();
1675 DALI_TEST_CHECK( editor );
1677 Stage::GetCurrent().Add( editor );
1679 editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworl" );
1680 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1681 editor.SetSize( 50.f, 50.f );
1682 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1683 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1684 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1685 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.2f );
1686 editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
1687 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION, 0.3f );
1688 editor.SetProperty( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION, 0.2f );
1690 // Avoid a crash when core load gl resources.
1691 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1693 // Render and notify
1694 application.SendNotification();
1695 application.Render();
1697 // Tap on the text editor
1698 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1699 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1701 // Render and notify
1702 application.SendNotification();
1703 application.Render();
1705 // Move at the end of the text.
1706 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1707 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1709 // Render and notify
1710 application.SendNotification();
1711 application.Render();
1713 for( unsigned int index = 0u; index < 10u; ++index )
1716 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1718 // Render and notify
1719 application.SendNotification();
1720 application.Render();
1722 // Modify duration after scroll is enabled
1723 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION, 0.1f );
1725 // Continuous scroll left to increase coverage
1726 for( unsigned int index = 0u; index < 10u; ++index )
1728 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME ) );
1730 // Render and notify
1731 application.SendNotification();
1732 application.Render();
1734 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SMOOTH_SCROLL_DURATION ), 0.1f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1735 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::SMOOTH_SCROLL ), true, TEST_LOCATION );
1736 DALI_TEST_EQUALS( editor.GetProperty<bool>( DevelTextEditor::Property::ENABLE_SCROLL_BAR ), true, TEST_LOCATION );
1737 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_SHOW_DURATION ), 0.3f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1738 DALI_TEST_EQUALS( editor.GetProperty<float>( DevelTextEditor::Property::SCROLL_BAR_FADE_DURATION ), 0.2f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1740 // Press Escape to increase coverage
1741 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME ) );
1742 application.SendNotification();
1743 application.Render();
1745 DALI_TEST_CHECK( !editor.HasKeyInputFocus() );
1750 int utcDaliTextEditorHandles(void)
1752 ToolkitTestApplication application;
1753 tet_infoline(" utcDaliTextEditorHandles");
1755 TextEditor editor = TextEditor::New();
1756 DALI_TEST_CHECK( editor );
1758 Stage::GetCurrent().Add( editor );
1760 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1761 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1762 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, HANDLE_IMAGE_FILE_NAME );
1763 editor.SetProperty( DevelTextEditor::Property::SMOOTH_SCROLL, true );
1765 editor.SetSize( 30.f, 500.f );
1766 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1767 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1769 // Avoid a crash when core load gl resources.
1770 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1772 // Render and notify
1773 application.SendNotification();
1774 application.Render();
1776 // Tap first to get the focus.
1777 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1778 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1780 // Render and notify
1781 application.SendNotification();
1782 application.Render();
1784 // Tap to create the grab handle.
1785 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1786 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1788 // Render and notify
1789 application.SendNotification();
1790 application.Render();
1792 // Get the active layer where the text's decoration is added.
1793 Actor activeLayer = editor.GetChildAt( 1u );
1795 // Get the handle's actor.
1796 Actor handle = activeLayer.GetChildAt( 1u );
1797 handle.SetSize( 100.f, 100.f );
1799 // Render and notify
1800 application.SendNotification();
1801 application.Render();
1803 // Touch the grab handle to set it as pressed.
1804 Vector2 touchPos( 10.0f, 50.0f );
1805 Dali::Integration::TouchEvent event;
1806 event = Dali::Integration::TouchEvent();
1807 event.AddPoint( GetPointDownInside( touchPos ) );
1808 application.ProcessEvent( event );
1810 // Render and notify
1811 application.SendNotification();
1812 application.Render();
1814 // drag grab handle right
1815 SendPan(application, Gesture::Possible, touchPos);
1816 SendPan(application, Gesture::Started, touchPos);
1818 Wait(application, 100);
1820 for(int i = 0;i<20;i++)
1822 SendPan(application, Gesture::Continuing, touchPos);
1827 SendPan(application, Gesture::Finished, touchPos);
1830 // Release the grab handle.
1831 event = Dali::Integration::TouchEvent();
1832 event.AddPoint( GetPointUpInside( touchPos ) );
1833 application.ProcessEvent( event );
1835 // Render and notify
1836 application.SendNotification();
1837 application.Render();