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, "Setting font style" );
318 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("Setting font style"), 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 );
322 // Check that the Alignment properties can be correctly set
323 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
324 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
326 // Check scroll properties.
327 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
328 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
329 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
330 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
332 // Check cursor properties
333 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
334 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
335 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
336 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
338 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
339 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
340 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
341 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
342 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
343 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
344 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
345 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
347 // Check handle images
348 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
349 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
350 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
351 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
352 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
354 // Check handle images
355 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
356 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
357 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
358 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
359 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
360 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
362 // Check the highlight color
363 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
364 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
366 // Decoration bounding box
367 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
368 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
370 // Check the enable markup property.
371 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
372 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
373 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
375 // Check input color property.
376 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
377 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
379 // Check input font properties.
380 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
381 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
382 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "Setting input font style" );
383 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "Setting input font style", TEST_LOCATION );
384 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
385 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
387 // Check the line spacing property
388 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
389 editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
390 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
392 // Check the input line spacing property
393 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
394 editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
395 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
397 // Check the underline property
398 editor.SetProperty( TextEditor::Property::UNDERLINE, "Underline properties" );
399 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION );
401 // Check the input underline property
402 editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
403 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
405 // Check the shadow property
406 editor.SetProperty( TextEditor::Property::SHADOW, "Shadow properties" );
407 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
409 // Check the input shadow property
410 editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
411 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
413 // Check the emboss property
414 editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
415 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
417 // Check the input emboss property
418 editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
419 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
421 // Check the outline property
422 editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
423 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
425 // Check the input outline property
426 editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
427 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
432 // Positive Atlas Text Renderer test
433 int utcDaliTextEditorAtlasRenderP(void)
435 ToolkitTestApplication application;
436 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
437 StyleManager styleManager = StyleManager::Get();
438 styleManager.ApplyDefaultTheme();
439 TextEditor editor = TextEditor::New();
440 DALI_TEST_CHECK( editor );
442 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
444 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
446 Stage::GetCurrent().Add( editor );
450 // Render some text with the shared atlas backend
451 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
452 application.SendNotification();
453 application.Render();
457 tet_result(TET_FAIL);
462 // Positive test for the textChanged signal.
463 int utcDaliTextEditorTextChangedP(void)
465 ToolkitTestApplication application;
466 tet_infoline(" utcDaliTextEditorTextChangedP");
467 TextEditor editor = TextEditor::New();
468 DALI_TEST_CHECK( editor );
470 Stage::GetCurrent().Add( editor );
472 editor.TextChangedSignal().Connect(&TestTextChangedCallback);
474 gTextChangedCallBackCalled = false;
475 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
476 DALI_TEST_CHECK( gTextChangedCallBackCalled );
478 application.SendNotification();
480 editor.SetKeyInputFocus();
482 gTextChangedCallBackCalled = false;
483 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
484 DALI_TEST_CHECK( gTextChangedCallBackCalled );
489 int utcDaliTextEditorEvent01(void)
491 ToolkitTestApplication application;
492 tet_infoline(" utcDaliTextEditorEvent01");
494 // Creates a tap event. After creating a tap event the text editor should
495 // have the focus and add text with key events should be possible.
497 TextEditor editor = TextEditor::New();
498 DALI_TEST_CHECK( editor );
500 Stage::GetCurrent().Add( editor );
502 editor.SetSize( 300.f, 50.f );
503 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
504 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
506 // Avoid a crash when core load gl resources.
507 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
510 application.SendNotification();
511 application.Render();
513 // Add a key event but as the text editor has not the focus it should do nothing.
514 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
517 application.SendNotification();
518 application.Render();
520 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
522 // Create a tap event to touch the text editor.
523 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
524 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
527 application.SendNotification();
528 application.Render();
530 // Now the text editor has the focus, so it can handle the key events.
531 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
532 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
535 application.SendNotification();
536 application.Render();
538 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
540 // Create a second text editor and send key events to it.
541 TextEditor editor2 = TextEditor::New();
543 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
544 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
545 editor2.SetSize( 100.f, 100.f );
546 editor2.SetPosition( 100.f, 100.f );
548 Stage::GetCurrent().Add( editor2 );
551 application.SendNotification();
552 application.Render();
554 // Create a tap event on the second text editor.
555 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
556 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
559 application.SendNotification();
560 application.Render();
562 // The second text editor has the focus. It should handle the key events.
563 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
564 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
567 application.SendNotification();
568 application.Render();
570 // Check the text has been added to the second text editor.
571 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
576 int utcDaliTextEditorEvent02(void)
578 ToolkitTestApplication application;
579 tet_infoline(" utcDaliTextEditorEvent02");
581 // Checks if the right number of actors are created.
583 TextEditor editor = TextEditor::New();
584 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
585 DALI_TEST_CHECK( editor );
587 Stage::GetCurrent().Add( editor );
589 editor.SetSize( 300.f, 50.f );
590 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
591 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
593 // Avoid a crash when core load gl resources.
594 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
597 application.SendNotification();
598 application.Render();
600 // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
601 DALI_TEST_EQUALS( editor.GetChildCount(), 2u, TEST_LOCATION );
603 Actor offscreenRoot = editor.GetChildAt( 0u );
604 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
605 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
607 Actor offscreenImage = editor.GetChildAt( 1u );
608 DALI_TEST_CHECK( offscreenImage );
610 // Create a tap event to touch the text editor.
611 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
612 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
615 application.SendNotification();
616 application.Render();
618 Actor layer = editor.GetChildAt( 2u );
619 DALI_TEST_CHECK( layer.IsLayer() );
621 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
622 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
624 // Now the text editor has the focus, so it can handle the key events.
625 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
626 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
629 application.SendNotification();
630 application.Render();
632 // Checks the cursor and the renderer have been created.
633 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
634 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
636 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
637 DALI_TEST_CHECK( cursor );
639 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
640 DALI_TEST_CHECK( camera );
642 // The offscreen root actor has a container with all the actors which contain the text renderers.
643 Actor container = offscreenRoot.GetChildAt( 1u );
644 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
646 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
647 DALI_TEST_CHECK( renderer );
650 // Move the cursor and check the position changes.
651 Vector3 position1 = cursor.GetCurrentPosition();
653 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
654 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
657 application.SendNotification();
658 application.Render();
660 Vector3 position2 = cursor.GetCurrentPosition();
662 DALI_TEST_CHECK( position2.x < position1.x );
664 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
665 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
668 application.SendNotification();
669 application.Render();
671 Vector3 position3 = cursor.GetCurrentPosition();
673 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
675 // Send some taps and check the cursor positions.
677 // Try to tap at the beginning.
678 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
679 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
682 application.SendNotification();
683 application.Render();
685 // Cursor position should be the same than position1.
686 Vector3 position4 = cursor.GetCurrentPosition();
688 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
690 // Tap away from the start position.
691 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
692 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
695 application.SendNotification();
696 application.Render();
698 Vector3 position5 = cursor.GetCurrentPosition();
700 DALI_TEST_CHECK( position5.x > position4.x );
702 // Remove all the text.
703 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
704 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
705 editor.SetProperty( TextEditor::Property::TEXT, "" );
708 application.SendNotification();
709 application.Render();
711 // Cursor position should be the same than position2.
712 Vector3 position6 = cursor.GetCurrentPosition();
714 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
716 // Should not be a renderer.
717 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
722 int utcDaliTextEditorEvent03(void)
724 ToolkitTestApplication application;
725 tet_infoline(" utcDaliTextEditorEvent03");
727 // Checks if the highlight actor is created.
729 TextEditor editor = TextEditor::New();
730 DALI_TEST_CHECK( editor );
732 Stage::GetCurrent().Add( editor );
734 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
735 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
736 editor.SetSize( 30.f, 50.f );
737 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
738 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
740 // Avoid a crash when core load gl resources.
741 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
744 application.SendNotification();
745 application.Render();
747 // Tap first to get the focus.
748 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
749 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
752 application.SendNotification();
753 application.Render();
755 // Double tap to select a word.
756 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
757 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
760 application.SendNotification();
761 application.Render();
763 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
764 Actor offscreenRoot = editor.GetChildAt( 0u );
765 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
767 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
768 DALI_TEST_CHECK( camera );
770 // The offscreen root actor has a container with all the actors which contain the text renderers.
771 Actor container = offscreenRoot.GetChildAt( 1u );
772 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
774 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
775 DALI_TEST_CHECK( renderer );
778 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
779 DALI_TEST_CHECK( highlight );