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>
30 using namespace Toolkit;
32 void dali_texteditor_startup(void)
34 test_return_value = TET_UNDEF;
37 void dali_texteditor_cleanup(void)
39 test_return_value = TET_PASS;
45 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
46 const char* const PROPERTY_NAME_TEXT = "text";
47 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
48 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
49 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
50 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
51 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
52 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
53 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
54 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
55 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
56 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
57 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
58 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
59 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
60 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
61 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
62 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
67 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
68 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
69 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
70 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
71 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
72 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
73 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
74 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
76 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
77 const char* const PROPERTY_NAME_INPUT_LINE_SPACING = "inputLineSpacing";
78 const char* const PROPERTY_NAME_UNDERLINE = "underline";
79 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
80 const char* const PROPERTY_NAME_SHADOW = "shadow";
81 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
82 const char* const PROPERTY_NAME_EMBOSS = "emboss";
83 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
84 const char* const PROPERTY_NAME_OUTLINE = "outline";
85 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
87 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
89 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
91 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
92 const float TO_MILLISECONDS = 1000.f;
93 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
95 const float SCROLL_THRESHOLD = 10.f;
96 const float SCROLL_SPEED = 300.f;
98 const unsigned int DEFAULT_FONT_SIZE = 1152u;
99 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
101 const int KEY_A_CODE = 38;
102 const int KEY_D_CODE = 40;
103 const int KEY_WHITE_SPACE_CODE = 65;
105 static bool gTextChangedCallBackCalled;
106 static bool gInputStyleChangedCallbackCalled;
107 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
109 struct CallbackFunctor
111 CallbackFunctor(bool* callbackFlag)
112 : mCallbackFlag( callbackFlag )
118 *mCallbackFlag = true;
123 static void TestTextChangedCallback( TextEditor control )
125 tet_infoline(" TestTextChangedCallback");
127 gTextChangedCallBackCalled = true;
130 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
132 tet_infoline(" TestInputStyleChangedCallback");
134 gInputStyleChangedCallbackCalled = true;
135 gInputStyleMask = mask;
138 // Generate a TapGestureEvent to send to Core.
139 Integration::TapGestureEvent GenerateTap(
140 Gesture::State state,
141 unsigned int numberOfTaps,
142 unsigned int numberOfTouches,
145 Integration::TapGestureEvent tap( state );
147 tap.numberOfTaps = numberOfTaps;
148 tap.numberOfTouches = numberOfTouches;
154 // Generate a KeyEvent to send to Core.
155 Integration::KeyEvent GenerateKey( const std::string& keyName,
156 const std::string& keyString,
159 unsigned long timeStamp,
160 const Integration::KeyEvent::State& keyState )
162 return Integration::KeyEvent( keyName,
172 int UtcDaliToolkitTextEditorConstructorP(void)
174 ToolkitTestApplication application;
175 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
176 TextEditor textEditor;
177 DALI_TEST_CHECK( !textEditor );
181 int UtcDaliToolkitTextEditorNewP(void)
183 ToolkitTestApplication application;
184 tet_infoline(" UtcDaliToolkitTextEditorNewP");
185 TextEditor textEditor = TextEditor::New();
186 DALI_TEST_CHECK( textEditor );
190 int UtcDaliToolkitTextEditorDownCastP(void)
192 ToolkitTestApplication application;
193 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
194 TextEditor textEditor1 = TextEditor::New();
195 BaseHandle object( textEditor1 );
197 TextEditor textEditor2 = TextEditor::DownCast( object );
198 DALI_TEST_CHECK( textEditor2 );
200 TextEditor textEditor3 = DownCast< TextEditor >( object );
201 DALI_TEST_CHECK( textEditor3 );
205 int UtcDaliToolkitTextEditorDownCastN(void)
207 ToolkitTestApplication application;
208 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
209 BaseHandle uninitializedObject;
210 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
211 DALI_TEST_CHECK( !textEditor1 );
213 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
214 DALI_TEST_CHECK( !textEditor2 );
218 int UtcDaliToolkitTextEditorCopyConstructorP(void)
220 ToolkitTestApplication application;
221 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
222 TextEditor textEditor = TextEditor::New();
223 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
225 TextEditor copy( textEditor );
226 DALI_TEST_CHECK( copy );
227 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
231 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
233 ToolkitTestApplication application;
234 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
235 TextEditor textEditor = TextEditor::New();
236 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
238 TextEditor copy = textEditor;
239 DALI_TEST_CHECK( copy );
240 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
244 int UtcDaliTextEditorNewP(void)
246 ToolkitTestApplication application;
247 tet_infoline(" UtcDaliToolkitTextEditorNewP");
248 TextEditor textEditor = TextEditor::New();
249 DALI_TEST_CHECK( textEditor );
253 // Positive test case for a method
254 int UtcDaliTextEditorGetPropertyP(void)
256 ToolkitTestApplication application;
257 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
258 TextEditor editor = TextEditor::New();
259 DALI_TEST_CHECK( editor );
261 // Check Property Indices are correct
262 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
263 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
264 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
265 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
266 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
267 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
268 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
269 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
270 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
271 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
272 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
273 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
274 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
275 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
276 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
277 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
278 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
279 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
280 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
281 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
282 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
283 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
284 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
285 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
286 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
287 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
288 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
289 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
290 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
291 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
293 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
294 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
295 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
296 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
297 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
298 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
299 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
300 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
301 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
302 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
307 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
310 Property::Map imageMap;
311 imageMap[mapKey] =mapValue;
313 editor.SetProperty( property , imageMap );
314 Property::Value propValue = editor.GetProperty( property );
315 Property::Map* resultMap = propValue.GetMap();
317 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
325 // Positive test case for a method
326 int UtcDaliTextEditorSetPropertyP(void)
328 ToolkitTestApplication application;
329 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
330 TextEditor editor = TextEditor::New();
331 DALI_TEST_CHECK( editor );
332 Stage::GetCurrent().Add( editor );
334 // Note - we can't check the defaults since the stylesheets are platform-specific
336 // Check the render backend property.
337 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
338 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
340 // Check text property.
341 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
342 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
344 // Check text's color property
345 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
346 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
348 // Check font properties.
349 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
350 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
351 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
352 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION );
353 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
354 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
357 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
358 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
359 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"slant\":\"roman\"}" );
360 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
361 editor.SetProperty( TextEditor::Property::FONT_STYLE, "" );
362 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string(""), TEST_LOCATION );
364 // Check that the Alignment properties can be correctly set
365 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
366 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
368 // Check scroll properties.
369 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
370 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
371 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
372 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
374 // Check cursor properties
375 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
376 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
377 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
378 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
380 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
381 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
382 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
383 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
384 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
385 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
386 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
387 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
389 // Check handle images
390 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
391 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
392 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
393 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
394 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
396 // Check handle images
397 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
398 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
399 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
400 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
401 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
402 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
404 // Check the highlight color
405 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
406 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
408 // Decoration bounding box
409 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
410 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
412 // Check the enable markup property.
413 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
414 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
415 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
417 // Check input color property.
418 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
419 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
421 // Check input font properties.
422 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
423 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
424 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
425 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
426 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
427 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
429 // Reset input font style.
430 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
431 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
432 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
433 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
434 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "" );
435 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
437 // Check the line spacing property
438 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
439 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
440 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
442 // Check the input line spacing property
443 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
444 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
445 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
447 // Check the underline property
448 editor.SetProperty( TextEditor::Property::UNDERLINE, "Underline properties" );
449 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION );
451 // Check the input underline property
452 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
453 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
455 // Check the shadow property
456 editor.SetProperty( TextEditor::Property::SHADOW, "Shadow properties" );
457 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
459 // Check the input shadow property
460 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
461 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
463 // Check the emboss property
464 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
465 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
467 // Check the input emboss property
468 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
469 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
471 // Check the outline property
472 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
473 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
475 // Check the input outline property
476 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
477 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
482 // Positive Atlas Text Renderer test
483 int utcDaliTextEditorAtlasRenderP(void)
485 ToolkitTestApplication application;
486 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
487 StyleManager styleManager = StyleManager::Get();
488 styleManager.ApplyDefaultTheme();
489 TextEditor editor = TextEditor::New();
490 DALI_TEST_CHECK( editor );
492 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
494 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
496 Stage::GetCurrent().Add( editor );
500 // Render some text with the shared atlas backend
501 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
502 application.SendNotification();
503 application.Render();
507 tet_result(TET_FAIL);
512 // Positive test for the textChanged signal.
513 int utcDaliTextEditorTextChangedP(void)
515 ToolkitTestApplication application;
516 tet_infoline(" utcDaliTextEditorTextChangedP");
517 TextEditor editor = TextEditor::New();
518 DALI_TEST_CHECK( editor );
520 Stage::GetCurrent().Add( editor );
522 // connect to the text changed signal.
523 ConnectionTracker* testTracker = new ConnectionTracker();
524 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
525 bool textChangedSignal = false;
526 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
528 gTextChangedCallBackCalled = false;
529 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
530 DALI_TEST_CHECK( gTextChangedCallBackCalled );
531 DALI_TEST_CHECK( textChangedSignal );
533 application.SendNotification();
535 editor.SetKeyInputFocus();
537 gTextChangedCallBackCalled = false;
538 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
539 DALI_TEST_CHECK( gTextChangedCallBackCalled );
544 int utcDaliTextEditorInputStyleChanged01(void)
546 ToolkitTestApplication application;
547 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
549 // The text-editor emits signals when the input style changes. These changes of style are
550 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
551 // can't be emitted during the size negotiation as the callbacks may update the UI.
552 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
553 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
554 application.CreateAdaptor();
558 char* pathNamePtr = get_current_dir_name();
559 const std::string pathName( pathNamePtr );
562 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
563 fontClient.SetDpi( 93u, 93u );
565 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
566 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
568 TextEditor editor = TextEditor::New();
569 DALI_TEST_CHECK( editor );
572 editor.SetSize( 300.f, 50.f );
573 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
574 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
576 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
577 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
579 // connect to the text changed signal.
580 ConnectionTracker* testTracker = new ConnectionTracker();
581 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
582 bool inputStyleChangedSignal = false;
583 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
585 Stage::GetCurrent().Add( editor );
588 application.SendNotification();
589 application.Render();
591 // Executes the idle callbacks added by the text control on the change of input style.
592 application.RunIdles();
594 gInputStyleChangedCallbackCalled = false;
595 gInputStyleMask = TextEditor::InputStyle::NONE;
596 inputStyleChangedSignal = false;
598 // Create a tap event to touch the text editor.
599 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
600 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
603 application.SendNotification();
604 application.Render();
606 // Executes the idle callbacks added by the text control on the change of input style.
607 application.RunIdles();
609 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
610 if( gInputStyleChangedCallbackCalled )
612 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
614 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
615 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
617 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
618 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
620 DALI_TEST_CHECK( inputStyleChangedSignal );
622 gInputStyleChangedCallbackCalled = false;
623 gInputStyleMask = TextEditor::InputStyle::NONE;
624 inputStyleChangedSignal = false;
626 // Create a tap event to touch the text editor.
627 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
628 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
631 application.SendNotification();
632 application.Render();
634 // Executes the idle callbacks added by the text control on the change of input style.
635 application.RunIdles();
637 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
638 DALI_TEST_CHECK( !inputStyleChangedSignal );
640 gInputStyleChangedCallbackCalled = false;
641 gInputStyleMask = TextEditor::InputStyle::NONE;
642 inputStyleChangedSignal = false;
644 // Create a tap event to touch the text editor.
645 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
646 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
649 application.SendNotification();
650 application.Render();
652 // Executes the idle callbacks added by the text control on the change of input style.
653 application.RunIdles();
655 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
656 if( gInputStyleChangedCallbackCalled )
658 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
660 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
661 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
663 DALI_TEST_CHECK( inputStyleChangedSignal );
665 gInputStyleChangedCallbackCalled = false;
666 gInputStyleMask = TextEditor::InputStyle::NONE;
667 inputStyleChangedSignal = false;
669 // Create a tap event to touch the text editor.
670 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
671 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
674 application.SendNotification();
675 application.Render();
677 // Executes the idle callbacks added by the text control on the change of input style.
678 application.RunIdles();
680 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
681 if( gInputStyleChangedCallbackCalled )
683 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
685 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
686 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
688 const std::string style = editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ).Get<std::string>();
689 DALI_TEST_EQUALS( style, "{\"weight\":\"bold\"}", TEST_LOCATION );
691 DALI_TEST_CHECK( inputStyleChangedSignal );
693 gInputStyleChangedCallbackCalled = false;
694 gInputStyleMask = TextEditor::InputStyle::NONE;
695 inputStyleChangedSignal = false;
697 // Create a tap event to touch the text editor.
698 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
699 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
702 application.SendNotification();
703 application.Render();
705 // Executes the idle callbacks added by the text control on the change of input style.
706 application.RunIdles();
708 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
709 DALI_TEST_CHECK( !inputStyleChangedSignal );
711 gInputStyleChangedCallbackCalled = false;
712 gInputStyleMask = TextEditor::InputStyle::NONE;
713 inputStyleChangedSignal = false;
715 // Create a tap event to touch the text editor.
716 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
717 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
720 application.SendNotification();
721 application.Render();
723 // Executes the idle callbacks added by the text control on the change of input style.
724 application.RunIdles();
726 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
727 if( gInputStyleChangedCallbackCalled )
729 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
731 const std::string style = editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ).Get<std::string>();
732 DALI_TEST_CHECK( style.empty() );
734 DALI_TEST_CHECK( inputStyleChangedSignal );
736 gInputStyleChangedCallbackCalled = false;
737 gInputStyleMask = TextEditor::InputStyle::NONE;
738 inputStyleChangedSignal = false;
740 // Create a tap event to touch the text editor.
741 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
742 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
745 application.SendNotification();
746 application.Render();
748 // Executes the idle callbacks added by the text control on the change of input style.
749 application.RunIdles();
751 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
752 DALI_TEST_CHECK( !inputStyleChangedSignal );
757 int utcDaliTextEditorInputStyleChanged02(void)
759 ToolkitTestApplication application;
760 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
762 // The text-editor emits signals when the input style changes. These changes of style are
763 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
764 // can't be emitted during the size negotiation as the callbacks may update the UI.
765 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
766 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
767 application.CreateAdaptor();
771 char* pathNamePtr = get_current_dir_name();
772 const std::string pathName( pathNamePtr );
775 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
776 fontClient.SetDpi( 93u, 93u );
778 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
779 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
781 TextEditor editor = TextEditor::New();
782 DALI_TEST_CHECK( editor );
785 editor.SetSize( 300.f, 50.f );
786 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
787 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
789 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
790 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>" );
792 // connect to the text changed signal.
793 ConnectionTracker* testTracker = new ConnectionTracker();
794 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
795 bool inputStyleChangedSignal = false;
796 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
798 Stage::GetCurrent().Add( editor );
801 application.SendNotification();
802 application.Render();
804 // Executes the idle callbacks added by the text control on the change of input style.
805 application.RunIdles();
807 gInputStyleChangedCallbackCalled = false;
808 gInputStyleMask = TextEditor::InputStyle::NONE;
809 inputStyleChangedSignal = false;
811 // Create a tap event to touch the text editor.
812 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
813 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
814 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
815 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
818 application.SendNotification();
819 application.Render();
821 // Executes the idle callbacks added by the text control on the change of input style.
822 application.RunIdles();
824 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
825 if( gInputStyleChangedCallbackCalled )
827 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
828 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
829 TextEditor::InputStyle::POINT_SIZE |
830 TextEditor::InputStyle::COLOR ),
833 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
834 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
836 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
837 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
839 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
840 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
842 DALI_TEST_CHECK( inputStyleChangedSignal );
844 gInputStyleChangedCallbackCalled = false;
845 gInputStyleMask = TextEditor::InputStyle::NONE;
846 inputStyleChangedSignal = false;
848 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
851 application.SendNotification();
852 application.Render();
854 // Executes the idle callbacks added by the text control on the change of input style.
855 application.RunIdles();
857 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
858 if( gInputStyleChangedCallbackCalled )
860 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
861 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
864 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
865 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
867 DALI_TEST_CHECK( inputStyleChangedSignal );
869 gInputStyleChangedCallbackCalled = false;
870 gInputStyleMask = TextEditor::InputStyle::NONE;
871 inputStyleChangedSignal = false;
873 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
876 application.SendNotification();
877 application.Render();
879 // Executes the idle callbacks added by the text control on the change of input style.
880 application.RunIdles();
882 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
883 DALI_TEST_CHECK( !inputStyleChangedSignal );
885 gInputStyleChangedCallbackCalled = false;
886 gInputStyleMask = TextEditor::InputStyle::NONE;
887 inputStyleChangedSignal = false;
889 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
892 application.SendNotification();
893 application.Render();
895 // Executes the idle callbacks added by the text control on the change of input style.
896 application.RunIdles();
898 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
899 if( gInputStyleChangedCallbackCalled )
901 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
902 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
905 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
906 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
908 DALI_TEST_CHECK( inputStyleChangedSignal );
910 gInputStyleChangedCallbackCalled = false;
911 gInputStyleMask = TextEditor::InputStyle::NONE;
912 inputStyleChangedSignal = false;
914 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
916 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
917 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
918 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
920 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
921 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
922 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
923 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
925 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
928 application.SendNotification();
929 application.Render();
931 // Executes the idle callbacks added by the text control on the change of input style.
932 application.RunIdles();
934 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
935 DALI_TEST_CHECK( !inputStyleChangedSignal );
937 // Create a tap event to touch the text editor.
938 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
939 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
942 application.SendNotification();
943 application.Render();
945 // Executes the idle callbacks added by the text control on the change of input style.
946 application.RunIdles();
948 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
949 if( gInputStyleChangedCallbackCalled )
951 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
952 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
953 TextEditor::InputStyle::POINT_SIZE |
954 TextEditor::InputStyle::FONT_STYLE |
955 TextEditor::InputStyle::LINE_SPACING |
956 TextEditor::InputStyle::UNDERLINE |
957 TextEditor::InputStyle::SHADOW |
958 TextEditor::InputStyle::EMBOSS |
959 TextEditor::InputStyle::OUTLINE ),
962 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
963 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
965 DALI_TEST_CHECK( inputStyleChangedSignal );
967 gInputStyleChangedCallbackCalled = false;
968 gInputStyleMask = TextEditor::InputStyle::NONE;
969 inputStyleChangedSignal = false;
971 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
972 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"black\",\"width\":\"expanded\",\"slant\":\"oblique\"}" );
974 // Create a tap event to touch the text editor.
975 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
976 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
979 application.SendNotification();
980 application.Render();
982 // Executes the idle callbacks added by the text control on the change of input style.
983 application.RunIdles();
985 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
986 if( gInputStyleChangedCallbackCalled )
988 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
989 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
990 TextEditor::InputStyle::POINT_SIZE |
991 TextEditor::InputStyle::FONT_STYLE ),
994 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
995 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
997 DALI_TEST_CHECK( inputStyleChangedSignal );
1002 int utcDaliTextEditorEvent01(void)
1004 ToolkitTestApplication application;
1005 tet_infoline(" utcDaliTextEditorEvent01");
1007 // Creates a tap event. After creating a tap event the text editor should
1008 // have the focus and add text with key events should be possible.
1010 TextEditor editor = TextEditor::New();
1011 DALI_TEST_CHECK( editor );
1013 Stage::GetCurrent().Add( editor );
1015 editor.SetSize( 300.f, 50.f );
1016 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1017 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1019 // Avoid a crash when core load gl resources.
1020 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1022 // Render and notify
1023 application.SendNotification();
1024 application.Render();
1026 // Add a key event but as the text editor has not the focus it should do nothing.
1027 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1029 // Render and notify
1030 application.SendNotification();
1031 application.Render();
1033 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1035 // Create a tap event to touch the text editor.
1036 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1037 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1039 // Render and notify
1040 application.SendNotification();
1041 application.Render();
1043 // Now the text editor has the focus, so it can handle the key events.
1044 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1045 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1047 // Render and notify
1048 application.SendNotification();
1049 application.Render();
1051 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1053 // Create a second text editor and send key events to it.
1054 TextEditor editor2 = TextEditor::New();
1056 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1057 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1058 editor2.SetSize( 100.f, 100.f );
1059 editor2.SetPosition( 100.f, 100.f );
1061 Stage::GetCurrent().Add( editor2 );
1063 // Render and notify
1064 application.SendNotification();
1065 application.Render();
1067 // Create a tap event on the second text editor.
1068 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1069 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1071 // Render and notify
1072 application.SendNotification();
1073 application.Render();
1075 // The second text editor has the focus. It should handle the key events.
1076 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1077 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1079 // Render and notify
1080 application.SendNotification();
1081 application.Render();
1083 // Check the text has been added to the second text editor.
1084 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1089 int utcDaliTextEditorEvent02(void)
1091 ToolkitTestApplication application;
1092 tet_infoline(" utcDaliTextEditorEvent02");
1094 // Checks if the right number of actors are created.
1096 TextEditor editor = TextEditor::New();
1097 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1098 DALI_TEST_CHECK( editor );
1100 Stage::GetCurrent().Add( editor );
1102 editor.SetSize( 300.f, 50.f );
1103 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1104 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1106 // Avoid a crash when core load gl resources.
1107 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1109 // Render and notify
1110 application.SendNotification();
1111 application.Render();
1113 // Check there are the expected number of children (the stencil).
1114 DALI_TEST_EQUALS( editor.GetChildCount(), 1u, TEST_LOCATION );
1116 Actor stencil = editor.GetChildAt( 0u );
1118 // Create a tap event to touch the text editor.
1119 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1120 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1122 // Render and notify
1123 application.SendNotification();
1124 application.Render();
1126 Actor layer = editor.GetChildAt( 1u );
1127 DALI_TEST_CHECK( layer.IsLayer() );
1129 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1130 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1132 // Now the text editor has the focus, so it can handle the key events.
1133 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1134 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1136 // Render and notify
1137 application.SendNotification();
1138 application.Render();
1140 // Checks the cursor and the renderer have been created.
1141 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1142 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1144 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1145 DALI_TEST_CHECK( cursor );
1147 // The stencil actor has a container with all the actors which contain the text renderers.
1148 Actor container = stencil.GetChildAt( 0u );
1149 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1151 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1152 DALI_TEST_CHECK( renderer );
1155 // Move the cursor and check the position changes.
1156 Vector3 position1 = cursor.GetCurrentPosition();
1158 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1159 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1161 // Render and notify
1162 application.SendNotification();
1163 application.Render();
1165 Vector3 position2 = cursor.GetCurrentPosition();
1167 DALI_TEST_CHECK( position2.x < position1.x );
1169 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1170 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1172 // Render and notify
1173 application.SendNotification();
1174 application.Render();
1176 Vector3 position3 = cursor.GetCurrentPosition();
1178 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1180 // Send some taps and check the cursor positions.
1182 // Try to tap at the beginning.
1183 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1184 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1186 // Render and notify
1187 application.SendNotification();
1188 application.Render();
1190 // Cursor position should be the same than position1.
1191 Vector3 position4 = cursor.GetCurrentPosition();
1193 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1195 // Tap away from the start position.
1196 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1197 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1199 // Render and notify
1200 application.SendNotification();
1201 application.Render();
1203 Vector3 position5 = cursor.GetCurrentPosition();
1205 DALI_TEST_CHECK( position5.x > position4.x );
1207 // Remove all the text.
1208 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1209 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1210 editor.SetProperty( TextEditor::Property::TEXT, "" );
1212 // Render and notify
1213 application.SendNotification();
1214 application.Render();
1216 // Cursor position should be the same than position2.
1217 Vector3 position6 = cursor.GetCurrentPosition();
1219 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1221 // Should not be a renderer.
1222 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1227 int utcDaliTextEditorEvent03(void)
1229 ToolkitTestApplication application;
1230 tet_infoline(" utcDaliTextEditorEvent03");
1232 // Checks if the highlight actor is created.
1234 TextEditor editor = TextEditor::New();
1235 DALI_TEST_CHECK( editor );
1237 Stage::GetCurrent().Add( editor );
1239 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1240 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1241 editor.SetSize( 30.f, 50.f );
1242 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1243 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1245 // Avoid a crash when core load gl resources.
1246 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1248 // Render and notify
1249 application.SendNotification();
1250 application.Render();
1252 // Send some taps and check text controller with clipboard window
1253 Dali::Clipboard clipboard = Clipboard::Get();
1254 clipboard.ShowClipboard();
1255 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1256 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1257 clipboard.HideClipboard();
1259 // Render and notify
1260 application.SendNotification();
1261 application.Render();
1263 // Tap first to get the focus.
1264 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1265 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1267 // Render and notify
1268 application.SendNotification();
1269 application.Render();
1271 // Double tap to select a word.
1272 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1273 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1275 // Render and notify
1276 application.SendNotification();
1277 application.Render();
1279 // The stencil actor should have two actors: the renderer and the highlight actor.
1280 Actor stencil = editor.GetChildAt( 0u );
1282 // The stencil actor has a container with all the actors which contain the text renderers.
1283 Actor container = stencil.GetChildAt( 0u );
1284 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1286 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1287 DALI_TEST_CHECK( renderer );
1290 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1291 DALI_TEST_CHECK( highlight );