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/devel-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>
25 #include <dali-toolkit/devel-api/controls/text-controls/text-editor.h> ///< @todo to be removed when text-editor is added to the dali-toolkit.h
28 using namespace Toolkit;
30 void dali_texteditor_startup(void)
32 test_return_value = TET_UNDEF;
35 void dali_texteditor_cleanup(void)
37 test_return_value = TET_PASS;
43 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
44 const char* const PROPERTY_NAME_TEXT = "text";
45 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
46 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
47 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
48 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
49 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
50 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
51 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
52 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
53 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
54 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
55 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
56 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
57 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
58 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
59 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
60 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
61 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
62 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
66 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
67 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
68 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
69 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
70 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
71 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
72 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
74 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
76 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
78 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
79 const float TO_MILLISECONDS = 1000.f;
80 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
82 const float SCROLL_THRESHOLD = 10.f;
83 const float SCROLL_SPEED = 300.f;
85 static bool gTextChangedCallBackCalled;
87 static void TestTextChangedCallback( TextEditor control )
89 tet_infoline(" TestTextChangedCallback");
91 gTextChangedCallBackCalled = true;
94 // Generate a TapGestureEvent to send to Core.
95 Integration::TapGestureEvent GenerateTap(
97 unsigned int numberOfTaps,
98 unsigned int numberOfTouches,
101 Integration::TapGestureEvent tap( state );
103 tap.numberOfTaps = numberOfTaps;
104 tap.numberOfTouches = numberOfTouches;
110 // Generate a KeyEvent to send to Core.
111 Integration::KeyEvent GenerateKey( const std::string& keyName,
112 const std::string& keyString,
115 unsigned long timeStamp,
116 const Integration::KeyEvent::State& keyState )
118 return Integration::KeyEvent( keyName,
128 int UtcDaliToolkitTextEditorConstructorP(void)
130 ToolkitTestApplication application;
131 tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
132 TextEditor textEditor;
133 DALI_TEST_CHECK( !textEditor );
137 int UtcDaliToolkitTextEditorNewP(void)
139 ToolkitTestApplication application;
140 tet_infoline(" UtcDaliToolkitTextEditorNewP");
141 TextEditor textEditor = TextEditor::New();
142 DALI_TEST_CHECK( textEditor );
146 int UtcDaliToolkitTextEditorDownCastP(void)
148 ToolkitTestApplication application;
149 tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
150 TextEditor textEditor1 = TextEditor::New();
151 BaseHandle object( textEditor1 );
153 TextEditor textEditor2 = TextEditor::DownCast( object );
154 DALI_TEST_CHECK( textEditor2 );
156 TextEditor textEditor3 = DownCast< TextEditor >( object );
157 DALI_TEST_CHECK( textEditor3 );
161 int UtcDaliToolkitTextEditorDownCastN(void)
163 ToolkitTestApplication application;
164 tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
165 BaseHandle uninitializedObject;
166 TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
167 DALI_TEST_CHECK( !textEditor1 );
169 TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
170 DALI_TEST_CHECK( !textEditor2 );
174 int UtcDaliToolkitTextEditorCopyConstructorP(void)
176 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
178 TextEditor textEditor = TextEditor::New();
179 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
181 TextEditor copy( textEditor );
182 DALI_TEST_CHECK( copy );
183 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textEditor.GetProperty<std::string>( TextLabel::Property::TEXT ) );
187 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
189 ToolkitTestApplication application;
190 tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
191 TextEditor textEditor = TextEditor::New();
192 textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
194 TextEditor copy = textEditor;
195 DALI_TEST_CHECK( copy );
196 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
200 int UtcDaliTextEditorNewP(void)
202 ToolkitTestApplication application;
203 tet_infoline(" UtcDaliToolkitTextEditorNewP");
204 TextEditor textEditor = TextEditor::New();
205 DALI_TEST_CHECK( textEditor );
209 // Positive test case for a method
210 int UtcDaliTextEditorGetPropertyP(void)
212 ToolkitTestApplication application;
213 tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
214 TextEditor editor = TextEditor::New();
215 DALI_TEST_CHECK( editor );
217 // Check Property Indices are correct
218 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
219 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
220 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
221 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
222 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
223 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
224 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
225 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
226 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
227 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
228 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
229 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
230 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
231 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
232 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
233 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
234 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
235 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
236 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
237 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
238 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
239 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
240 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
241 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
242 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
243 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
244 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
245 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
246 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
247 DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
251 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
254 Property::Map imageMap;
255 imageMap[mapKey] =mapValue;
257 editor.SetProperty( property , imageMap );
258 Property::Value propValue = editor.GetProperty( property );
259 Property::Map* resultMap = propValue.GetMap();
261 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
269 // Positive test case for a method
270 int UtcDaliTextEditorSetPropertyP(void)
272 ToolkitTestApplication application;
273 tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
274 TextEditor editor = TextEditor::New();
275 DALI_TEST_CHECK( editor );
276 Stage::GetCurrent().Add( editor );
278 // Note - we can't check the defaults since the stylesheets are platform-specific
280 // Check the render backend property.
281 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
282 DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
284 // Check text property.
285 editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
286 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
288 // Check text's color property
289 editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
290 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
292 // Check font properties.
293 editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
294 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
295 editor.SetProperty( TextEditor::Property::FONT_STYLE, "Setting font style" );
296 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_STYLE ), std::string("Setting font style"), TEST_LOCATION );
297 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
298 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
300 // Check that the Alignment properties can be correctly set
301 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
302 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
304 // Check scroll properties.
305 editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
306 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
307 editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
308 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
310 // Check cursor properties
311 editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
312 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
313 editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
314 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
316 editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
317 DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
318 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
319 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
320 editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
321 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
322 editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
323 DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
325 // Check handle images
326 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
327 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
328 editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
329 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
330 editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
332 // Check handle images
333 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
334 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
335 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
336 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
337 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
338 DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
340 // Check the highlight color
341 editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
342 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
344 // Decoration bounding box
345 editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
346 DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
348 // Check the enable markup property.
349 DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
350 editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
351 DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
353 // Check input color property.
354 editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
355 DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
357 // Check input font properties.
358 editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
359 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
360 editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, "Setting input font style" );
361 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_STYLE ), "Setting input font style", TEST_LOCATION );
362 editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
363 DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
368 // Positive Atlas Text Renderer test
369 int utcDaliTextEditorAtlasRenderP(void)
371 ToolkitTestApplication application;
372 tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
373 StyleManager styleManager = StyleManager::Get();
374 styleManager.ApplyDefaultTheme();
375 TextEditor editor = TextEditor::New();
376 DALI_TEST_CHECK( editor );
378 editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
380 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
382 Stage::GetCurrent().Add( editor );
386 // Render some text with the shared atlas backend
387 editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
388 application.SendNotification();
389 application.Render();
393 tet_result(TET_FAIL);
398 // Positive test for the textChanged signal.
399 int utcDaliTextEditorTextChangedP(void)
401 ToolkitTestApplication application;
402 tet_infoline(" utcDaliTextEditorTextChangedP");
403 TextEditor editor = TextEditor::New();
404 DALI_TEST_CHECK( editor );
406 Stage::GetCurrent().Add( editor );
408 editor.TextChangedSignal().Connect(&TestTextChangedCallback);
410 gTextChangedCallBackCalled = false;
411 editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
412 DALI_TEST_CHECK( gTextChangedCallBackCalled );
414 application.SendNotification();
416 editor.SetKeyInputFocus();
418 gTextChangedCallBackCalled = false;
419 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
420 DALI_TEST_CHECK( gTextChangedCallBackCalled );
425 int utcDaliTextEditorEvent01(void)
427 ToolkitTestApplication application;
428 tet_infoline(" utcDaliTextEditorEvent01");
430 // Creates a tap event. After creating a tap event the text editor should
431 // have the focus and add text with key events should be possible.
433 TextEditor editor = TextEditor::New();
434 DALI_TEST_CHECK( editor );
436 Stage::GetCurrent().Add( editor );
438 editor.SetSize( 300.f, 50.f );
439 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
440 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
442 // Avoid a crash when core load gl resources.
443 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
446 application.SendNotification();
447 application.Render();
449 // Add a key event but as the text editor has not the focus it should do nothing.
450 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
453 application.SendNotification();
454 application.Render();
456 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
458 // Create a tap event to touch the text editor.
459 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
460 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
463 application.SendNotification();
464 application.Render();
466 // Now the text editor has the focus, so it can handle the key events.
467 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
468 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
471 application.SendNotification();
472 application.Render();
474 DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
476 // Create a second text editor and send key events to it.
477 TextEditor editor2 = TextEditor::New();
479 editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
480 editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
481 editor2.SetSize( 100.f, 100.f );
482 editor2.SetPosition( 100.f, 100.f );
484 Stage::GetCurrent().Add( editor2 );
487 application.SendNotification();
488 application.Render();
490 // Create a tap event on the second text editor.
491 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
492 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
495 application.SendNotification();
496 application.Render();
498 // The second text editor has the focus. It should handle the key events.
499 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
500 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
503 application.SendNotification();
504 application.Render();
506 // Check the text has been added to the second text editor.
507 DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
512 int utcDaliTextEditorEvent02(void)
514 ToolkitTestApplication application;
515 tet_infoline(" utcDaliTextEditorEvent02");
517 // Checks if the right number of actors are created.
519 TextEditor editor = TextEditor::New();
520 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
521 DALI_TEST_CHECK( editor );
523 Stage::GetCurrent().Add( editor );
525 editor.SetSize( 300.f, 50.f );
526 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
527 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
529 // Avoid a crash when core load gl resources.
530 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
533 application.SendNotification();
534 application.Render();
536 // Check there are the expected number of children ( active layer, offscreen root actor, and the offscreen image actor
537 DALI_TEST_EQUALS( editor.GetChildCount(), 3u, TEST_LOCATION );
539 Actor layer = editor.GetChildAt( 0u );
540 DALI_TEST_CHECK( layer.IsLayer() );
542 Actor offscreenRoot = editor.GetChildAt( 1u );
543 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
544 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
546 Actor offscreenImage = editor.GetChildAt( 2u );
547 DALI_TEST_CHECK( offscreenImage );
549 // Create a tap event to touch the text editor.
550 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
551 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
554 application.SendNotification();
555 application.Render();
557 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
558 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
560 // Now the text editor has the focus, so it can handle the key events.
561 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
562 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
565 application.SendNotification();
566 application.Render();
568 // Checks the cursor and the renderer have been created.
569 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
570 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
572 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
573 DALI_TEST_CHECK( cursor );
575 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
576 DALI_TEST_CHECK( camera );
578 Renderer renderer = offscreenRoot.GetChildAt( 1u ).GetRendererAt( 0u );
579 DALI_TEST_CHECK( renderer );
581 // Move the cursor and check the position changes.
582 Vector3 position1 = cursor.GetCurrentPosition();
584 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
585 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
588 application.SendNotification();
589 application.Render();
591 Vector3 position2 = cursor.GetCurrentPosition();
593 DALI_TEST_CHECK( position2.x < position1.x );
595 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
596 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
599 application.SendNotification();
600 application.Render();
602 Vector3 position3 = cursor.GetCurrentPosition();
604 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
606 // Send some taps and check the cursor positions.
608 // Try to tap at the beginning.
609 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
610 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
613 application.SendNotification();
614 application.Render();
616 // Cursor position should be the same than position1.
617 Vector3 position4 = cursor.GetCurrentPosition();
619 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
621 // Tap away from the start position.
622 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
623 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
626 application.SendNotification();
627 application.Render();
629 Vector3 position5 = cursor.GetCurrentPosition();
631 DALI_TEST_CHECK( position5.x > position4.x );
633 // Remove all the text.
634 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
635 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
636 editor.SetProperty( TextEditor::Property::TEXT, "" );
639 application.SendNotification();
640 application.Render();
642 // Cursor position should be the same than position2.
643 Vector3 position6 = cursor.GetCurrentPosition();
645 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
647 // Should not be a renderer.
648 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
653 int utcDaliTextEditorEvent03(void)
655 ToolkitTestApplication application;
656 tet_infoline(" utcDaliTextEditorEvent03");
658 // Checks if the highlight actor is created.
660 TextEditor editor = TextEditor::New();
661 DALI_TEST_CHECK( editor );
663 Stage::GetCurrent().Add( editor );
665 editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
666 editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
667 editor.SetSize( 30.f, 50.f );
668 editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
669 editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
671 // Avoid a crash when core load gl resources.
672 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
675 application.SendNotification();
676 application.Render();
678 // Tap first to get the focus.
679 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
680 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
683 application.SendNotification();
684 application.Render();
686 // Double tap to select a word.
687 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
688 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
691 application.SendNotification();
692 application.Render();
694 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
695 Actor offscreenRoot = editor.GetChildAt( 1u );
696 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
698 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
699 DALI_TEST_CHECK( camera );
701 Renderer renderer = offscreenRoot.GetChildAt( 1u ).GetRendererAt( 0u );
702 DALI_TEST_CHECK( renderer );
704 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
705 DALI_TEST_CHECK( highlight );