2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/tap-gesture-event.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/pan-gesture-event.h>
27 #include <dali/integration-api/events/long-press-gesture-event.h>
28 #include <dali-toolkit-test-suite-utils.h>
29 #include <dali-toolkit/dali-toolkit.h>
32 using namespace Toolkit;
34 void dali_textfield_startup(void)
36 test_return_value = TET_UNDEF;
39 void dali_textfield_cleanup(void)
41 test_return_value = TET_PASS;
47 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
48 const char* const PROPERTY_NAME_TEXT = "text";
49 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT = "placeholderText";
50 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
51 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
52 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
53 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
54 const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength";
55 const char* const PROPERTY_NAME_EXCEED_POLICY = "exceedPolicy";
56 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
57 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment";
58 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
59 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor";
60 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset";
61 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor";
62 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
63 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
64 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
65 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
66 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
67 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
68 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
69 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
70 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
71 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
72 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
73 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
74 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
78 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
79 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
80 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "inputMethodSettings";
81 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
82 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
83 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
84 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
85 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
87 const char* const PROPERTY_NAME_UNDERLINE = "underline";
88 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
89 const char* const PROPERTY_NAME_SHADOW = "shadow";
90 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
91 const char* const PROPERTY_NAME_EMBOSS = "emboss";
92 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
93 const char* const PROPERTY_NAME_OUTLINE = "outline";
94 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
96 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
98 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
99 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
101 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
102 const float RENDER_FRAME_INTERVAL = 16.66f;
104 const float TO_MILLISECONDS = 1000.f;
105 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
107 const float SCROLL_THRESHOLD = 10.f;
108 const float SCROLL_SPEED = 300.f;
110 const unsigned int DEFAULT_FONT_SIZE = 1152u;
111 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
113 static bool gTextChangedCallBackCalled;
114 static bool gMaxCharactersCallBackCalled;
115 static bool gInputStyleChangedCallbackCalled;
116 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
118 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
120 Integration::ResourceRequest* request = platform.GetRequest();
121 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
122 Integration::ResourcePointer resource(bitmap);
123 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
127 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
131 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
135 LoadBitmapResource( app.GetPlatform(), width, height );
137 Property::Map propertyMap;
138 propertyMap["filename"] = "image.png";
139 propertyMap["width"] = width;
140 propertyMap["height"] = height;
141 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
142 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
143 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
144 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
145 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
146 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
147 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
148 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
151 // Generate a PanGestureEvent to send to Core
152 static Integration::PanGestureEvent GeneratePan(
153 Gesture::State state,
154 const Vector2& previousPosition,
155 const Vector2& currentPosition,
156 unsigned long timeDelta,
157 unsigned int numberOfTouches = 1)
159 Integration::PanGestureEvent pan(state);
161 pan.previousPosition = previousPosition;
162 pan.currentPosition = currentPosition;
163 pan.timeDelta = timeDelta;
164 pan.numberOfTouches = numberOfTouches;
170 * Helper to generate PanGestureEvent
172 * @param[in] application Application instance
173 * @param[in] state The Gesture State
174 * @param[in] pos The current position of touch.
176 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
180 if( (state == Gesture::Started) ||
181 (state == Gesture::Possible) )
187 application.ProcessEvent(GeneratePan(state, last, pos, 16));
194 * Simulate time passed by.
196 * @note this will always process at least 1 frame (1/60 sec)
198 * @param application Test application instance
199 * @param duration Time to pass in milliseconds.
200 * @return The actual time passed in milliseconds
202 static int Wait(ToolkitTestApplication& application, int duration = 0)
206 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
208 application.SendNotification();
209 application.Render(RENDER_FRAME_INTERVAL);
210 time += RENDER_FRAME_INTERVAL;
216 struct CallbackFunctor
218 CallbackFunctor(bool* callbackFlag)
219 : mCallbackFlag( callbackFlag )
225 *mCallbackFlag = true;
230 static void TestTextChangedCallback( TextField control )
232 tet_infoline(" TestTextChangedCallback");
234 gTextChangedCallBackCalled = true;
237 static void TestMaxLengthReachedCallback( TextField control )
239 tet_infoline(" TestMaxLengthReachedCallback");
241 gMaxCharactersCallBackCalled = true;
244 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
246 tet_infoline(" TestInputStyleChangedCallback");
248 gInputStyleChangedCallbackCalled = true;
249 gInputStyleMask = mask;
252 // Generate a TapGestureEvent to send to Core.
253 Integration::TapGestureEvent GenerateTap(
254 Gesture::State state,
255 unsigned int numberOfTaps,
256 unsigned int numberOfTouches,
259 Integration::TapGestureEvent tap( state );
261 tap.numberOfTaps = numberOfTaps;
262 tap.numberOfTouches = numberOfTouches;
269 Integration::LongPressGestureEvent GenerateLongPress(
270 Gesture::State state,
271 unsigned int numberOfTouches,
274 Integration::LongPressGestureEvent longPress( state );
276 longPress.numberOfTouches = numberOfTouches;
277 longPress.point = point;
281 // Generate a KeyEvent to send to Core.
282 Integration::KeyEvent GenerateKey( const std::string& keyName,
283 const std::string& keyString,
286 unsigned long timeStamp,
287 const Integration::KeyEvent::State& keyState )
289 return Integration::KeyEvent( keyName,
299 int UtcDaliToolkitTextFieldConstructorP(void)
301 ToolkitTestApplication application;
302 tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
304 DALI_TEST_CHECK( !textField );
308 int UtcDaliToolkitTextFieldNewP(void)
310 ToolkitTestApplication application;
311 tet_infoline(" UtcDaliToolkitTextFieldNewP");
312 TextField textField = TextField::New();
313 DALI_TEST_CHECK( textField );
317 int UtcDaliToolkitTextFieldDownCastP(void)
319 ToolkitTestApplication application;
320 tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
321 TextField textField1 = TextField::New();
322 BaseHandle object( textField1 );
324 TextField textField2 = TextField::DownCast( object );
325 DALI_TEST_CHECK( textField2 );
327 TextField textField3 = DownCast< TextField >( object );
328 DALI_TEST_CHECK( textField3 );
332 int UtcDaliToolkitTextFieldDownCastN(void)
334 ToolkitTestApplication application;
335 tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
336 BaseHandle uninitializedObject;
337 TextField textField1 = TextField::DownCast( uninitializedObject );
338 DALI_TEST_CHECK( !textField1 );
340 TextField textField2 = DownCast< TextField >( uninitializedObject );
341 DALI_TEST_CHECK( !textField2 );
345 int UtcDaliToolkitTextFieldCopyConstructorP(void)
347 ToolkitTestApplication application;
348 tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
349 TextField textField = TextField::New();
350 textField.SetProperty( TextField::Property::TEXT, "Test" );
352 TextField copy( textField );
353 DALI_TEST_CHECK( copy );
354 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
358 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
360 ToolkitTestApplication application;
361 tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
362 TextField textField = TextField::New();
363 textField.SetProperty( TextField::Property::TEXT, "Test" );
365 TextField copy = textField;
366 DALI_TEST_CHECK( copy );
367 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
371 int UtcDaliTextFieldNewP(void)
373 ToolkitTestApplication application;
374 tet_infoline(" UtcDaliToolkitTextFieldNewP");
375 TextField textField = TextField::New();
376 DALI_TEST_CHECK( textField );
380 // Positive test case for a method
381 int UtcDaliTextFieldGetPropertyP(void)
383 ToolkitTestApplication application;
384 tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
385 TextField field = TextField::New();
386 DALI_TEST_CHECK( field );
388 // Check Property Indices are correct
389 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND );
390 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
391 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
392 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
393 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
394 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
395 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
396 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
397 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
398 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
399 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
400 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
401 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
402 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextField::Property::SHADOW_OFFSET );
403 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextField::Property::SHADOW_COLOR );
404 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
405 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
406 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
407 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
408 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
409 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
410 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
411 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
412 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
413 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
414 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
415 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
416 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
417 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
418 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
419 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
420 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
421 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
422 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
423 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
424 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
425 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
426 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
427 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
428 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
429 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
430 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
431 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
432 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
433 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
434 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
435 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
440 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
443 Property::Map imageMap;
444 imageMap[mapKey] =mapValue;
446 field.SetProperty( property , imageMap );
447 Property::Value propValue = field.GetProperty( property );
448 Property::Map* resultMap = propValue.GetMap();
450 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
458 // Positive test case for a method
459 int UtcDaliTextFieldSetPropertyP(void)
461 ToolkitTestApplication application;
462 tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
463 TextField field = TextField::New();
464 DALI_TEST_CHECK( field );
465 Stage::GetCurrent().Add( field );
467 // Note - we can't check the defaults since the stylesheets are platform-specific
469 // Check the render backend property.
470 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
471 DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty<int>( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
473 // Check text property.
474 field.SetProperty( TextField::Property::TEXT, "Setting Text" );
475 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
477 // Check placeholder text properties.
478 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
479 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
481 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
482 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
484 // Check font properties.
485 field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
486 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
487 field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
488 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION );
489 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
490 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
493 field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
494 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
495 field.SetProperty( TextField::Property::FONT_STYLE, "{\"slant\":\"roman\"}" );
496 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
497 field.SetProperty( TextField::Property::FONT_STYLE, "" );
498 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string(""), TEST_LOCATION );
500 // Check that the MAX_LENGTH property can be correctly set
501 const int maxNumberOfCharacters = 20;
502 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
503 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
505 // Check exceed policy
506 // Set a different exceed policy is not implemented.
508 // Check that the Alignment properties can be correctly set
509 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
510 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
511 field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
512 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
514 // Check text's color property
515 field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
516 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
518 // Check placeholder text's color property.
519 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
520 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
522 // Check shadow properties.
523 field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
524 DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
525 field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
526 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
528 // Check cursor properties
529 field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
530 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
531 field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
532 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
534 field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
535 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
536 field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
537 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
538 field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
539 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
540 field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
541 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
543 // Check scroll properties.
544 field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
545 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
546 field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
547 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
549 // Check handle images
550 field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
551 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
552 field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
553 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
554 field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
556 // Check handle images
557 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
558 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
559 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
560 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
561 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
562 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
564 // Check the highlight color
565 field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
566 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
568 // Decoration bounding box
569 field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
570 DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
572 // Check input color property.
573 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
574 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
576 // Check the enable markup property.
577 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
578 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
579 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
581 // Check input font properties.
582 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
583 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
584 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
585 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
586 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
587 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
589 // Reset input font style.
590 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
591 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
592 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
593 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
594 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "" );
595 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
597 // Check the underline property
598 field.SetProperty( TextField::Property::UNDERLINE, "Underline properties" );
599 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION );
601 // Check the input underline property
602 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
603 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
605 // Check the shadow property
606 field.SetProperty( TextField::Property::SHADOW, "Shadow properties" );
607 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
609 // Check the input shadow property
610 field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
611 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
613 // Check the emboss property
614 field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
615 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
617 // Check the input emboss property
618 field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
619 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
621 // Check the outline property
622 field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
623 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
625 // Check the input outline property
626 field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
627 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
632 // Positive Atlas Text Renderer test
633 int utcDaliTextFieldAtlasRenderP(void)
635 ToolkitTestApplication application;
636 tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
637 StyleManager styleManager = StyleManager::Get();
638 styleManager.ApplyDefaultTheme();
639 TextField field = TextField::New();
640 DALI_TEST_CHECK( field );
642 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
644 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
646 Stage::GetCurrent().Add( field );
650 // Render some text with the shared atlas backend
651 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
652 application.SendNotification();
653 application.Render();
657 tet_result(TET_FAIL);
662 // Positive test for the textChanged signal.
663 int utcDaliTextFieldTextChangedP(void)
665 ToolkitTestApplication application;
666 tet_infoline(" utcDaliTextFieldTextChangedP");
667 TextField field = TextField::New();
668 DALI_TEST_CHECK( field );
670 Stage::GetCurrent().Add( field );
672 // connect to the text changed signal.
673 ConnectionTracker* testTracker = new ConnectionTracker();
674 field.TextChangedSignal().Connect(&TestTextChangedCallback);
675 bool textChangedSignal = false;
676 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
678 gTextChangedCallBackCalled = false;
679 field.SetProperty( TextField::Property::TEXT, "ABC" );
680 DALI_TEST_CHECK( gTextChangedCallBackCalled );
681 DALI_TEST_CHECK( textChangedSignal );
683 application.SendNotification();
685 field.SetKeyInputFocus();
687 gTextChangedCallBackCalled = false;
688 application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
689 DALI_TEST_CHECK( gTextChangedCallBackCalled );
694 // Negative test for the textChanged signal.
695 int utcDaliTextFieldTextChangedN(void)
697 ToolkitTestApplication application;
698 tet_infoline(" utcDaliTextFieldTextChangedN");
699 TextField field = TextField::New();
700 DALI_TEST_CHECK( field );
702 Stage::GetCurrent().Add( field );
704 // connect to the text changed signal.
705 ConnectionTracker* testTracker = new ConnectionTracker();
706 field.TextChangedSignal().Connect(&TestTextChangedCallback);
707 bool textChangedSignal = false;
708 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
710 gTextChangedCallBackCalled = false;
711 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
712 DALI_TEST_CHECK( !gTextChangedCallBackCalled );
713 DALI_TEST_CHECK( !textChangedSignal );
718 // Positive test for Max Characters reached signal.
719 int utcDaliTextFieldMaxCharactersReachedP(void)
721 ToolkitTestApplication application;
722 tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
723 TextField field = TextField::New();
724 DALI_TEST_CHECK( field );
726 Stage::GetCurrent().Add( field );
728 const int maxNumberOfCharacters = 1;
729 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
731 field.SetKeyInputFocus();
733 // connect to the text changed signal.
734 ConnectionTracker* testTracker = new ConnectionTracker();
735 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
736 bool maxLengthReachedSignal = false;
737 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
739 gMaxCharactersCallBackCalled = false;
741 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
742 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
744 DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
745 DALI_TEST_CHECK( maxLengthReachedSignal );
750 // Negative test for Max Characters reached signal.
751 int utcDaliTextFieldMaxCharactersReachedN(void)
753 ToolkitTestApplication application;
754 tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
755 TextField field = TextField::New();
756 DALI_TEST_CHECK( field );
758 Stage::GetCurrent().Add( field );
760 const int maxNumberOfCharacters = 3;
761 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
763 field.SetKeyInputFocus();
765 // connect to the text changed signal.
766 ConnectionTracker* testTracker = new ConnectionTracker();
767 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
768 bool maxLengthReachedSignal = false;
769 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
771 gMaxCharactersCallBackCalled = false;
773 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
774 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
776 DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
777 DALI_TEST_CHECK( !maxLengthReachedSignal );
782 int utcDaliTextFieldInputStyleChanged01(void)
784 ToolkitTestApplication application;
785 tet_infoline(" utcDaliTextFieldInputStyleChanged01");
787 // The text-field emits signals when the input style changes. These changes of style are
788 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
789 // can't be emitted during the size negotiation as the callbacks may update the UI.
790 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
791 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
792 application.CreateAdaptor();
796 char* pathNamePtr = get_current_dir_name();
797 const std::string pathName( pathNamePtr );
800 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
801 fontClient.SetDpi( 93u, 93u );
803 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
804 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
806 TextField field = TextField::New();
807 DALI_TEST_CHECK( field );
810 field.SetSize( 300.f, 50.f );
811 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
812 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
814 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
815 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
817 // connect to the text changed signal.
818 ConnectionTracker* testTracker = new ConnectionTracker();
819 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
820 bool inputStyleChangedSignal = false;
821 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
823 Stage::GetCurrent().Add( field );
826 application.SendNotification();
827 application.Render();
829 // Executes the idle callbacks added by the text control on the change of input style.
830 application.RunIdles();
832 gInputStyleChangedCallbackCalled = false;
833 gInputStyleMask = TextField::InputStyle::NONE;
834 inputStyleChangedSignal = false;
836 // Create a tap event to touch the text field.
837 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
838 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
841 application.SendNotification();
842 application.Render();
844 // Executes the idle callbacks added by the text control on the change of input style.
845 application.RunIdles();
847 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
848 if( gInputStyleChangedCallbackCalled )
850 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
852 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
853 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
855 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
856 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
858 DALI_TEST_CHECK( inputStyleChangedSignal );
860 gInputStyleChangedCallbackCalled = false;
861 gInputStyleMask = TextField::InputStyle::NONE;
862 inputStyleChangedSignal = false;
864 // Create a tap event to touch the text field.
865 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
866 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
869 application.SendNotification();
870 application.Render();
872 // Executes the idle callbacks added by the text control on the change of input style.
873 application.RunIdles();
875 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
876 DALI_TEST_CHECK( !inputStyleChangedSignal );
878 gInputStyleChangedCallbackCalled = false;
879 gInputStyleMask = TextField::InputStyle::NONE;
880 inputStyleChangedSignal = false;
882 // Create a tap event to touch the text field.
883 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
884 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
887 application.SendNotification();
888 application.Render();
890 // Executes the idle callbacks added by the text control on the change of input style.
891 application.RunIdles();
893 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
894 if( gInputStyleChangedCallbackCalled )
896 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
898 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
899 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
901 DALI_TEST_CHECK( inputStyleChangedSignal );
903 gInputStyleChangedCallbackCalled = false;
904 gInputStyleMask = TextField::InputStyle::NONE;
905 inputStyleChangedSignal = false;
907 // Create a tap event to touch the text field.
908 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
909 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
912 application.SendNotification();
913 application.Render();
915 // Executes the idle callbacks added by the text control on the change of input style.
916 application.RunIdles();
918 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
919 if( gInputStyleChangedCallbackCalled )
921 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
923 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
924 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
926 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
927 DALI_TEST_EQUALS( style, "{\"weight\":\"bold\"}", TEST_LOCATION );
929 DALI_TEST_CHECK( inputStyleChangedSignal );
931 gInputStyleChangedCallbackCalled = false;
932 gInputStyleMask = TextField::InputStyle::NONE;
933 inputStyleChangedSignal = false;
935 // Create a tap event to touch the text field.
936 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
937 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
940 application.SendNotification();
941 application.Render();
943 // Executes the idle callbacks added by the text control on the change of input style.
944 application.RunIdles();
946 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
947 DALI_TEST_CHECK( !inputStyleChangedSignal );
949 gInputStyleChangedCallbackCalled = false;
950 gInputStyleMask = TextField::InputStyle::NONE;
951 inputStyleChangedSignal = false;
953 // Create a tap event to touch the text field.
954 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
955 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
958 application.SendNotification();
959 application.Render();
961 // Executes the idle callbacks added by the text control on the change of input style.
962 application.RunIdles();
964 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
965 if( gInputStyleChangedCallbackCalled )
967 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
969 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
970 DALI_TEST_CHECK( style.empty() );
972 DALI_TEST_CHECK( inputStyleChangedSignal );
974 gInputStyleChangedCallbackCalled = false;
975 gInputStyleMask = TextField::InputStyle::NONE;
976 inputStyleChangedSignal = false;
978 // Create a tap event to touch the text field.
979 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
980 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
983 application.SendNotification();
984 application.Render();
986 // Executes the idle callbacks added by the text control on the change of input style.
987 application.RunIdles();
989 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
990 DALI_TEST_CHECK( !inputStyleChangedSignal );
995 int utcDaliTextFieldInputStyleChanged02(void)
997 ToolkitTestApplication application;
998 tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1000 // The text-field emits signals when the input style changes. These changes of style are
1001 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1002 // can't be emitted during the size negotiation as the callbacks may update the UI.
1003 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1004 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1005 application.CreateAdaptor();
1009 char* pathNamePtr = get_current_dir_name();
1010 const std::string pathName( pathNamePtr );
1011 free( pathNamePtr );
1013 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1014 fontClient.SetDpi( 93u, 93u );
1016 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1017 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1019 TextField field = TextField::New();
1020 DALI_TEST_CHECK( field );
1023 field.SetSize( 300.f, 50.f );
1024 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1025 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1027 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1028 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='blue'> l</color><color value='green'>lo</color> <font weight='bold'>world</font> demo</font>" );
1030 // connect to the text changed signal.
1031 ConnectionTracker* testTracker = new ConnectionTracker();
1032 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1033 bool inputStyleChangedSignal = false;
1034 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1036 Stage::GetCurrent().Add( field );
1038 // Render and notify
1039 application.SendNotification();
1040 application.Render();
1042 // Executes the idle callbacks added by the text control on the change of input style.
1043 application.RunIdles();
1045 gInputStyleChangedCallbackCalled = false;
1046 gInputStyleMask = TextField::InputStyle::NONE;
1047 inputStyleChangedSignal = false;
1049 // Create a tap event to touch the text field.
1050 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1051 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1052 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1053 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1055 // Render and notify
1056 application.SendNotification();
1057 application.Render();
1059 // Executes the idle callbacks added by the text control on the change of input style.
1060 application.RunIdles();
1062 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1063 if( gInputStyleChangedCallbackCalled )
1065 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1066 static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1067 TextField::InputStyle::POINT_SIZE |
1068 TextField::InputStyle::COLOR ),
1071 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1072 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1074 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1075 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1077 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1078 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1080 DALI_TEST_CHECK( inputStyleChangedSignal );
1082 gInputStyleChangedCallbackCalled = false;
1083 gInputStyleMask = TextField::InputStyle::NONE;
1084 inputStyleChangedSignal = false;
1086 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1088 // Render and notify
1089 application.SendNotification();
1090 application.Render();
1092 // Executes the idle callbacks added by the text control on the change of input style.
1093 application.RunIdles();
1095 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1096 if( gInputStyleChangedCallbackCalled )
1098 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1099 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1102 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1103 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1105 DALI_TEST_CHECK( inputStyleChangedSignal );
1107 gInputStyleChangedCallbackCalled = false;
1108 gInputStyleMask = TextField::InputStyle::NONE;
1109 inputStyleChangedSignal = false;
1111 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1113 // Render and notify
1114 application.SendNotification();
1115 application.Render();
1117 // Executes the idle callbacks added by the text control on the change of input style.
1118 application.RunIdles();
1120 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1121 DALI_TEST_CHECK( !inputStyleChangedSignal );
1123 gInputStyleChangedCallbackCalled = false;
1124 gInputStyleMask = TextField::InputStyle::NONE;
1125 inputStyleChangedSignal = false;
1127 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1129 // Render and notify
1130 application.SendNotification();
1131 application.Render();
1133 // Executes the idle callbacks added by the text control on the change of input style.
1134 application.RunIdles();
1136 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1137 if( gInputStyleChangedCallbackCalled )
1139 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1140 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1143 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1144 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1146 DALI_TEST_CHECK( inputStyleChangedSignal );
1148 gInputStyleChangedCallbackCalled = false;
1149 gInputStyleMask = TextField::InputStyle::NONE;
1150 inputStyleChangedSignal = false;
1152 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1154 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
1155 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1157 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1158 field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1159 field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1160 field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1162 // Render and notify
1163 application.SendNotification();
1164 application.Render();
1166 // Executes the idle callbacks added by the text control on the change of input style.
1167 application.RunIdles();
1169 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1170 DALI_TEST_CHECK( !inputStyleChangedSignal );
1172 // Create a tap event to touch the text field.
1173 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1174 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1176 // Render and notify
1177 application.SendNotification();
1178 application.Render();
1180 // Executes the idle callbacks added by the text control on the change of input style.
1181 application.RunIdles();
1183 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1184 if( gInputStyleChangedCallbackCalled )
1186 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1187 static_cast<unsigned int>( TextField::InputStyle::COLOR |
1188 TextField::InputStyle::POINT_SIZE |
1189 TextField::InputStyle::FONT_STYLE |
1190 TextField::InputStyle::UNDERLINE |
1191 TextField::InputStyle::SHADOW |
1192 TextField::InputStyle::EMBOSS |
1193 TextField::InputStyle::OUTLINE ),
1196 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1197 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1199 DALI_TEST_CHECK( inputStyleChangedSignal );
1204 int utcDaliTextFieldEvent01(void)
1206 ToolkitTestApplication application;
1207 tet_infoline(" utcDaliTextFieldEvent01");
1209 // Creates a tap event. After creating a tap event the text field should
1210 // have the focus and add text with key events should be possible.
1212 TextField field = TextField::New();
1213 DALI_TEST_CHECK( field );
1215 Stage::GetCurrent().Add( field );
1217 field.SetSize( 300.f, 50.f );
1218 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1219 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1221 // Avoid a crash when core load gl resources.
1222 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1224 // Render and notify
1225 application.SendNotification();
1226 application.Render();
1228 // Add a key event but as the text field has not the focus it should do nothing.
1229 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1231 // Render and notify
1232 application.SendNotification();
1233 application.Render();
1235 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1237 // Create a tap event to touch the text field.
1238 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1239 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1241 // Render and notify
1242 application.SendNotification();
1243 application.Render();
1245 // Now the text field has the focus, so it can handle the key events.
1246 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1247 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1249 // Render and notify
1250 application.SendNotification();
1251 application.Render();
1253 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1255 // Create a second text field and send key events to it.
1256 TextField field2 = TextField::New();
1258 field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1259 field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1260 field2.SetSize( 100.f, 100.f );
1261 field2.SetPosition( 100.f, 100.f );
1263 Stage::GetCurrent().Add( field2 );
1265 // Render and notify
1266 application.SendNotification();
1267 application.Render();
1269 // Create a tap event on the second text field.
1270 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1271 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1273 // Render and notify
1274 application.SendNotification();
1275 application.Render();
1277 // The second text field has the focus. It should handle the key events.
1278 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1279 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1281 // Render and notify
1282 application.SendNotification();
1283 application.Render();
1285 // Check the text has been added to the second text field.
1286 DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1291 int utcDaliTextFieldEvent02(void)
1293 ToolkitTestApplication application;
1294 tet_infoline(" utcDaliTextFieldEvent02");
1296 // Checks if the right number of actors are created.
1298 TextField field = TextField::New();
1299 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1300 DALI_TEST_CHECK( field );
1301 LoadMarkerImages(application, field);
1303 Stage::GetCurrent().Add( field );
1305 field.SetSize( 300.f, 50.f );
1306 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1307 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1309 // Avoid a crash when core load gl resources.
1310 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1312 // Render and notify
1313 application.SendNotification();
1314 application.Render();
1316 // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
1317 DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
1319 Actor offscreenRoot = field.GetChildAt( 0u );
1320 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1321 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1323 Actor offscreenImage = field.GetChildAt( 1u );
1324 DALI_TEST_CHECK( offscreenImage );
1326 // Create a tap event to touch the text field.
1327 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1328 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1330 // Render and notify
1331 application.SendNotification();
1332 application.Render();
1334 Actor layer = field.GetChildAt( 2u );
1335 DALI_TEST_CHECK( layer.IsLayer() );
1337 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1338 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1340 // Now the text field has the focus, so it can handle the key events.
1341 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1342 application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1344 // Render and notify
1345 application.SendNotification();
1346 application.Render();
1348 // Checks the cursor and the renderer have been created.
1349 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1350 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
1352 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1353 DALI_TEST_CHECK( cursor );
1355 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1356 DALI_TEST_CHECK( camera );
1358 // The offscreen root actor has a container with all the actors which contain the text renderers.
1359 Actor container = offscreenRoot.GetChildAt( 1u );
1360 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1362 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1363 DALI_TEST_CHECK( renderer );
1366 // Move the cursor and check the position changes.
1367 Vector3 position1 = cursor.GetCurrentPosition();
1369 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1370 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1372 // Render and notify
1373 application.SendNotification();
1374 application.Render();
1376 Vector3 position2 = cursor.GetCurrentPosition();
1378 DALI_TEST_CHECK( position2.x < position1.x );
1380 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1381 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1383 // Render and notify
1384 application.SendNotification();
1385 application.Render();
1387 Vector3 position3 = cursor.GetCurrentPosition();
1389 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1391 // Send some taps and check the cursor positions.
1393 // Try to tap at the beginning.
1394 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1395 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1397 // Render and notify
1398 application.SendNotification();
1399 application.Render();
1401 // Cursor position should be the same than position1.
1402 Vector3 position4 = cursor.GetCurrentPosition();
1404 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1406 // Tap away from the start position.
1407 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1408 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1410 // Render and notify
1411 application.SendNotification();
1412 application.Render();
1414 Vector3 position5 = cursor.GetCurrentPosition();
1416 DALI_TEST_CHECK( position5.x > position4.x );
1418 // Remove all the text.
1419 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1420 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1421 field.SetProperty( TextField::Property::TEXT, "" );
1423 // Render and notify
1424 application.SendNotification();
1425 application.Render();
1427 // Cursor position should be the same than position2.
1428 Vector3 position6 = cursor.GetCurrentPosition();
1430 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1432 // Should not be a renderer.
1433 DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
1438 int utcDaliTextFieldEvent03(void)
1440 ToolkitTestApplication application;
1441 tet_infoline(" utcDaliTextFieldEvent03");
1443 // Checks if the highlight actor is created.
1445 TextField field = TextField::New();
1446 DALI_TEST_CHECK( field );
1448 Stage::GetCurrent().Add( field );
1450 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1451 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1452 field.SetSize( 30.f, 50.f );
1453 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1454 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1456 // Avoid a crash when core load gl resources.
1457 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1458 LoadMarkerImages(application, field);
1460 // Render and notify
1461 application.SendNotification();
1462 application.Render();
1464 // Tap first to get the focus.
1465 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1466 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1468 // Render and notify
1469 application.SendNotification();
1470 application.Render();
1472 // Double tap to select a word.
1473 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1474 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1476 // Render and notify
1477 application.SendNotification();
1478 application.Render();
1480 // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
1481 Actor offscreenRoot = field.GetChildAt( 1u );
1482 DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1484 CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1485 DALI_TEST_CHECK( camera );
1487 // The offscreen root actor has a container with all the actors which contain the text renderers.
1488 Actor container = offscreenRoot.GetChildAt( 1u );
1489 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1491 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1492 DALI_TEST_CHECK( renderer );
1495 Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
1496 DALI_TEST_CHECK( highlight );
1501 int utcDaliTextFieldEvent04(void)
1503 ToolkitTestApplication application;
1504 tet_infoline(" utcDaliTextFieldEvent04");
1506 // Checks if the highlight actor is created.
1508 TextField field = TextField::New();
1509 DALI_TEST_CHECK( field );
1510 Stage::GetCurrent().Add( field );
1511 LoadMarkerImages(application, field);
1512 // Render and notify
1513 application.SendNotification();
1514 application.Render();
1516 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1517 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1518 field.SetSize( 300.f, 50.f );
1519 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1520 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1522 // Avoid a crash when core load gl resources.
1523 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1524 // Render and notify
1525 application.SendNotification();
1526 application.Render();
1528 // Create a tap event to touch the text field.
1529 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1530 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1531 // Render and notify
1532 application.SendNotification();
1533 application.Render();
1536 // Tap first to get the focus.
1537 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1538 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1540 // Render and notify
1541 application.SendNotification();
1542 application.Render();
1544 // Double tap to select a word.
1545 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1546 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1548 // Render and notify
1549 application.SendNotification();
1550 application.Render();
1553 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1554 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1558 int utcDaliTextFieldEvent05(void)
1560 ToolkitTestApplication application;
1561 tet_infoline(" utcDaliTextFieldEvent05");
1563 // Checks dragging of cursor/grab handle
1565 TextField field = TextField::New();
1566 DALI_TEST_CHECK( field );
1567 Stage::GetCurrent().Add( field );
1568 LoadMarkerImages(application, field);
1569 // Render and notify
1570 application.SendNotification();
1571 application.Render();
1573 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1574 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1575 field.SetSize( 300.f, 50.f );
1576 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1577 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1579 // Avoid a crash when core load gl resources.
1580 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1581 // Render and notify
1582 application.SendNotification();
1583 application.Render();
1585 // Create a tap event to touch the text field.
1586 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1587 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1588 // Render and notify
1589 application.SendNotification();
1590 application.Render();
1593 // Tap first to get the focus.
1594 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1595 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1597 // Render and notify
1598 application.SendNotification();
1599 application.Render();
1601 // Double tap to select a word.
1602 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1603 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1605 // Render and notify
1606 application.SendNotification();
1607 application.Render();
1609 // drag grab handle right
1610 Vector2 pos(0.0f, 40.0f);
1611 SendPan(application, Gesture::Possible, pos);
1612 SendPan(application, Gesture::Started, pos);
1614 Wait(application, 100);
1616 for(int i = 0;i<20;i++)
1618 SendPan(application, Gesture::Continuing, pos);
1623 SendPan(application, Gesture::Finished, pos);
1624 Wait(application, RENDER_FRAME_INTERVAL);
1626 Actor offscreenRoot = field.GetChildAt( 1u );
1630 int utcDaliTextFieldEvent06(void)
1632 ToolkitTestApplication application;
1633 tet_infoline(" utcDaliTextFieldEvent06");
1635 // Checks Longpress when in edit mode
1637 TextField field = TextField::New();
1638 DALI_TEST_CHECK( field );
1639 Stage::GetCurrent().Add( field );
1640 LoadMarkerImages(application, field);
1641 // Render and notify
1642 application.SendNotification();
1643 application.Render();
1645 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1646 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1647 field.SetSize( 300.f, 50.f );
1648 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1649 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1651 // Avoid a crash when core load gl resources.
1652 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1653 // Render and notify
1654 application.SendNotification();
1655 application.Render();
1657 // Create a tap event to touch the text field.
1658 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1659 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1660 // Render and notify
1661 application.SendNotification();
1662 application.Render();
1665 // Tap first to get the focus.
1666 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1667 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1669 // Render and notify
1670 application.SendNotification();
1671 application.Render();
1674 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1675 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1677 // Render and notify
1678 application.SendNotification();
1679 application.Render();
1684 int utcDaliTextFieldEvent07(void)
1686 ToolkitTestApplication application;
1687 tet_infoline(" utcDaliTextFieldEvent07");
1689 // Checks Longpress to start edit mode
1691 TextField field = TextField::New();
1692 DALI_TEST_CHECK( field );
1693 Stage::GetCurrent().Add( field );
1694 LoadMarkerImages(application, field);
1695 // Render and notify
1696 application.SendNotification();
1697 application.Render();
1699 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1700 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1701 field.SetSize( 300.f, 50.f );
1702 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1703 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1705 // Avoid a crash when core load gl resources.
1706 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1707 // Render and notify
1708 application.SendNotification();
1709 application.Render();
1712 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1713 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1715 // Render and notify
1716 application.SendNotification();
1717 application.Render();
1722 int utcDaliTextFieldEvent08(void)
1724 ToolkitTestApplication application;
1725 tet_infoline(" utcDaliTextFieldEvent08");
1727 // Checks Longpress when only place holder text
1729 TextField field = TextField::New();
1730 DALI_TEST_CHECK( field );
1731 Stage::GetCurrent().Add( field );
1732 LoadMarkerImages(application, field);
1733 // Render and notify
1734 application.SendNotification();
1735 application.Render();
1737 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
1738 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1739 field.SetSize( 300.f, 50.f );
1740 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1741 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1743 // Avoid a crash when core load gl resources.
1744 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1745 // Render and notify
1746 application.SendNotification();
1747 application.Render();
1750 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1751 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1753 // Render and notify
1754 application.SendNotification();
1755 application.Render();
1760 int utcDaliTextFieldStyleWhilstSelected(void)
1762 ToolkitTestApplication application;
1763 tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
1765 // Change font and styles whilst text is selected whilst word selected
1767 TextField field = TextField::New();
1768 DALI_TEST_CHECK( field );
1769 Stage::GetCurrent().Add( field );
1770 LoadMarkerImages(application, field);
1771 // Render and notify
1772 application.SendNotification();
1773 application.Render();
1775 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1776 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1777 field.SetSize( 300.f, 50.f );
1778 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1779 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1781 // Avoid a crash when core load gl resources.
1782 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1783 // Render and notify
1784 application.SendNotification();
1785 application.Render();
1787 // Create a tap event to touch the text field.
1788 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1789 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1790 // Render and notify
1791 application.SendNotification();
1792 application.Render();
1795 // Tap first to get the focus.
1796 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1797 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1799 // Render and notify
1800 application.SendNotification();
1801 application.Render();
1803 // Double tap to select a word.
1804 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1805 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1807 // Render and notify
1808 application.SendNotification();
1809 application.Render();
1811 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
1812 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
1814 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1815 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1817 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"width\":\"expanded\",\"slant\":\"italic\"}" );
1818 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"width\":\"expanded\",\"slant\":\"italic\"}", TEST_LOCATION );
1820 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
1821 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1823 field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
1824 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
1826 field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1827 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1829 field.SetProperty( TextField::Property::FONT_STYLE, "{\"width\":\"expanded\"}" );
1830 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"width\":\"expanded\"}", TEST_LOCATION );