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/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/tap-gesture-event.h>
25 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
29 using namespace Toolkit;
31 void dali_texteditor_startup(void)
33 test_return_value = TET_UNDEF;
36 void dali_texteditor_cleanup(void)
38 test_return_value = TET_PASS;
44 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
45 const char* const PROPERTY_NAME_TEXT = "text";
46 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
47 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
48 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
49 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
50 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
51 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
52 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
53 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
54 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
55 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
56 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
57 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
58 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
59 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
60 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
61 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
62 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
67 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
68 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
69 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
70 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
71 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
72 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
73 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
75 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
76 const char* const PROPERTY_NAME_INPUT_LINE_SPACING = "inputLineSpacing";
77 const char* const PROPERTY_NAME_UNDERLINE = "underline";
78 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
79 const char* const PROPERTY_NAME_SHADOW = "shadow";
80 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
81 const char* const PROPERTY_NAME_EMBOSS = "emboss";
82 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
83 const char* const PROPERTY_NAME_OUTLINE = "outline";
84 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
86 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
88 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
90 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
91 const float TO_MILLISECONDS = 1000.f;
92 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
94 const float SCROLL_THRESHOLD = 10.f;
95 const float SCROLL_SPEED = 300.f;
97 const unsigned int DEFAULT_FONT_SIZE = 1152u;
98 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
100 static bool gTextChangedCallBackCalled;
101 static bool gInputStyleChangedCallbackCalled;
102 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
104 struct CallbackFunctor
106 CallbackFunctor(bool* callbackFlag)
107 : mCallbackFlag( callbackFlag )
113 *mCallbackFlag = true;
118 static void TestTextChangedCallback( TextEditor control )
120 tet_infoline(" TestTextChangedCallback");
122 gTextChangedCallBackCalled = true;
125 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
127 tet_infoline(" TestInputStyleChangedCallback");
129 gInputStyleChangedCallbackCalled = true;
130 gInputStyleMask = mask;
133 // Generate a TapGestureEvent to send to Core.
134 Integration::TapGestureEvent GenerateTap(
135 Gesture::State state,
136 unsigned int numberOfTaps,
137 unsigned int numberOfTouches,
140 Integration::TapGestureEvent tap( state );
142 tap.numberOfTaps = numberOfTaps;
143 tap.numberOfTouches = numberOfTouches;
149 // Generate a KeyEvent to send to Core.
150 Integration::KeyEvent GenerateKey( const std::string& keyName,
151 const std::string& keyString,
154 unsigned long timeStamp,
155 const Integration::KeyEvent::State& keyState )
157 return Integration::KeyEvent( keyName,
167 int UtcDaliToolkitTextEditorConstructorP(void)
169 ToolkitTestApplication application;
170 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
171 TextEditor textEditor;
172 DALI_TEST_CHECK( !textEditor );
176 int UtcDaliToolkitTextEditorNewP(void)
178 ToolkitTestApplication application;
179 tet_infoline(" UtcDaliToolkitTextEditorNewP");
180 TextEditor textEditor = TextEditor::New();
181 DALI_TEST_CHECK( textEditor );
185 int UtcDaliToolkitTextEditorDownCastP(void)
187 ToolkitTestApplication application;
188 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
189 TextEditor textEditor1 = TextEditor::New();
190 BaseHandle object( textEditor1 );
192 TextEditor textEditor2 = TextEditor::DownCast( object );
193 DALI_TEST_CHECK( textEditor2 );
195 TextEditor textEditor3 = DownCast< TextEditor >( object );
196 DALI_TEST_CHECK( textEditor3 );
200 int UtcDaliToolkitTextEditorDownCastN(void)
202 ToolkitTestApplication application;
203 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
204 BaseHandle uninitializedObject;
205 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
206 DALI_TEST_CHECK( !textEditor1 );
208 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
209 DALI_TEST_CHECK( !textEditor2 );
213 int UtcDaliToolkitTextEditorCopyConstructorP(void)
215 ToolkitTestApplication application;
216 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
217 TextEditor textEditor = TextEditor::New();
218 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
220 TextEditor copy( textEditor );
221 DALI_TEST_CHECK( copy );
222 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
226 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
228 ToolkitTestApplication application;
229 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
230 TextEditor textEditor = TextEditor::New();
231 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
233 TextEditor copy = textEditor;
234 DALI_TEST_CHECK( copy );
235 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
239 int UtcDaliTextEditorNewP(void)
241 ToolkitTestApplication application;
242 tet_infoline(" UtcDaliToolkitTextEditorNewP");
243 TextEditor textEditor = TextEditor::New();
244 DALI_TEST_CHECK( textEditor );
248 // Positive test case for a method
249 int UtcDaliTextEditorGetPropertyP(void)
251 ToolkitTestApplication application;
252 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
253 TextEditor editor = TextEditor::New();
254 DALI_TEST_CHECK( editor );
256 // Check Property Indices are correct
257 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
258 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
259 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
260 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
261 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
262 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
263 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
264 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
265 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
266 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
267 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
268 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
269 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
270 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
271 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
272 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
273 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
274 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
275 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
276 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
277 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
278 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
279 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
280 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
281 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
282 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
283 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
284 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
285 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
286 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
288 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
289 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
290 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
291 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
292 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
293 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
294 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
295 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
296 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
297 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
302 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
305 Property::Map imageMap;
306 imageMap[mapKey] =mapValue;
308 editor.SetProperty( property , imageMap );
309 Property::Value propValue = editor.GetProperty( property );
310 Property::Map* resultMap = propValue.GetMap();
312 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
320 // Positive test case for a method
321 int UtcDaliTextEditorSetPropertyP(void)
323 ToolkitTestApplication application;
324 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
325 TextEditor editor = TextEditor::New();
326 DALI_TEST_CHECK( editor );
327 Stage::GetCurrent().Add( editor );
329 // Note - we can't check the defaults since the stylesheets are platform-specific
331 // Check the render backend property.
332 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
333 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
335 // Check text property.
336 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
337 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
339 // Check text's color property
340 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
341 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
343 // Check font properties.
344 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
345 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
346 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
347 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION );
348 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
349 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
352 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
353 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
354 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"slant\":\"roman\"}" );
355 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
356 editor.SetProperty( TextEditor::Property::FONT_STYLE, "" );
357 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string(""), TEST_LOCATION );
359 // Check that the Alignment properties can be correctly set
360 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
361 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
363 // Check scroll properties.
364 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
365 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
366 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
367 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
369 // Check cursor properties
370 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
371 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
372 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
373 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
375 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
376 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
377 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
378 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
379 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
380 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
381 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
382 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
384 // Check handle images
385 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
386 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
387 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
388 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
389 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
391 // Check handle images
392 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
393 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
394 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
395 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
396 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
397 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
399 // Check the highlight color
400 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
401 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
403 // Decoration bounding box
404 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
405 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
407 // Check the enable markup property.
408 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
409 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
410 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
412 // Check input color property.
413 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
414 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
416 // Check input font properties.
417 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
418 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
419 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
420 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
421 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
422 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
424 // Reset input font style.
425 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
426 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
427 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
428 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
429 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "" );
430 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
432 // Check the line spacing property
433 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
434 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
435 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
437 // Check the input line spacing property
438 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
439 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
440 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
442 // Check the underline property
443 editor.SetProperty( TextEditor::Property::UNDERLINE, "Underline properties" );
444 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION );
446 // Check the input underline property
447 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
448 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
450 // Check the shadow property
451 editor.SetProperty( TextEditor::Property::SHADOW, "Shadow properties" );
452 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
454 // Check the input shadow property
455 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
456 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
458 // Check the emboss property
459 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
460 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
462 // Check the input emboss property
463 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
464 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
466 // Check the outline property
467 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
468 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
470 // Check the input outline property
471 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
472 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
477 // Positive Atlas Text Renderer test
478 int utcDaliTextEditorAtlasRenderP(void)
480 ToolkitTestApplication application;
481 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
482 StyleManager styleManager = StyleManager::Get();
483 styleManager.ApplyDefaultTheme();
484 TextEditor editor = TextEditor::New();
485 DALI_TEST_CHECK( editor );
487 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
489 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
491 Stage::GetCurrent().Add( editor );
495 // Render some text with the shared atlas backend
496 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
497 application.SendNotification();
498 application.Render();
502 tet_result(TET_FAIL);
507 // Positive test for the textChanged signal.
508 int utcDaliTextEditorTextChangedP(void)
510 ToolkitTestApplication application;
511 tet_infoline(" utcDaliTextEditorTextChangedP");
512 TextEditor editor = TextEditor::New();
513 DALI_TEST_CHECK( editor );
515 Stage::GetCurrent().Add( editor );
517 // connect to the text changed signal.
518 ConnectionTracker* testTracker = new ConnectionTracker();
519 editor.TextChangedSignal().Connect( &TestTextChangedCallback );
520 bool textChangedSignal = false;
521 editor.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
523 gTextChangedCallBackCalled = false;
524 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
525 DALI_TEST_CHECK( gTextChangedCallBackCalled );
526 DALI_TEST_CHECK( textChangedSignal );
528 application.SendNotification();
530 editor.SetKeyInputFocus();
532 gTextChangedCallBackCalled = false;
533 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
534 DALI_TEST_CHECK( gTextChangedCallBackCalled );
539 int utcDaliTextEditorInputStyleChanged01(void)
541 ToolkitTestApplication application;
542 tet_infoline(" utcDaliTextEditorInputStyleChanged01");
544 // The text-editor emits signals when the input style changes. These changes of style are
545 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
546 // can't be emitted during the size negotiation as the callbacks may update the UI.
547 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
548 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
549 application.CreateAdaptor();
553 char* pathNamePtr = get_current_dir_name();
554 const std::string pathName( pathNamePtr );
557 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
558 fontClient.SetDpi( 93u, 93u );
560 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
561 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
563 TextEditor editor = TextEditor::New();
564 DALI_TEST_CHECK( editor );
567 editor.SetSize( 300.f, 50.f );
568 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
569 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
571 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
572 editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
574 // connect to the text changed signal.
575 ConnectionTracker* testTracker = new ConnectionTracker();
576 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
577 bool inputStyleChangedSignal = false;
578 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
580 Stage::GetCurrent().Add( editor );
583 application.SendNotification();
584 application.Render();
586 // Executes the idle callbacks added by the text control on the change of input style.
587 application.RunIdles();
589 gInputStyleChangedCallbackCalled = false;
590 gInputStyleMask = TextEditor::InputStyle::NONE;
591 inputStyleChangedSignal = false;
593 // Create a tap event to touch the text editor.
594 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
595 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
598 application.SendNotification();
599 application.Render();
601 // Executes the idle callbacks added by the text control on the change of input style.
602 application.RunIdles();
604 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
605 if( gInputStyleChangedCallbackCalled )
607 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
609 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
610 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
612 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
613 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
615 DALI_TEST_CHECK( inputStyleChangedSignal );
617 gInputStyleChangedCallbackCalled = false;
618 gInputStyleMask = TextEditor::InputStyle::NONE;
619 inputStyleChangedSignal = false;
621 // Create a tap event to touch the text editor.
622 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
623 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
626 application.SendNotification();
627 application.Render();
629 // Executes the idle callbacks added by the text control on the change of input style.
630 application.RunIdles();
632 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
633 DALI_TEST_CHECK( !inputStyleChangedSignal );
635 gInputStyleChangedCallbackCalled = false;
636 gInputStyleMask = TextEditor::InputStyle::NONE;
637 inputStyleChangedSignal = false;
639 // Create a tap event to touch the text editor.
640 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
641 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
644 application.SendNotification();
645 application.Render();
647 // Executes the idle callbacks added by the text control on the change of input style.
648 application.RunIdles();
650 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
651 if( gInputStyleChangedCallbackCalled )
653 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
655 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
656 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
658 DALI_TEST_CHECK( inputStyleChangedSignal );
660 gInputStyleChangedCallbackCalled = false;
661 gInputStyleMask = TextEditor::InputStyle::NONE;
662 inputStyleChangedSignal = false;
664 // Create a tap event to touch the text editor.
665 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
666 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
669 application.SendNotification();
670 application.Render();
672 // Executes the idle callbacks added by the text control on the change of input style.
673 application.RunIdles();
675 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
676 if( gInputStyleChangedCallbackCalled )
678 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
680 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
681 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
683 const std::string style = editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ).Get<std::string>();
684 DALI_TEST_EQUALS( style, "{\"weight\":\"bold\"}", TEST_LOCATION );
686 DALI_TEST_CHECK( inputStyleChangedSignal );
688 gInputStyleChangedCallbackCalled = false;
689 gInputStyleMask = TextEditor::InputStyle::NONE;
690 inputStyleChangedSignal = false;
692 // Create a tap event to touch the text editor.
693 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
694 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
697 application.SendNotification();
698 application.Render();
700 // Executes the idle callbacks added by the text control on the change of input style.
701 application.RunIdles();
703 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
704 DALI_TEST_CHECK( !inputStyleChangedSignal );
706 gInputStyleChangedCallbackCalled = false;
707 gInputStyleMask = TextEditor::InputStyle::NONE;
708 inputStyleChangedSignal = false;
710 // Create a tap event to touch the text editor.
711 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
712 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
715 application.SendNotification();
716 application.Render();
718 // Executes the idle callbacks added by the text control on the change of input style.
719 application.RunIdles();
721 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
722 if( gInputStyleChangedCallbackCalled )
724 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
726 const std::string style = editor.GetProperty( TextEditor::Property::INPUT_FONT_STYLE ).Get<std::string>();
727 DALI_TEST_CHECK( style.empty() );
729 DALI_TEST_CHECK( inputStyleChangedSignal );
731 gInputStyleChangedCallbackCalled = false;
732 gInputStyleMask = TextEditor::InputStyle::NONE;
733 inputStyleChangedSignal = false;
735 // Create a tap event to touch the text editor.
736 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
737 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
740 application.SendNotification();
741 application.Render();
743 // Executes the idle callbacks added by the text control on the change of input style.
744 application.RunIdles();
746 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
747 DALI_TEST_CHECK( !inputStyleChangedSignal );
752 int utcDaliTextEditorInputStyleChanged02(void)
754 ToolkitTestApplication application;
755 tet_infoline(" utcDaliTextEditorInputStyleChanged02");
757 // The text-editor emits signals when the input style changes. These changes of style are
758 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
759 // can't be emitted during the size negotiation as the callbacks may update the UI.
760 // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
761 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
762 application.CreateAdaptor();
766 char* pathNamePtr = get_current_dir_name();
767 const std::string pathName( pathNamePtr );
770 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
771 fontClient.SetDpi( 93u, 93u );
773 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
774 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
776 TextEditor editor = TextEditor::New();
777 DALI_TEST_CHECK( editor );
780 editor.SetSize( 300.f, 50.f );
781 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
782 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
784 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
785 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>" );
787 // connect to the text changed signal.
788 ConnectionTracker* testTracker = new ConnectionTracker();
789 editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
790 bool inputStyleChangedSignal = false;
791 editor.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
793 Stage::GetCurrent().Add( editor );
796 application.SendNotification();
797 application.Render();
799 // Executes the idle callbacks added by the text control on the change of input style.
800 application.RunIdles();
802 gInputStyleChangedCallbackCalled = false;
803 gInputStyleMask = TextEditor::InputStyle::NONE;
804 inputStyleChangedSignal = false;
806 // Create a tap event to touch the text editor.
807 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
808 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
809 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
810 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
813 application.SendNotification();
814 application.Render();
816 // Executes the idle callbacks added by the text control on the change of input style.
817 application.RunIdles();
819 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
820 if( gInputStyleChangedCallbackCalled )
822 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
823 static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
824 TextEditor::InputStyle::POINT_SIZE |
825 TextEditor::InputStyle::COLOR ),
828 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
829 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
831 const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
832 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
834 const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
835 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
837 DALI_TEST_CHECK( inputStyleChangedSignal );
839 gInputStyleChangedCallbackCalled = false;
840 gInputStyleMask = TextEditor::InputStyle::NONE;
841 inputStyleChangedSignal = false;
843 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
846 application.SendNotification();
847 application.Render();
849 // Executes the idle callbacks added by the text control on the change of input style.
850 application.RunIdles();
852 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
853 if( gInputStyleChangedCallbackCalled )
855 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
856 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
859 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
860 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
862 DALI_TEST_CHECK( inputStyleChangedSignal );
864 gInputStyleChangedCallbackCalled = false;
865 gInputStyleMask = TextEditor::InputStyle::NONE;
866 inputStyleChangedSignal = false;
868 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
871 application.SendNotification();
872 application.Render();
874 // Executes the idle callbacks added by the text control on the change of input style.
875 application.RunIdles();
877 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
878 DALI_TEST_CHECK( !inputStyleChangedSignal );
880 gInputStyleChangedCallbackCalled = false;
881 gInputStyleMask = TextEditor::InputStyle::NONE;
882 inputStyleChangedSignal = false;
884 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
887 application.SendNotification();
888 application.Render();
890 // Executes the idle callbacks added by the text control on the change of input style.
891 application.RunIdles();
893 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
894 if( gInputStyleChangedCallbackCalled )
896 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
897 static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
900 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
901 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
903 DALI_TEST_CHECK( inputStyleChangedSignal );
905 gInputStyleChangedCallbackCalled = false;
906 gInputStyleMask = TextEditor::InputStyle::NONE;
907 inputStyleChangedSignal = false;
909 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
911 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
912 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
913 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
915 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
916 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
917 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
918 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
920 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
923 application.SendNotification();
924 application.Render();
926 // Executes the idle callbacks added by the text control on the change of input style.
927 application.RunIdles();
929 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
930 DALI_TEST_CHECK( !inputStyleChangedSignal );
932 // Create a tap event to touch the text editor.
933 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
934 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
937 application.SendNotification();
938 application.Render();
940 // Executes the idle callbacks added by the text control on the change of input style.
941 application.RunIdles();
943 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
944 if( gInputStyleChangedCallbackCalled )
946 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
947 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
948 TextEditor::InputStyle::POINT_SIZE |
949 TextEditor::InputStyle::FONT_STYLE |
950 TextEditor::InputStyle::LINE_SPACING |
951 TextEditor::InputStyle::UNDERLINE |
952 TextEditor::InputStyle::SHADOW |
953 TextEditor::InputStyle::EMBOSS |
954 TextEditor::InputStyle::OUTLINE ),
957 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
958 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
960 DALI_TEST_CHECK( inputStyleChangedSignal );
962 gInputStyleChangedCallbackCalled = false;
963 gInputStyleMask = TextEditor::InputStyle::NONE;
964 inputStyleChangedSignal = false;
966 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
967 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"black\",\"width\":\"expanded\",\"slant\":\"oblique\"}" );
969 // Create a tap event to touch the text editor.
970 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
971 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
974 application.SendNotification();
975 application.Render();
977 // Executes the idle callbacks added by the text control on the change of input style.
978 application.RunIdles();
980 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
981 if( gInputStyleChangedCallbackCalled )
983 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
984 static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
985 TextEditor::InputStyle::POINT_SIZE |
986 TextEditor::InputStyle::FONT_STYLE ),
989 const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
990 DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
992 DALI_TEST_CHECK( inputStyleChangedSignal );
997 int utcDaliTextEditorEvent01(void)
999 ToolkitTestApplication application;
1000 tet_infoline(" utcDaliTextEditorEvent01");
1002 // Creates a tap event. After creating a tap event the text editor should
1003 // have the focus and add text with key events should be possible.
1005 TextEditor editor = TextEditor::New();
1006 DALI_TEST_CHECK( editor );
1008 Stage::GetCurrent().Add( editor );
1010 editor.SetSize( 300.f, 50.f );
1011 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1012 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1014 // Avoid a crash when core load gl resources.
1015 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1017 // Render and notify
1018 application.SendNotification();
1019 application.Render();
1021 // Add a key event but as the text editor has not the focus it should do nothing.
1022 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1024 // Render and notify
1025 application.SendNotification();
1026 application.Render();
1028 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1030 // Create a tap event to touch the text editor.
1031 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1032 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1034 // Render and notify
1035 application.SendNotification();
1036 application.Render();
1038 // Now the text editor has the focus, so it can handle the key events.
1039 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1040 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1042 // Render and notify
1043 application.SendNotification();
1044 application.Render();
1046 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1048 // Create a second text editor and send key events to it.
1049 TextEditor editor2 = TextEditor::New();
1051 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1052 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1053 editor2.SetSize( 100.f, 100.f );
1054 editor2.SetPosition( 100.f, 100.f );
1056 Stage::GetCurrent().Add( editor2 );
1058 // Render and notify
1059 application.SendNotification();
1060 application.Render();
1062 // Create a tap event on the second text editor.
1063 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1064 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1066 // Render and notify
1067 application.SendNotification();
1068 application.Render();
1070 // The second text editor has the focus. It should handle the key events.
1071 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1072 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1074 // Render and notify
1075 application.SendNotification();
1076 application.Render();
1078 // Check the text has been added to the second text editor.
1079 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1084 int utcDaliTextEditorEvent02(void)
1086 ToolkitTestApplication application;
1087 tet_infoline(" utcDaliTextEditorEvent02");
1089 // Checks if the right number of actors are created.
1091 TextEditor editor = TextEditor::New();
1092 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1093 DALI_TEST_CHECK( editor );
1095 Stage::GetCurrent().Add( editor );
1097 editor.SetSize( 300.f, 50.f );
1098 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1099 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1101 // Avoid a crash when core load gl resources.
1102 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1104 // Render and notify
1105 application.SendNotification();
1106 application.Render();
1108 // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
1109 DALI_TEST_EQUALS( editor.GetChildCount(), 2u, TEST_LOCATION );
1111 Actor offscreenRoot = editor.GetChildAt( 0u );
1112 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1113 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1115 Actor offscreenImage = editor.GetChildAt( 1u );
1116 DALI_TEST_CHECK( offscreenImage );
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( 2u );
1127 DALI_TEST_CHECK( layer.IsLayer() );
1129 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1130 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1132 // Now the text editor has the focus, so it can handle the key events.
1133 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1134 application.ProcessEvent( GenerateKey( "a", "a", 0, 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( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
1144 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1145 DALI_TEST_CHECK( cursor );
1147 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1148 DALI_TEST_CHECK( camera );
1150 // The offscreen root actor has a container with all the actors which contain the text renderers.
1151 Actor container = offscreenRoot.GetChildAt( 1u );
1152 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1154 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1155 DALI_TEST_CHECK( renderer );
1158 // Move the cursor and check the position changes.
1159 Vector3 position1 = cursor.GetCurrentPosition();
1161 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1162 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1164 // Render and notify
1165 application.SendNotification();
1166 application.Render();
1168 Vector3 position2 = cursor.GetCurrentPosition();
1170 DALI_TEST_CHECK( position2.x < position1.x );
1172 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1173 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1175 // Render and notify
1176 application.SendNotification();
1177 application.Render();
1179 Vector3 position3 = cursor.GetCurrentPosition();
1181 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1183 // Send some taps and check the cursor positions.
1185 // Try to tap at the beginning.
1186 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1187 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1189 // Render and notify
1190 application.SendNotification();
1191 application.Render();
1193 // Cursor position should be the same than position1.
1194 Vector3 position4 = cursor.GetCurrentPosition();
1196 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1198 // Tap away from the start position.
1199 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1200 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1202 // Render and notify
1203 application.SendNotification();
1204 application.Render();
1206 Vector3 position5 = cursor.GetCurrentPosition();
1208 DALI_TEST_CHECK( position5.x > position4.x );
1210 // Remove all the text.
1211 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1212 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1213 editor.SetProperty( TextEditor::Property::TEXT, "" );
1215 // Render and notify
1216 application.SendNotification();
1217 application.Render();
1219 // Cursor position should be the same than position2.
1220 Vector3 position6 = cursor.GetCurrentPosition();
1222 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1224 // Should not be a renderer.
1225 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
1230 int utcDaliTextEditorEvent03(void)
1232 ToolkitTestApplication application;
1233 tet_infoline(" utcDaliTextEditorEvent03");
1235 // Checks if the highlight actor is created.
1237 TextEditor editor = TextEditor::New();
1238 DALI_TEST_CHECK( editor );
1240 Stage::GetCurrent().Add( editor );
1242 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1243 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1244 editor.SetSize( 30.f, 50.f );
1245 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1246 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1248 // Avoid a crash when core load gl resources.
1249 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1251 // Render and notify
1252 application.SendNotification();
1253 application.Render();
1255 // Tap first to get the focus.
1256 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1257 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1259 // Render and notify
1260 application.SendNotification();
1261 application.Render();
1263 // Double tap to select a word.
1264 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1265 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1267 // Render and notify
1268 application.SendNotification();
1269 application.Render();
1271 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
1272 Actor offscreenRoot = editor.GetChildAt( 0u );
1273 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1275 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1276 DALI_TEST_CHECK( camera );
1278 // The offscreen root actor has a container with all the actors which contain the text renderers.
1279 Actor container = offscreenRoot.GetChildAt( 1u );
1280 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1282 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1283 DALI_TEST_CHECK( renderer );
1286 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
1287 DALI_TEST_CHECK( highlight );