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 static bool gTextChangedCallBackCalled;
102 static bool gInputStyleChangedCallbackCalled;
103 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
105 struct CallbackFunctor
107 CallbackFunctor(bool* callbackFlag)
108 : mCallbackFlag( callbackFlag )
114 *mCallbackFlag = true;
119 static void TestTextChangedCallback( TextEditor control )
121 tet_infoline(" TestTextChangedCallback");
123 gTextChangedCallBackCalled = true;
126 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
128 tet_infoline(" TestInputStyleChangedCallback");
130 gInputStyleChangedCallbackCalled = true;
131 gInputStyleMask = mask;
134 // Generate a TapGestureEvent to send to Core.
135 Integration::TapGestureEvent GenerateTap(
136 Gesture::State state,
137 unsigned int numberOfTaps,
138 unsigned int numberOfTouches,
141 Integration::TapGestureEvent tap( state );
143 tap.numberOfTaps = numberOfTaps;
144 tap.numberOfTouches = numberOfTouches;
150 // Generate a KeyEvent to send to Core.
151 Integration::KeyEvent GenerateKey( const std::string& keyName,
152 const std::string& keyString,
155 unsigned long timeStamp,
156 const Integration::KeyEvent::State& keyState )
158 return Integration::KeyEvent( keyName,
168 int UtcDaliToolkitTextEditorConstructorP(void)
170 ToolkitTestApplication application;
171 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
172 TextEditor textEditor;
173 DALI_TEST_CHECK( !textEditor );
177 int UtcDaliToolkitTextEditorNewP(void)
179 ToolkitTestApplication application;
180 tet_infoline(" UtcDaliToolkitTextEditorNewP");
181 TextEditor textEditor = TextEditor::New();
182 DALI_TEST_CHECK( textEditor );
186 int UtcDaliToolkitTextEditorDownCastP(void)
188 ToolkitTestApplication application;
189 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
190 TextEditor textEditor1 = TextEditor::New();
191 BaseHandle object( textEditor1 );
193 TextEditor textEditor2 = TextEditor::DownCast( object );
194 DALI_TEST_CHECK( textEditor2 );
196 TextEditor textEditor3 = DownCast< TextEditor >( object );
197 DALI_TEST_CHECK( textEditor3 );
201 int UtcDaliToolkitTextEditorDownCastN(void)
203 ToolkitTestApplication application;
204 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
205 BaseHandle uninitializedObject;
206 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
207 DALI_TEST_CHECK( !textEditor1 );
209 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
210 DALI_TEST_CHECK( !textEditor2 );
214 int UtcDaliToolkitTextEditorCopyConstructorP(void)
216 ToolkitTestApplication application;
217 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
218 TextEditor textEditor = TextEditor::New();
219 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
221 TextEditor copy( textEditor );
222 DALI_TEST_CHECK( copy );
223 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
227 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
229 ToolkitTestApplication application;
230 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
231 TextEditor textEditor = TextEditor::New();
232 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
234 TextEditor copy = textEditor;
235 DALI_TEST_CHECK( copy );
236 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
240 int UtcDaliTextEditorNewP(void)
242 ToolkitTestApplication application;
243 tet_infoline(" UtcDaliToolkitTextEditorNewP");
244 TextEditor textEditor = TextEditor::New();
245 DALI_TEST_CHECK( textEditor );
249 // Positive test case for a method
250 int UtcDaliTextEditorGetPropertyP(void)
252 ToolkitTestApplication application;
253 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
254 TextEditor editor = TextEditor::New();
255 DALI_TEST_CHECK( editor );
257 // Check Property Indices are correct
258 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
259 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
260 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
261 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
262 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
263 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
264 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
265 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
266 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
267 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
268 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
269 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
270 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
271 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
272 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
273 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
274 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
275 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
276 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
277 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
278 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
279 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
280 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
281 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
282 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
283 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
284 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
285 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
286 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
287 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
289 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
290 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
291 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
292 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
293 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
294 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
295 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
296 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
297 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
298 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
303 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
306 Property::Map imageMap;
307 imageMap[mapKey] =mapValue;
309 editor.SetProperty( property , imageMap );
310 Property::Value propValue = editor.GetProperty( property );
311 Property::Map* resultMap = propValue.GetMap();
313 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
321 // Positive test case for a method
322 int UtcDaliTextEditorSetPropertyP(void)
324 ToolkitTestApplication application;
325 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
326 TextEditor editor = TextEditor::New();
327 DALI_TEST_CHECK( editor );
328 Stage::GetCurrent().Add( editor );
330 // Note - we can't check the defaults since the stylesheets are platform-specific
332 // Check the render backend property.
333 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
334 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
336 // Check text property.
337 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
338 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
340 // Check text's color property
341 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
342 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
344 // Check font properties.
345 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
346 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
347 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
348 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION );
349 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
350 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
353 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
354 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
355 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"slant\":\"roman\"}" );
356 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
357 editor.SetProperty( TextEditor::Property::FONT_STYLE, "" );
358 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string(""), TEST_LOCATION );
360 // Check that the Alignment properties can be correctly set
361 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
362 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
364 // Check scroll properties.
365 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
366 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
367 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
368 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
370 // Check cursor properties
371 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
372 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
373 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
374 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
376 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
377 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
378 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
379 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
380 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
381 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
382 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
383 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
385 // Check handle images
386 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
387 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
388 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
389 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
390 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
392 // Check handle images
393 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
394 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
395 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
396 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
397 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
398 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
400 // Check the highlight color
401 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
402 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
404 // Decoration bounding box
405 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
406 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
408 // Check the enable markup property.
409 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
410 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
411 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
413 // Check input color property.
414 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
415 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
417 // Check input font properties.
418 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
419 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
420 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
421 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
422 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
423 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
425 // Reset input font style.
426 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
427 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
428 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
429 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
430 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "" );
431 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
433 // Check the line spacing property
434 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
435 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
436 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
438 // Check the input line spacing property
439 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
440 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
441 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
443 // Check the underline property
444 editor.SetProperty( TextEditor::Property::UNDERLINE, "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" );
445 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), std::string("{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION );
447 // Check the input underline property
448 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
449 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
451 // Check the shadow property
452 editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" );
453 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"2 2\"}"), TEST_LOCATION );
455 // Check the input shadow property
456 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
457 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
459 // Check the emboss property
460 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
461 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
463 // Check the input emboss property
464 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
465 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
467 // Check the outline property
468 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
469 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
471 // Check the input outline property
472 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
473 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
478 // Positive Atlas Text Renderer test
479 int utcDaliTextEditorAtlasRenderP(void)
481 ToolkitTestApplication application;
482 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
483 StyleManager styleManager = StyleManager::Get();
484 styleManager.ApplyDefaultTheme();
485 TextEditor editor = TextEditor::New();
486 DALI_TEST_CHECK( editor );
488 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
490 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
492 Stage::GetCurrent().Add( editor );
496 // Render some text with the shared atlas backend
497 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
498 application.SendNotification();
499 application.Render();
503 tet_result(TET_FAIL);
508 // Positive test for the textChanged signal.
509 int utcDaliTextEditorTextChangedP(void)
511 ToolkitTestApplication application;
512 tet_infoline(" utcDaliTextEditorTextChangedP");
513 TextEditor editor = TextEditor::New();
514 DALI_TEST_CHECK( editor );
516 Stage::GetCurrent().Add( editor );
518 // connect to the text changed signal.
519 ConnectionTracker* testTracker = new ConnectionTracker();
520 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
521 bool textChangedSignal = false;
522 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
524 gTextChangedCallBackCalled = false;
525 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
526 DALI_TEST_CHECK( gTextChangedCallBackCalled );
527 DALI_TEST_CHECK( textChangedSignal );
529 application.SendNotification();
531 editor.SetKeyInputFocus();
533 gTextChangedCallBackCalled = false;
534 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
535 DALI_TEST_CHECK( gTextChangedCallBackCalled );
540 int utcDaliTextEditorInputStyleChanged01(void)
542 ToolkitTestApplication application;
543 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
545 // The text-editor emits signals when the input style changes. These changes of style are
546 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
547 // can't be emitted during the size negotiation as the callbacks may update the UI.
548 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
549 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
550 application.CreateAdaptor();
554 char* pathNamePtr = get_current_dir_name();
555 const std::string pathName( pathNamePtr );
558 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
559 fontClient.SetDpi( 93u, 93u );
561 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
562 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
564 TextEditor editor = TextEditor::New();
565 DALI_TEST_CHECK( editor );
568 editor.SetSize( 300.f, 50.f );
569 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
570 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
572 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
573 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
575 // connect to the text changed signal.
576 ConnectionTracker* testTracker = new ConnectionTracker();
577 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
578 bool inputStyleChangedSignal = false;
579 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
581 Stage::GetCurrent().Add( editor );
584 application.SendNotification();
585 application.Render();
587 // Executes the idle callbacks added by the text control on the change of input style.
588 application.RunIdles();
590 gInputStyleChangedCallbackCalled = false;
591 gInputStyleMask = TextEditor::InputStyle::NONE;
592 inputStyleChangedSignal = false;
594 // Create a tap event to touch the text editor.
595 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
596 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
599 application.SendNotification();
600 application.Render();
602 // Executes the idle callbacks added by the text control on the change of input style.
603 application.RunIdles();
605 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
606 if( gInputStyleChangedCallbackCalled )
608 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
610 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
611 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
613 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
614 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
616 DALI_TEST_CHECK( inputStyleChangedSignal );
618 gInputStyleChangedCallbackCalled = false;
619 gInputStyleMask = TextEditor::InputStyle::NONE;
620 inputStyleChangedSignal = false;
622 // Create a tap event to touch the text editor.
623 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
624 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
627 application.SendNotification();
628 application.Render();
630 // Executes the idle callbacks added by the text control on the change of input style.
631 application.RunIdles();
633 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
634 DALI_TEST_CHECK( !inputStyleChangedSignal );
636 gInputStyleChangedCallbackCalled = false;
637 gInputStyleMask = TextEditor::InputStyle::NONE;
638 inputStyleChangedSignal = false;
640 // Create a tap event to touch the text editor.
641 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
642 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
645 application.SendNotification();
646 application.Render();
648 // Executes the idle callbacks added by the text control on the change of input style.
649 application.RunIdles();
651 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
652 if( gInputStyleChangedCallbackCalled )
654 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
656 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
657 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
659 DALI_TEST_CHECK( inputStyleChangedSignal );
661 gInputStyleChangedCallbackCalled = false;
662 gInputStyleMask = TextEditor::InputStyle::NONE;
663 inputStyleChangedSignal = false;
665 // Create a tap event to touch the text editor.
666 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
667 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
670 application.SendNotification();
671 application.Render();
673 // Executes the idle callbacks added by the text control on the change of input style.
674 application.RunIdles();
676 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
677 if( gInputStyleChangedCallbackCalled )
679 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
681 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
682 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
684 const std::string style = editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ).Get<std::string>();
685 DALI_TEST_EQUALS( style, "{\"weight\":\"bold\"}", TEST_LOCATION );
687 DALI_TEST_CHECK( inputStyleChangedSignal );
689 gInputStyleChangedCallbackCalled = false;
690 gInputStyleMask = TextEditor::InputStyle::NONE;
691 inputStyleChangedSignal = false;
693 // Create a tap event to touch the text editor.
694 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
695 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
698 application.SendNotification();
699 application.Render();
701 // Executes the idle callbacks added by the text control on the change of input style.
702 application.RunIdles();
704 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
705 DALI_TEST_CHECK( !inputStyleChangedSignal );
707 gInputStyleChangedCallbackCalled = false;
708 gInputStyleMask = TextEditor::InputStyle::NONE;
709 inputStyleChangedSignal = false;
711 // Create a tap event to touch the text editor.
712 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
713 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
716 application.SendNotification();
717 application.Render();
719 // Executes the idle callbacks added by the text control on the change of input style.
720 application.RunIdles();
722 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
723 if( gInputStyleChangedCallbackCalled )
725 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
727 const std::string style = editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ).Get<std::string>();
728 DALI_TEST_CHECK( style.empty() );
730 DALI_TEST_CHECK( inputStyleChangedSignal );
732 gInputStyleChangedCallbackCalled = false;
733 gInputStyleMask = TextEditor::InputStyle::NONE;
734 inputStyleChangedSignal = false;
736 // Create a tap event to touch the text editor.
737 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
738 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
741 application.SendNotification();
742 application.Render();
744 // Executes the idle callbacks added by the text control on the change of input style.
745 application.RunIdles();
747 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
748 DALI_TEST_CHECK( !inputStyleChangedSignal );
753 int utcDaliTextEditorInputStyleChanged02(void)
755 ToolkitTestApplication application;
756 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
758 // The text-editor emits signals when the input style changes. These changes of style are
759 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
760 // can't be emitted during the size negotiation as the callbacks may update the UI.
761 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
762 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
763 application.CreateAdaptor();
767 char* pathNamePtr = get_current_dir_name();
768 const std::string pathName( pathNamePtr );
771 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
772 fontClient.SetDpi( 93u, 93u );
774 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
775 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
777 TextEditor editor = TextEditor::New();
778 DALI_TEST_CHECK( editor );
781 editor.SetSize( 300.f, 50.f );
782 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
783 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
785 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
786 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>" );
788 // connect to the text changed signal.
789 ConnectionTracker* testTracker = new ConnectionTracker();
790 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
791 bool inputStyleChangedSignal = false;
792 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
794 Stage::GetCurrent().Add( editor );
797 application.SendNotification();
798 application.Render();
800 // Executes the idle callbacks added by the text control on the change of input style.
801 application.RunIdles();
803 gInputStyleChangedCallbackCalled = false;
804 gInputStyleMask = TextEditor::InputStyle::NONE;
805 inputStyleChangedSignal = false;
807 // Create a tap event to touch the text editor.
808 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
809 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
810 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
811 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
814 application.SendNotification();
815 application.Render();
817 // Executes the idle callbacks added by the text control on the change of input style.
818 application.RunIdles();
820 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
821 if( gInputStyleChangedCallbackCalled )
823 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
824 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
825 TextEditor::InputStyle::POINT_SIZE |
826 TextEditor::InputStyle::COLOR ),
829 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
830 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
832 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
833 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
835 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
836 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
838 DALI_TEST_CHECK( inputStyleChangedSignal );
840 gInputStyleChangedCallbackCalled = false;
841 gInputStyleMask = TextEditor::InputStyle::NONE;
842 inputStyleChangedSignal = false;
844 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
847 application.SendNotification();
848 application.Render();
850 // Executes the idle callbacks added by the text control on the change of input style.
851 application.RunIdles();
853 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
854 if( gInputStyleChangedCallbackCalled )
856 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
857 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
860 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
861 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
863 DALI_TEST_CHECK( inputStyleChangedSignal );
865 gInputStyleChangedCallbackCalled = false;
866 gInputStyleMask = TextEditor::InputStyle::NONE;
867 inputStyleChangedSignal = false;
869 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
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 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
888 application.SendNotification();
889 application.Render();
891 // Executes the idle callbacks added by the text control on the change of input style.
892 application.RunIdles();
894 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
895 if( gInputStyleChangedCallbackCalled )
897 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
898 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
901 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
902 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
904 DALI_TEST_CHECK( inputStyleChangedSignal );
906 gInputStyleChangedCallbackCalled = false;
907 gInputStyleMask = TextEditor::InputStyle::NONE;
908 inputStyleChangedSignal = false;
910 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
912 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
913 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
914 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
916 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
917 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
918 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
919 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
921 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
924 application.SendNotification();
925 application.Render();
927 // Executes the idle callbacks added by the text control on the change of input style.
928 application.RunIdles();
930 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
931 DALI_TEST_CHECK( !inputStyleChangedSignal );
933 // Create a tap event to touch the text editor.
934 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
935 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
938 application.SendNotification();
939 application.Render();
941 // Executes the idle callbacks added by the text control on the change of input style.
942 application.RunIdles();
944 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
945 if( gInputStyleChangedCallbackCalled )
947 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
948 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
949 TextEditor::InputStyle::POINT_SIZE |
950 TextEditor::InputStyle::FONT_STYLE |
951 TextEditor::InputStyle::LINE_SPACING |
952 TextEditor::InputStyle::UNDERLINE |
953 TextEditor::InputStyle::SHADOW |
954 TextEditor::InputStyle::EMBOSS |
955 TextEditor::InputStyle::OUTLINE ),
958 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
959 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
961 DALI_TEST_CHECK( inputStyleChangedSignal );
963 gInputStyleChangedCallbackCalled = false;
964 gInputStyleMask = TextEditor::InputStyle::NONE;
965 inputStyleChangedSignal = false;
967 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
968 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"black\",\"width\":\"expanded\",\"slant\":\"oblique\"}" );
970 // Create a tap event to touch the text editor.
971 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
972 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
975 application.SendNotification();
976 application.Render();
978 // Executes the idle callbacks added by the text control on the change of input style.
979 application.RunIdles();
981 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
982 if( gInputStyleChangedCallbackCalled )
984 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
985 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
986 TextEditor::InputStyle::POINT_SIZE |
987 TextEditor::InputStyle::FONT_STYLE ),
990 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
991 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
993 DALI_TEST_CHECK( inputStyleChangedSignal );
998 int utcDaliTextEditorEvent01(void)
1000 ToolkitTestApplication application;
1001 tet_infoline(" utcDaliTextEditorEvent01");
1003 // Creates a tap event. After creating a tap event the text editor should
1004 // have the focus and add text with key events should be possible.
1006 TextEditor editor = TextEditor::New();
1007 DALI_TEST_CHECK( editor );
1009 Stage::GetCurrent().Add( editor );
1011 editor.SetSize( 300.f, 50.f );
1012 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1013 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1015 // Avoid a crash when core load gl resources.
1016 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1018 // Render and notify
1019 application.SendNotification();
1020 application.Render();
1022 // Add a key event but as the text editor has not the focus it should do nothing.
1023 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1025 // Render and notify
1026 application.SendNotification();
1027 application.Render();
1029 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1031 // Create a tap event to touch the text editor.
1032 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1033 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1035 // Render and notify
1036 application.SendNotification();
1037 application.Render();
1039 // Now the text editor has the focus, so it can handle the key events.
1040 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1041 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1043 // Render and notify
1044 application.SendNotification();
1045 application.Render();
1047 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1049 // Create a second text editor and send key events to it.
1050 TextEditor editor2 = TextEditor::New();
1052 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1053 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1054 editor2.SetSize( 100.f, 100.f );
1055 editor2.SetPosition( 100.f, 100.f );
1057 Stage::GetCurrent().Add( editor2 );
1059 // Render and notify
1060 application.SendNotification();
1061 application.Render();
1063 // Create a tap event on the second text editor.
1064 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1065 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1067 // Render and notify
1068 application.SendNotification();
1069 application.Render();
1071 // The second text editor has the focus. It should handle the key events.
1072 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1073 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1075 // Render and notify
1076 application.SendNotification();
1077 application.Render();
1079 // Check the text has been added to the second text editor.
1080 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1085 int utcDaliTextEditorEvent02(void)
1087 ToolkitTestApplication application;
1088 tet_infoline(" utcDaliTextEditorEvent02");
1090 // Checks if the right number of actors are created.
1092 TextEditor editor = TextEditor::New();
1093 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1094 DALI_TEST_CHECK( editor );
1096 Stage::GetCurrent().Add( editor );
1098 editor.SetSize( 300.f, 50.f );
1099 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1100 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1102 // Avoid a crash when core load gl resources.
1103 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1105 // Render and notify
1106 application.SendNotification();
1107 application.Render();
1109 // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
1110 DALI_TEST_EQUALS( editor.GetChildCount(), 2u, TEST_LOCATION );
1112 Actor offscreenRoot = editor.GetChildAt( 0u );
1113 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1114 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1116 Actor offscreenImage = editor.GetChildAt( 1u );
1117 DALI_TEST_CHECK( offscreenImage );
1119 // Create a tap event to touch the text editor.
1120 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1121 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1123 // Render and notify
1124 application.SendNotification();
1125 application.Render();
1127 Actor layer = editor.GetChildAt( 2u );
1128 DALI_TEST_CHECK( layer.IsLayer() );
1130 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1131 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1133 // Now the text editor has the focus, so it can handle the key events.
1134 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1135 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1137 // Render and notify
1138 application.SendNotification();
1139 application.Render();
1141 // Checks the cursor and the renderer have been created.
1142 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1143 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
1145 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1146 DALI_TEST_CHECK( cursor );
1148 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1149 DALI_TEST_CHECK( camera );
1151 // The offscreen root actor has a container with all the actors which contain the text renderers.
1152 Actor container = offscreenRoot.GetChildAt( 1u );
1153 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1155 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1156 DALI_TEST_CHECK( renderer );
1159 // Move the cursor and check the position changes.
1160 Vector3 position1 = cursor.GetCurrentPosition();
1162 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1163 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1165 // Render and notify
1166 application.SendNotification();
1167 application.Render();
1169 Vector3 position2 = cursor.GetCurrentPosition();
1171 DALI_TEST_CHECK( position2.x < position1.x );
1173 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1174 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1176 // Render and notify
1177 application.SendNotification();
1178 application.Render();
1180 Vector3 position3 = cursor.GetCurrentPosition();
1182 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1184 // Send some taps and check the cursor positions.
1186 // Try to tap at the beginning.
1187 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1188 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1190 // Render and notify
1191 application.SendNotification();
1192 application.Render();
1194 // Cursor position should be the same than position1.
1195 Vector3 position4 = cursor.GetCurrentPosition();
1197 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1199 // Tap away from the start position.
1200 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1201 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1203 // Render and notify
1204 application.SendNotification();
1205 application.Render();
1207 Vector3 position5 = cursor.GetCurrentPosition();
1209 DALI_TEST_CHECK( position5.x > position4.x );
1211 // Remove all the text.
1212 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1213 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1214 editor.SetProperty( TextEditor::Property::TEXT, "" );
1216 // Render and notify
1217 application.SendNotification();
1218 application.Render();
1220 // Cursor position should be the same than position2.
1221 Vector3 position6 = cursor.GetCurrentPosition();
1223 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1225 // Should not be a renderer.
1226 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
1231 int utcDaliTextEditorEvent03(void)
1233 ToolkitTestApplication application;
1234 tet_infoline(" utcDaliTextEditorEvent03");
1236 // Checks if the highlight actor is created.
1238 TextEditor editor = TextEditor::New();
1239 DALI_TEST_CHECK( editor );
1241 Stage::GetCurrent().Add( editor );
1243 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1244 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1245 editor.SetSize( 30.f, 50.f );
1246 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1247 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1249 // Avoid a crash when core load gl resources.
1250 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1252 // Render and notify
1253 application.SendNotification();
1254 application.Render();
1256 // Send some taps and check text controller with clipboard window
1257 Dali::Clipboard clipboard = Clipboard::Get();
1258 clipboard.ShowClipboard();
1259 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1260 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1261 clipboard.HideClipboard();
1263 // Render and notify
1264 application.SendNotification();
1265 application.Render();
1267 // Tap first to get the focus.
1268 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1269 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1271 // Render and notify
1272 application.SendNotification();
1273 application.Render();
1275 // Double tap to select a word.
1276 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1277 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1279 // Render and notify
1280 application.SendNotification();
1281 application.Render();
1283 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
1284 Actor offscreenRoot = editor.GetChildAt( 0u );
1285 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1287 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1288 DALI_TEST_CHECK( camera );
1290 // The offscreen root actor has a container with all the actors which contain the text renderers.
1291 Actor container = offscreenRoot.GetChildAt( 1u );
1292 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1294 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1295 DALI_TEST_CHECK( renderer );
1298 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
1299 DALI_TEST_CHECK( highlight );