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.
20 #include <dali/public-api/rendering/renderer.h>
21 #include <dali/integration-api/events/key-event-integ.h>
22 #include <dali/integration-api/events/tap-gesture-event.h>
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
27 using namespace Toolkit;
29 void dali_texteditor_startup(void)
31 test_return_value = TET_UNDEF;
34 void dali_texteditor_cleanup(void)
36 test_return_value = TET_PASS;
42 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
43 const char* const PROPERTY_NAME_TEXT = "text";
44 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
45 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
46 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
47 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
48 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
49 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
50 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
51 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
52 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
53 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
54 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
55 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
56 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
57 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
58 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
59 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
60 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
61 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
62 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
65 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
66 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
67 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
68 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
69 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
70 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
71 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
73 const char* const PROPERTY_NAME_LINE_SPACING = "lineSpacing";
74 const char* const PROPERTY_NAME_INPUT_LINE_SPACING = "inputLineSpacing";
75 const char* const PROPERTY_NAME_UNDERLINE = "underline";
76 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
77 const char* const PROPERTY_NAME_SHADOW = "shadow";
78 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
79 const char* const PROPERTY_NAME_EMBOSS = "emboss";
80 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
81 const char* const PROPERTY_NAME_OUTLINE = "outline";
82 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
84 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
86 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
88 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
89 const float TO_MILLISECONDS = 1000.f;
90 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
92 const float SCROLL_THRESHOLD = 10.f;
93 const float SCROLL_SPEED = 300.f;
95 static bool gTextChangedCallBackCalled;
97 static void TestTextChangedCallback( TextEditor control )
99 tet_infoline(" TestTextChangedCallback");
101 gTextChangedCallBackCalled = true;
104 // Generate a TapGestureEvent to send to Core.
105 Integration::TapGestureEvent GenerateTap(
106 Gesture::State state,
107 unsigned int numberOfTaps,
108 unsigned int numberOfTouches,
111 Integration::TapGestureEvent tap( state );
113 tap.numberOfTaps = numberOfTaps;
114 tap.numberOfTouches = numberOfTouches;
120 // Generate a KeyEvent to send to Core.
121 Integration::KeyEvent GenerateKey( const std::string& keyName,
122 const std::string& keyString,
125 unsigned long timeStamp,
126 const Integration::KeyEvent::State& keyState )
128 return Integration::KeyEvent( keyName,
138 int UtcDaliToolkitTextEditorConstructorP(void)
140 ToolkitTestApplication application;
141 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
142 TextEditor textEditor;
143 DALI_TEST_CHECK( !textEditor );
147 int UtcDaliToolkitTextEditorNewP(void)
149 ToolkitTestApplication application;
150 tet_infoline(" UtcDaliToolkitTextEditorNewP");
151 TextEditor textEditor = TextEditor::New();
152 DALI_TEST_CHECK( textEditor );
156 int UtcDaliToolkitTextEditorDownCastP(void)
158 ToolkitTestApplication application;
159 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
160 TextEditor textEditor1 = TextEditor::New();
161 BaseHandle object( textEditor1 );
163 TextEditor textEditor2 = TextEditor::DownCast( object );
164 DALI_TEST_CHECK( textEditor2 );
166 TextEditor textEditor3 = DownCast< TextEditor >( object );
167 DALI_TEST_CHECK( textEditor3 );
171 int UtcDaliToolkitTextEditorDownCastN(void)
173 ToolkitTestApplication application;
174 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
175 BaseHandle uninitializedObject;
176 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
177 DALI_TEST_CHECK( !textEditor1 );
179 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
180 DALI_TEST_CHECK( !textEditor2 );
184 int UtcDaliToolkitTextEditorCopyConstructorP(void)
186 ToolkitTestApplication application;
187 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
188 TextEditor textEditor = TextEditor::New();
189 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
191 TextEditor copy( textEditor );
192 DALI_TEST_CHECK( copy );
193 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
197 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
199 ToolkitTestApplication application;
200 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
201 TextEditor textEditor = TextEditor::New();
202 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
204 TextEditor copy = textEditor;
205 DALI_TEST_CHECK( copy );
206 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
210 int UtcDaliTextEditorNewP(void)
212 ToolkitTestApplication application;
213 tet_infoline(" UtcDaliToolkitTextEditorNewP");
214 TextEditor textEditor = TextEditor::New();
215 DALI_TEST_CHECK( textEditor );
219 // Positive test case for a method
220 int UtcDaliTextEditorGetPropertyP(void)
222 ToolkitTestApplication application;
223 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
224 TextEditor editor = TextEditor::New();
225 DALI_TEST_CHECK( editor );
227 // Check Property Indices are correct
228 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
229 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
230 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
231 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
232 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
233 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
234 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
235 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
236 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
237 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
238 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
239 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
240 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
241 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
242 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
243 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
244 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
245 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
246 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
247 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
248 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
249 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
250 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
251 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
252 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
253 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
254 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
255 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
256 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
257 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
259 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
260 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
261 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
262 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
263 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
264 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
265 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
266 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
267 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
268 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
273 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
276 Property::Map imageMap;
277 imageMap[mapKey] =mapValue;
279 editor.SetProperty( property , imageMap );
280 Property::Value propValue = editor.GetProperty( property );
281 Property::Map* resultMap = propValue.GetMap();
283 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
291 // Positive test case for a method
292 int UtcDaliTextEditorSetPropertyP(void)
294 ToolkitTestApplication application;
295 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
296 TextEditor editor = TextEditor::New();
297 DALI_TEST_CHECK( editor );
298 Stage::GetCurrent().Add( editor );
300 // Note - we can't check the defaults since the stylesheets are platform-specific
302 // Check the render backend property.
303 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
304 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
306 // Check text property.
307 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
308 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
310 // Check text's color property
311 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
312 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
314 // Check font properties.
315 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
316 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
317 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
318 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION );
319 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
320 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
323 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
324 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
325 editor.SetProperty( TextEditor::Property::FONT_STYLE, "{\"slant\":\"roman\"}" );
326 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
327 editor.SetProperty( TextEditor::Property::FONT_STYLE, "" );
328 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string(""), TEST_LOCATION );
330 // Check that the Alignment properties can be correctly set
331 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
332 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
334 // Check scroll properties.
335 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
336 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
337 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
338 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
340 // Check cursor properties
341 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
342 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
343 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
344 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
346 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
347 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
348 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
349 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
350 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
351 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
352 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
353 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
355 // Check handle images
356 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
357 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
358 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
359 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
360 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
362 // Check handle images
363 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
364 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
365 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
366 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
367 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
368 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
370 // Check the highlight color
371 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
372 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
374 // Decoration bounding box
375 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
376 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
378 // Check the enable markup property.
379 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
380 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
381 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
383 // Check input color property.
384 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
385 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
387 // Check input font properties.
388 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
389 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
390 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
391 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
392 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
393 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
395 // Reset input font style.
396 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
397 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
398 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
399 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
400 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "" );
401 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
403 // Check the line spacing property
404 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
405 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
406 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
408 // Check the input line spacing property
409 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
410 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
411 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
413 // Check the underline property
414 editor.SetProperty( TextEditor::Property::UNDERLINE, "Underline properties" );
415 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION );
417 // Check the input underline property
418 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
419 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
421 // Check the shadow property
422 editor.SetProperty( TextEditor::Property::SHADOW, "Shadow properties" );
423 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
425 // Check the input shadow property
426 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
427 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
429 // Check the emboss property
430 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
431 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
433 // Check the input emboss property
434 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
435 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
437 // Check the outline property
438 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
439 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
441 // Check the input outline property
442 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
443 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
448 // Positive Atlas Text Renderer test
449 int utcDaliTextEditorAtlasRenderP(void)
451 ToolkitTestApplication application;
452 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
453 StyleManager styleManager = StyleManager::Get();
454 styleManager.ApplyDefaultTheme();
455 TextEditor editor = TextEditor::New();
456 DALI_TEST_CHECK( editor );
458 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
460 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
462 Stage::GetCurrent().Add( editor );
466 // Render some text with the shared atlas backend
467 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
468 application.SendNotification();
469 application.Render();
473 tet_result(TET_FAIL);
478 // Positive test for the textChanged signal.
479 int utcDaliTextEditorTextChangedP(void)
481 ToolkitTestApplication application;
482 tet_infoline(" utcDaliTextEditorTextChangedP");
483 TextEditor editor = TextEditor::New();
484 DALI_TEST_CHECK( editor );
486 Stage::GetCurrent().Add( editor );
488 editor.TextChangedSignal().Connect(&TestTextChangedCallback);
490 gTextChangedCallBackCalled = false;
491 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
492 DALI_TEST_CHECK( gTextChangedCallBackCalled );
494 application.SendNotification();
496 editor.SetKeyInputFocus();
498 gTextChangedCallBackCalled = false;
499 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
500 DALI_TEST_CHECK( gTextChangedCallBackCalled );
505 int utcDaliTextEditorEvent01(void)
507 ToolkitTestApplication application;
508 tet_infoline(" utcDaliTextEditorEvent01");
510 // Creates a tap event. After creating a tap event the text editor should
511 // have the focus and add text with key events should be possible.
513 TextEditor editor = TextEditor::New();
514 DALI_TEST_CHECK( editor );
516 Stage::GetCurrent().Add( editor );
518 editor.SetSize( 300.f, 50.f );
519 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
520 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
522 // Avoid a crash when core load gl resources.
523 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
526 application.SendNotification();
527 application.Render();
529 // Add a key event but as the text editor has not the focus it should do nothing.
530 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
533 application.SendNotification();
534 application.Render();
536 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
538 // Create a tap event to touch the text editor.
539 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
540 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
543 application.SendNotification();
544 application.Render();
546 // Now the text editor has the focus, so it can handle the key events.
547 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
548 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
551 application.SendNotification();
552 application.Render();
554 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
556 // Create a second text editor and send key events to it.
557 TextEditor editor2 = TextEditor::New();
559 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
560 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
561 editor2.SetSize( 100.f, 100.f );
562 editor2.SetPosition( 100.f, 100.f );
564 Stage::GetCurrent().Add( editor2 );
567 application.SendNotification();
568 application.Render();
570 // Create a tap event on the second text editor.
571 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
572 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
575 application.SendNotification();
576 application.Render();
578 // The second text editor has the focus. It should handle the key events.
579 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
580 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
583 application.SendNotification();
584 application.Render();
586 // Check the text has been added to the second text editor.
587 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
592 int utcDaliTextEditorEvent02(void)
594 ToolkitTestApplication application;
595 tet_infoline(" utcDaliTextEditorEvent02");
597 // Checks if the right number of actors are created.
599 TextEditor editor = TextEditor::New();
600 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
601 DALI_TEST_CHECK( editor );
603 Stage::GetCurrent().Add( editor );
605 editor.SetSize( 300.f, 50.f );
606 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
607 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
609 // Avoid a crash when core load gl resources.
610 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
613 application.SendNotification();
614 application.Render();
616 // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
617 DALI_TEST_EQUALS( editor.GetChildCount(), 2u, TEST_LOCATION );
619 Actor offscreenRoot = editor.GetChildAt( 0u );
620 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
621 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
623 Actor offscreenImage = editor.GetChildAt( 1u );
624 DALI_TEST_CHECK( offscreenImage );
626 // Create a tap event to touch the text editor.
627 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
628 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
631 application.SendNotification();
632 application.Render();
634 Actor layer = editor.GetChildAt( 2u );
635 DALI_TEST_CHECK( layer.IsLayer() );
637 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
638 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
640 // Now the text editor has the focus, so it can handle the key events.
641 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
642 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
645 application.SendNotification();
646 application.Render();
648 // Checks the cursor and the renderer have been created.
649 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
650 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
652 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
653 DALI_TEST_CHECK( cursor );
655 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
656 DALI_TEST_CHECK( camera );
658 // The offscreen root actor has a container with all the actors which contain the text renderers.
659 Actor container = offscreenRoot.GetChildAt( 1u );
660 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
662 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
663 DALI_TEST_CHECK( renderer );
666 // Move the cursor and check the position changes.
667 Vector3 position1 = cursor.GetCurrentPosition();
669 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
670 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
673 application.SendNotification();
674 application.Render();
676 Vector3 position2 = cursor.GetCurrentPosition();
678 DALI_TEST_CHECK( position2.x < position1.x );
680 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
681 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
684 application.SendNotification();
685 application.Render();
687 Vector3 position3 = cursor.GetCurrentPosition();
689 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
691 // Send some taps and check the cursor positions.
693 // Try to tap at the beginning.
694 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
695 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
698 application.SendNotification();
699 application.Render();
701 // Cursor position should be the same than position1.
702 Vector3 position4 = cursor.GetCurrentPosition();
704 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
706 // Tap away from the start position.
707 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
708 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
711 application.SendNotification();
712 application.Render();
714 Vector3 position5 = cursor.GetCurrentPosition();
716 DALI_TEST_CHECK( position5.x > position4.x );
718 // Remove all the text.
719 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
720 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
721 editor.SetProperty( TextEditor::Property::TEXT, "" );
724 application.SendNotification();
725 application.Render();
727 // Cursor position should be the same than position2.
728 Vector3 position6 = cursor.GetCurrentPosition();
730 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
732 // Should not be a renderer.
733 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
738 int utcDaliTextEditorEvent03(void)
740 ToolkitTestApplication application;
741 tet_infoline(" utcDaliTextEditorEvent03");
743 // Checks if the highlight actor is created.
745 TextEditor editor = TextEditor::New();
746 DALI_TEST_CHECK( editor );
748 Stage::GetCurrent().Add( editor );
750 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
751 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
752 editor.SetSize( 30.f, 50.f );
753 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
754 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
756 // Avoid a crash when core load gl resources.
757 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
760 application.SendNotification();
761 application.Render();
763 // Tap first to get the focus.
764 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
765 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
768 application.SendNotification();
769 application.Render();
771 // Double tap to select a word.
772 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
773 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
776 application.SendNotification();
777 application.Render();
779 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
780 Actor offscreenRoot = editor.GetChildAt( 0u );
781 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
783 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
784 DALI_TEST_CHECK( camera );
786 // The offscreen root actor has a container with all the actors which contain the text renderers.
787 Actor container = offscreenRoot.GetChildAt( 1u );
788 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
790 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
791 DALI_TEST_CHECK( renderer );
794 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
795 DALI_TEST_CHECK( highlight );