2 * Copyright (c) 2017 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>
30 #include "toolkit-clipboard.h"
33 using namespace Toolkit;
35 void dali_textfield_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_textfield_cleanup(void)
42 test_return_value = TET_PASS;
48 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
49 const char* const PROPERTY_NAME_TEXT = "text";
50 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT = "placeholderText";
51 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
52 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
53 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
54 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
55 const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength";
56 const char* const PROPERTY_NAME_EXCEED_POLICY = "exceedPolicy";
57 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
58 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment";
59 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
60 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor";
61 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset";
62 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor";
63 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
64 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
65 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
66 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
67 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
68 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
69 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
70 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
71 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
72 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
73 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
74 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
78 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
79 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
80 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
81 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "inputMethodSettings";
82 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
83 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
84 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
85 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
86 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
88 const char* const PROPERTY_NAME_UNDERLINE = "underline";
89 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
90 const char* const PROPERTY_NAME_SHADOW = "shadow";
91 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
92 const char* const PROPERTY_NAME_EMBOSS = "emboss";
93 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
94 const char* const PROPERTY_NAME_OUTLINE = "outline";
95 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
97 const char* const PROPERTY_NAME_HIDDEN_INPUT_SETTINGS = "hiddenInputSettings";
98 const char* const PROPERTY_NAME_PIXEL_SIZE = "pixelSize";
99 const char* const PROPERTY_NAME_ENABLE_SELECTION = "enableSelection";
100 const char* const PROPERTY_NAME_PLACEHOLDER = "placeholder";
101 const char* const PROPERTY_NAME_ELLIPSIS = "ellipsis";
103 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
105 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
106 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
108 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
109 const float RENDER_FRAME_INTERVAL = 16.66f;
111 const float TO_MILLISECONDS = 1000.f;
112 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
114 const float SCROLL_THRESHOLD = 10.f;
115 const float SCROLL_SPEED = 300.f;
117 const unsigned int DEFAULT_FONT_SIZE = 1152u;
118 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
120 const int KEY_A_CODE = 38;
121 const int KEY_D_CODE = 40;
123 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
125 static bool gTextChangedCallBackCalled;
126 static bool gMaxCharactersCallBackCalled;
127 static bool gInputStyleChangedCallbackCalled;
128 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
130 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
132 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
133 Integration::ResourcePointer resource(bitmap);
134 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
137 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
141 LoadBitmapResource( app.GetPlatform(), width, height );
143 Property::Map propertyMap;
144 propertyMap["filename"] = "image.png";
145 propertyMap["width"] = width;
146 propertyMap["height"] = height;
147 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
148 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
149 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
150 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
151 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
152 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
153 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
154 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
157 // Generate a PanGestureEvent to send to Core
158 static Integration::PanGestureEvent GeneratePan(
159 Gesture::State state,
160 const Vector2& previousPosition,
161 const Vector2& currentPosition,
162 unsigned long timeDelta,
163 unsigned int numberOfTouches = 1)
165 Integration::PanGestureEvent pan(state);
167 pan.previousPosition = previousPosition;
168 pan.currentPosition = currentPosition;
169 pan.timeDelta = timeDelta;
170 pan.numberOfTouches = numberOfTouches;
176 * Helper to generate PanGestureEvent
178 * @param[in] application Application instance
179 * @param[in] state The Gesture State
180 * @param[in] pos The current position of touch.
182 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
186 if( (state == Gesture::Started) ||
187 (state == Gesture::Possible) )
193 application.ProcessEvent(GeneratePan(state, last, pos, 16));
200 * Simulate time passed by.
202 * @note this will always process at least 1 frame (1/60 sec)
204 * @param application Test application instance
205 * @param duration Time to pass in milliseconds.
206 * @return The actual time passed in milliseconds
208 static int Wait(ToolkitTestApplication& application, int duration = 0)
212 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
214 application.SendNotification();
215 application.Render(RENDER_FRAME_INTERVAL);
216 time += RENDER_FRAME_INTERVAL;
222 Dali::Integration::Point GetPointDownInside( Vector2& pos )
224 Dali::Integration::Point point;
225 point.SetState( PointState::DOWN );
226 point.SetScreenPosition( pos );
230 Dali::Integration::Point GetPointUpInside( Vector2& pos )
232 Dali::Integration::Point point;
233 point.SetState( PointState::UP );
234 point.SetScreenPosition( pos );
238 struct CallbackFunctor
240 CallbackFunctor(bool* callbackFlag)
241 : mCallbackFlag( callbackFlag )
247 *mCallbackFlag = true;
252 static void TestTextChangedCallback( TextField control )
254 tet_infoline(" TestTextChangedCallback");
256 gTextChangedCallBackCalled = true;
259 static void TestMaxLengthReachedCallback( TextField control )
261 tet_infoline(" TestMaxLengthReachedCallback");
263 gMaxCharactersCallBackCalled = true;
266 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
268 tet_infoline(" TestInputStyleChangedCallback");
270 gInputStyleChangedCallbackCalled = true;
271 gInputStyleMask = mask;
274 // Generate a TapGestureEvent to send to Core.
275 Integration::TapGestureEvent GenerateTap(
276 Gesture::State state,
277 unsigned int numberOfTaps,
278 unsigned int numberOfTouches,
281 Integration::TapGestureEvent tap( state );
283 tap.numberOfTaps = numberOfTaps;
284 tap.numberOfTouches = numberOfTouches;
290 Integration::LongPressGestureEvent GenerateLongPress(
291 Gesture::State state,
292 unsigned int numberOfTouches,
295 Integration::LongPressGestureEvent longPress( state );
297 longPress.numberOfTouches = numberOfTouches;
298 longPress.point = point;
302 // Generate a KeyEvent to send to Core.
303 Integration::KeyEvent GenerateKey( const std::string& keyName,
304 const std::string& keyString,
307 unsigned long timeStamp,
308 const Integration::KeyEvent::State& keyState,
309 const std::string& deviceName = DEFAULT_DEVICE_NAME,
310 const Device::Class::Type& deviceClass = Device::Class::NONE,
311 const Device::Subclass::Type& deviceSubclass = Device::Subclass::NONE )
313 return Integration::KeyEvent( keyName,
324 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
326 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
328 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
330 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
332 if( valueGet.first.type == Property::Key::STRING )
334 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
335 if( NULL != valueSet )
337 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
339 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
345 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
351 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.indexKey );
352 if( NULL != valueSet )
354 if( valueGet.second.Get<int>() != valueSet->Get<int>() )
356 tet_printf( " Integer Value got : [%d], expected : [%d]", valueGet.second.Get<int>(), valueSet->Get<int>() );
362 tet_printf( " The Int key %d doesn't exist.", valueGet.first.indexKey );
374 int UtcDaliToolkitTextFieldConstructorP(void)
376 ToolkitTestApplication application;
377 tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
379 DALI_TEST_CHECK( !textField );
383 int UtcDaliToolkitTextFieldNewP(void)
385 ToolkitTestApplication application;
386 tet_infoline(" UtcDaliToolkitTextFieldNewP");
387 TextField textField = TextField::New();
388 DALI_TEST_CHECK( textField );
392 int UtcDaliToolkitTextFieldDownCastP(void)
394 ToolkitTestApplication application;
395 tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
396 TextField textField1 = TextField::New();
397 BaseHandle object( textField1 );
399 TextField textField2 = TextField::DownCast( object );
400 DALI_TEST_CHECK( textField2 );
402 TextField textField3 = DownCast< TextField >( object );
403 DALI_TEST_CHECK( textField3 );
407 int UtcDaliToolkitTextFieldDownCastN(void)
409 ToolkitTestApplication application;
410 tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
411 BaseHandle uninitializedObject;
412 TextField textField1 = TextField::DownCast( uninitializedObject );
413 DALI_TEST_CHECK( !textField1 );
415 TextField textField2 = DownCast< TextField >( uninitializedObject );
416 DALI_TEST_CHECK( !textField2 );
420 int UtcDaliToolkitTextFieldCopyConstructorP(void)
422 ToolkitTestApplication application;
423 tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
424 TextField textField = TextField::New();
425 textField.SetProperty( TextField::Property::TEXT, "Test" );
427 TextField copy( textField );
428 DALI_TEST_CHECK( copy );
429 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
433 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
435 ToolkitTestApplication application;
436 tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
437 TextField textField = TextField::New();
438 textField.SetProperty( TextField::Property::TEXT, "Test" );
440 TextField copy = textField;
441 DALI_TEST_CHECK( copy );
442 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
446 int UtcDaliTextFieldNewP(void)
448 ToolkitTestApplication application;
449 tet_infoline(" UtcDaliToolkitTextFieldNewP");
450 TextField textField = TextField::New();
451 DALI_TEST_CHECK( textField );
455 // Positive test case for a method
456 int UtcDaliTextFieldGetPropertyP(void)
458 ToolkitTestApplication application;
459 tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
460 TextField field = TextField::New();
461 DALI_TEST_CHECK( field );
463 // Check Property Indices are correct
464 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND );
465 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
466 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
467 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
468 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
469 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
470 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
471 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
472 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
473 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
474 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
475 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
476 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
477 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextField::Property::SHADOW_OFFSET );
478 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextField::Property::SHADOW_COLOR );
479 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
480 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
481 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
482 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
483 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
484 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
485 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
486 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
487 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
488 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
489 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
490 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
491 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
492 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
493 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
494 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
495 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
496 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
497 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
498 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
499 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
500 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
501 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
502 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
503 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
504 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
505 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
506 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
507 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
508 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
509 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
510 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
511 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HIDDEN_INPUT_SETTINGS ) == TextField::Property::HIDDEN_INPUT_SETTINGS );
512 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == TextField::Property::PIXEL_SIZE );
513 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == TextField::Property::ENABLE_SELECTION );
514 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextField::Property::PLACEHOLDER );
515 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextField::Property::ELLIPSIS );
520 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
523 Property::Map imageMap;
524 imageMap[mapKey] =mapValue;
526 field.SetProperty( property , imageMap );
527 Property::Value propValue = field.GetProperty( property );
528 Property::Map* resultMap = propValue.GetMap();
530 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
538 // Positive test case for a method
539 int UtcDaliTextFieldSetPropertyP(void)
541 ToolkitTestApplication application;
542 tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
543 TextField field = TextField::New();
544 DALI_TEST_CHECK( field );
545 Stage::GetCurrent().Add( field );
547 // Note - we can't check the defaults since the stylesheets are platform-specific
549 // Check the render backend property.
550 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
551 DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty<int>( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
553 // Check text property.
554 field.SetProperty( TextField::Property::TEXT, "Setting Text" );
555 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
557 // Check placeholder text properties.
558 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
559 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
561 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
562 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
564 // Check font properties.
565 field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
566 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
568 Property::Map fontStyleMapSet;
569 Property::Map fontStyleMapGet;
570 Property::Value* slantValue = NULL;
572 fontStyleMapSet.Insert( "weight", "bold" );
573 fontStyleMapSet.Insert( "width", "condensed" );
574 fontStyleMapSet.Insert( "slant", "italic" );
575 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
577 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
578 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
579 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
581 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
582 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
585 fontStyleMapSet.Clear();
586 fontStyleMapSet.Insert( "weight", "normal" );
587 fontStyleMapSet.Insert( "slant", "oblique" );
588 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
590 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
591 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
592 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
594 fontStyleMapSet.Clear();
595 fontStyleMapSet.Insert( "slant", "roman" );
596 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
597 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
599 // Replace 'roman' for 'normal'.
600 slantValue = fontStyleMapGet.Find( "slant" );
601 if( NULL != slantValue )
603 if( "normal" == slantValue->Get<std::string>() )
605 fontStyleMapGet["slant"] = "roman";
608 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
609 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
611 fontStyleMapSet.Clear();
613 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
614 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
615 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
616 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
618 // Check that the MAX_LENGTH property can be correctly set
619 const int maxNumberOfCharacters = 20;
620 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
621 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
623 // Check exceed policy
624 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP );
625 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION );
626 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
627 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
629 // Check that the Alignment properties can be correctly set
630 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
631 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
632 field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
633 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
635 // Check text's color property
636 field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
637 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
639 // Check placeholder text's color property.
640 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
641 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
643 // Check shadow properties.
644 field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
645 DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
646 field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
647 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
649 // Check cursor properties
650 field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
651 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
652 field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
653 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
655 field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
656 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
657 field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
658 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
659 field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
660 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
661 field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
662 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
664 // Check scroll properties.
665 field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
666 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
667 field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
668 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
670 // Check handle images
671 field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
672 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
673 field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
674 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
675 field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
677 // Check handle images
678 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
679 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
680 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
681 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
682 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
683 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
685 // Check the highlight color
686 field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
687 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
689 // Decoration bounding box
690 field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
691 DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
693 // Check the input method setting
694 Property::Map propertyMap;
695 InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
696 InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
697 InputMethod::ActionButtonTitle::Type actionButton = InputMethod::ActionButtonTitle::GO;
698 int inputVariation = 1;
699 propertyMap["PANEL_LAYOUT"] = panelLayout;
700 propertyMap["AUTO_CAPITALISE"] = autoCapital;
701 propertyMap["ACTION_BUTTON"] = actionButton;
702 propertyMap["VARIATION"] = inputVariation;
703 field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
705 Property::Value value = field.GetProperty( TextField::Property::INPUT_METHOD_SETTINGS );
707 DALI_TEST_CHECK( value.Get( map ) );
710 DALI_TEST_CHECK( map[ "PANEL_LAYOUT" ].Get( layout ) );
711 DALI_TEST_EQUALS( static_cast<int>(panelLayout), layout, TEST_LOCATION );
714 DALI_TEST_CHECK( map[ "AUTO_CAPITALISE" ].Get( capital ) );
715 DALI_TEST_EQUALS( static_cast<int>(autoCapital), capital, TEST_LOCATION );
718 DALI_TEST_CHECK( map[ "ACTION_BUTTON" ].Get( action ) );
719 DALI_TEST_EQUALS( static_cast<int>(actionButton), action, TEST_LOCATION );
722 DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) );
723 DALI_TEST_EQUALS( inputVariation, variation, TEST_LOCATION );
725 // Check input color property.
726 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
727 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
729 // Check the enable markup property.
730 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
731 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
732 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
734 // Check input font properties.
735 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
736 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
738 fontStyleMapSet.Clear();
739 fontStyleMapSet.Insert( "weight", "bold" );
740 fontStyleMapSet.Insert( "width", "condensed" );
741 fontStyleMapSet.Insert( "slant", "italic" );
743 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
744 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
745 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
746 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
748 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
749 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
751 // Reset input font style.
752 fontStyleMapSet.Clear();
753 fontStyleMapSet.Insert( "weight", "normal" );
754 fontStyleMapSet.Insert( "slant", "oblique" );
756 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
757 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
758 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
759 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
761 fontStyleMapSet.Clear();
762 fontStyleMapSet.Insert( "slant", "roman" );
764 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
765 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
767 // Replace 'roman' for 'normal'.
768 slantValue = fontStyleMapGet.Find( "slant" );
769 if( NULL != slantValue )
771 if( "normal" == slantValue->Get<std::string>() )
773 fontStyleMapGet["slant"] = "roman";
776 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
777 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
779 fontStyleMapSet.Clear();
781 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
782 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
783 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
784 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
786 Property::Map underlineMapSet;
787 Property::Map underlineMapGet;
789 underlineMapSet.Insert( "enable", "true" );
790 underlineMapSet.Insert( "color", "red" );
791 underlineMapSet.Insert( "height", "1" );
793 // Check the underline property
794 field.SetProperty( TextField::Property::UNDERLINE, underlineMapSet );
796 underlineMapGet = field.GetProperty<Property::Map>( TextField::Property::UNDERLINE );
797 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
798 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
800 // Check the input underline property
801 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
802 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
804 // Check the shadow property
805 Property::Map shadowMapSet;
806 Property::Map shadowMapGet;
808 shadowMapSet.Insert( "color", Color::GREEN );
809 shadowMapSet.Insert( "offset", Vector2(2.0f, 2.0f) );
810 shadowMapSet.Insert( "blurRadius", 3.0f );
812 field.SetProperty( TextField::Property::SHADOW, shadowMapSet );
814 shadowMapGet = field.GetProperty<Property::Map>( TextField::Property::SHADOW );
815 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
816 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
818 // Check the input shadow property
819 field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
820 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
822 // Check the emboss property
823 field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
824 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
826 // Check the input emboss property
827 field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
828 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
830 // Check the outline property
832 // Test string type first
833 // This is purely to maintain backward compatibility, but we don't support string as the outline property type.
834 field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
835 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
837 // Then test the property map type
838 Property::Map outlineMapSet;
839 Property::Map outlineMapGet;
841 outlineMapSet["color"] = Color::RED;
842 outlineMapSet["width"] = 2.0f;
844 field.SetProperty( TextField::Property::OUTLINE, outlineMapSet );
846 outlineMapSet["color"] = "red";
847 outlineMapSet["width"] = "2";
848 outlineMapGet = field.GetProperty<Property::Map>( TextField::Property::OUTLINE );
849 DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION );
850 DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION );
852 // Check the input outline property
853 field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
854 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
856 // Check the hidden input settings property
857 Property::Map hiddenMapSet;
858 Property::Map hiddenMapGet;
859 hiddenMapSet[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
860 hiddenMapSet[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 2;
861 hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 4;
862 hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
863 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, hiddenMapSet );
865 hiddenMapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
866 DALI_TEST_EQUALS( hiddenMapSet.Count(), hiddenMapGet.Count(), TEST_LOCATION );
867 DALI_TEST_EQUALS( DaliTestCheckMaps( hiddenMapSet, hiddenMapGet ), true, TEST_LOCATION );
869 // Check the pixel size of font
870 field.SetProperty( TextField::Property::PIXEL_SIZE, 20.f );
871 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
873 // Check the enable selection property
874 field.SetProperty( TextField::Property::ENABLE_SELECTION, false );
875 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_SELECTION ), false, TEST_LOCATION );
877 // Check the placeholder property with pixel size
878 Property::Map placeholderPixelSizeMapSet;
879 Property::Map placeholderPixelSizeMapGet;
880 Property::Map placeholderFontstyleMap;
881 placeholderPixelSizeMapSet["text"] = "Setting Placeholder Text";
882 placeholderPixelSizeMapSet["textFocused"] = "Setting Placeholder Text Focused";
883 placeholderPixelSizeMapSet["color"] = Color::BLUE;
884 placeholderPixelSizeMapSet["fontFamily"] = "Arial";
885 placeholderPixelSizeMapSet["pixelSize"] = 15.0f;
886 placeholderPixelSizeMapSet["ellipsis"] = true;
888 placeholderFontstyleMap.Insert( "weight", "bold" );
889 placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap;
890 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
892 placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
893 DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
895 tet_infoline("Test Placeholder settings set as strings is converted correctly to Property Index key and holds set value");
896 Property::Map placeholderConversionMap;
897 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
898 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
899 placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
900 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
901 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
902 placeholderConversionMap[ Text::PlaceHolder::Property::PIXEL_SIZE ] = placeholderPixelSizeMapSet["pixelSize"];
904 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderConversionMap ), true, TEST_LOCATION );
906 // Check the placeholder property with point size
907 Property::Map placeholderMapSet;
908 Property::Map placeholderMapGet;
909 placeholderMapSet["text"] = "Setting Placeholder Text";
910 placeholderMapSet["textFocused"] = "Setting Placeholder Text Focused";
911 placeholderMapSet["color"] = Color::RED;
912 placeholderMapSet["fontFamily"] = "Arial";
913 placeholderMapSet["pointSize"] = 12.0f;
914 placeholderMapSet["ellipsis"] = false;
916 // Check the placeholder font style property
917 placeholderFontstyleMap.Clear();
919 placeholderFontstyleMap.Insert( "weight", "bold" );
920 placeholderFontstyleMap.Insert( "width", "condensed" );
921 placeholderFontstyleMap.Insert( "slant", "italic" );
922 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
923 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
925 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
926 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
928 placeholderConversionMap.Clear();
929 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
930 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
931 placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
932 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
933 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
934 placeholderConversionMap[ Text::PlaceHolder::Property::POINT_SIZE ] = placeholderPixelSizeMapSet["pointSize"];
936 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
939 placeholderFontstyleMap.Clear();
940 placeholderFontstyleMap.Insert( "weight", "normal" );
941 placeholderFontstyleMap.Insert( "slant", "oblique" );
942 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
943 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
945 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
946 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
948 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
949 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
951 placeholderFontstyleMap.Clear();
952 placeholderFontstyleMap.Insert( "slant", "roman" );
953 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
954 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
956 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
958 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
960 placeholderFontstyleMap.Clear();
961 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
962 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
964 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
965 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
966 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
968 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
970 // Check the ellipsis property
971 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
972 field.SetProperty( TextField::Property::ELLIPSIS, true );
973 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
975 field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
976 DALI_TEST_EQUALS( field.GetProperty<int>( Actor::Property::LAYOUT_DIRECTION ), static_cast<int>( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
978 application.SendNotification();
979 application.Render();
984 // Positive Atlas Text Renderer test
985 int utcDaliTextFieldAtlasRenderP(void)
987 ToolkitTestApplication application;
988 tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
989 StyleManager styleManager = StyleManager::Get();
990 styleManager.ApplyDefaultTheme();
991 TextField field = TextField::New();
992 DALI_TEST_CHECK( field );
994 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
996 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
998 Stage::GetCurrent().Add( field );
1002 // Render some text with the shared atlas backend
1003 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
1004 application.SendNotification();
1005 application.Render();
1009 tet_result(TET_FAIL);
1014 // Positive test for the textChanged signal.
1015 int utcDaliTextFieldTextChangedP(void)
1017 ToolkitTestApplication application;
1018 tet_infoline(" utcDaliTextFieldTextChangedP");
1019 TextField field = TextField::New();
1020 DALI_TEST_CHECK( field );
1022 Stage::GetCurrent().Add( field );
1024 // connect to the text changed signal.
1025 ConnectionTracker* testTracker = new ConnectionTracker();
1026 field.TextChangedSignal().Connect(&TestTextChangedCallback);
1027 bool textChangedSignal = false;
1028 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
1030 gTextChangedCallBackCalled = false;
1031 field.SetProperty( TextField::Property::TEXT, "ABC" );
1032 DALI_TEST_CHECK( gTextChangedCallBackCalled );
1033 DALI_TEST_CHECK( textChangedSignal );
1035 application.SendNotification();
1037 field.SetKeyInputFocus();
1039 gTextChangedCallBackCalled = false;
1040 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1041 DALI_TEST_CHECK( gTextChangedCallBackCalled );
1046 // Negative test for the textChanged signal.
1047 int utcDaliTextFieldTextChangedN(void)
1049 ToolkitTestApplication application;
1050 tet_infoline(" utcDaliTextFieldTextChangedN");
1051 TextField field = TextField::New();
1052 DALI_TEST_CHECK( field );
1054 Stage::GetCurrent().Add( field );
1056 // connect to the text changed signal.
1057 ConnectionTracker* testTracker = new ConnectionTracker();
1058 field.TextChangedSignal().Connect(&TestTextChangedCallback);
1059 bool textChangedSignal = false;
1060 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
1062 gTextChangedCallBackCalled = false;
1063 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
1064 DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1065 DALI_TEST_CHECK( !textChangedSignal );
1070 // Positive test for Max Characters reached signal.
1071 int utcDaliTextFieldMaxCharactersReachedP(void)
1073 ToolkitTestApplication application;
1074 tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
1075 TextField field = TextField::New();
1076 DALI_TEST_CHECK( field );
1078 Stage::GetCurrent().Add( field );
1080 const int maxNumberOfCharacters = 1;
1081 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1083 field.SetKeyInputFocus();
1085 // connect to the text changed signal.
1086 ConnectionTracker* testTracker = new ConnectionTracker();
1087 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1088 bool maxLengthReachedSignal = false;
1089 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
1091 gMaxCharactersCallBackCalled = false;
1093 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1094 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1096 DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
1097 DALI_TEST_CHECK( maxLengthReachedSignal );
1102 // Negative test for Max Characters reached signal.
1103 int utcDaliTextFieldMaxCharactersReachedN(void)
1105 ToolkitTestApplication application;
1106 tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
1107 TextField field = TextField::New();
1108 DALI_TEST_CHECK( field );
1110 Stage::GetCurrent().Add( field );
1112 const int maxNumberOfCharacters = 3;
1113 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1115 field.SetKeyInputFocus();
1117 // connect to the text changed signal.
1118 ConnectionTracker* testTracker = new ConnectionTracker();
1119 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1120 bool maxLengthReachedSignal = false;
1121 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
1123 gMaxCharactersCallBackCalled = false;
1125 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1126 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1128 DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1129 DALI_TEST_CHECK( !maxLengthReachedSignal );
1134 int utcDaliTextFieldInputStyleChanged01(void)
1136 ToolkitTestApplication application;
1137 tet_infoline(" utcDaliTextFieldInputStyleChanged01");
1139 // The text-field emits signals when the input style changes. These changes of style are
1140 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1141 // can't be emitted during the size negotiation as the callbacks may update the UI.
1142 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1143 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1144 application.CreateAdaptor();
1148 char* pathNamePtr = get_current_dir_name();
1149 const std::string pathName( pathNamePtr );
1150 free( pathNamePtr );
1152 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1153 fontClient.SetDpi( 93u, 93u );
1155 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1156 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1158 TextField field = TextField::New();
1159 DALI_TEST_CHECK( field );
1162 field.SetSize( 300.f, 50.f );
1163 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1164 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1166 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1167 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
1169 // connect to the text changed signal.
1170 ConnectionTracker* testTracker = new ConnectionTracker();
1171 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1172 bool inputStyleChangedSignal = false;
1173 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1175 Stage::GetCurrent().Add( field );
1177 // Render and notify
1178 application.SendNotification();
1179 application.Render();
1181 // Executes the idle callbacks added by the text control on the change of input style.
1182 application.RunIdles();
1184 gInputStyleChangedCallbackCalled = false;
1185 gInputStyleMask = TextField::InputStyle::NONE;
1186 inputStyleChangedSignal = false;
1188 // Create a tap event to touch the text field.
1189 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1190 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1192 // Render and notify
1193 application.SendNotification();
1194 application.Render();
1196 // Executes the idle callbacks added by the text control on the change of input style.
1197 application.RunIdles();
1199 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1200 if( gInputStyleChangedCallbackCalled )
1202 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
1204 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1205 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1207 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1208 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1210 DALI_TEST_CHECK( inputStyleChangedSignal );
1212 gInputStyleChangedCallbackCalled = false;
1213 gInputStyleMask = TextField::InputStyle::NONE;
1214 inputStyleChangedSignal = false;
1216 // Create a tap event to touch the text field.
1217 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1218 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1220 // Render and notify
1221 application.SendNotification();
1222 application.Render();
1224 // Executes the idle callbacks added by the text control on the change of input style.
1225 application.RunIdles();
1227 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1228 DALI_TEST_CHECK( !inputStyleChangedSignal );
1230 gInputStyleChangedCallbackCalled = false;
1231 gInputStyleMask = TextField::InputStyle::NONE;
1232 inputStyleChangedSignal = false;
1234 // Create a tap event to touch the text field.
1235 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1236 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1238 // Render and notify
1239 application.SendNotification();
1240 application.Render();
1242 // Executes the idle callbacks added by the text control on the change of input style.
1243 application.RunIdles();
1245 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1246 if( gInputStyleChangedCallbackCalled )
1248 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1250 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1251 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1253 DALI_TEST_CHECK( inputStyleChangedSignal );
1255 gInputStyleChangedCallbackCalled = false;
1256 gInputStyleMask = TextField::InputStyle::NONE;
1257 inputStyleChangedSignal = false;
1259 // Create a tap event to touch the text field.
1260 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1261 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1263 // Render and notify
1264 application.SendNotification();
1265 application.Render();
1267 // Executes the idle callbacks added by the text control on the change of input style.
1268 application.RunIdles();
1270 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1271 if( gInputStyleChangedCallbackCalled )
1273 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1275 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1276 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1278 const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1280 Property::Map fontStyleMapSet;
1281 fontStyleMapSet.Insert( "weight", "bold" );
1283 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1284 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1286 DALI_TEST_CHECK( inputStyleChangedSignal );
1288 gInputStyleChangedCallbackCalled = false;
1289 gInputStyleMask = TextField::InputStyle::NONE;
1290 inputStyleChangedSignal = false;
1292 // Create a tap event to touch the text field.
1293 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1294 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1296 // Render and notify
1297 application.SendNotification();
1298 application.Render();
1300 // Executes the idle callbacks added by the text control on the change of input style.
1301 application.RunIdles();
1303 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1304 DALI_TEST_CHECK( !inputStyleChangedSignal );
1306 gInputStyleChangedCallbackCalled = false;
1307 gInputStyleMask = TextField::InputStyle::NONE;
1308 inputStyleChangedSignal = false;
1310 // Create a tap event to touch the text field.
1311 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1312 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1314 // Render and notify
1315 application.SendNotification();
1316 application.Render();
1318 // Executes the idle callbacks added by the text control on the change of input style.
1319 application.RunIdles();
1321 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1322 if( gInputStyleChangedCallbackCalled )
1324 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1326 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1327 DALI_TEST_CHECK( style.empty() );
1329 DALI_TEST_CHECK( inputStyleChangedSignal );
1331 gInputStyleChangedCallbackCalled = false;
1332 gInputStyleMask = TextField::InputStyle::NONE;
1333 inputStyleChangedSignal = false;
1335 // Create a tap event to touch the text field.
1336 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1337 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1339 // Render and notify
1340 application.SendNotification();
1341 application.Render();
1343 // Executes the idle callbacks added by the text control on the change of input style.
1344 application.RunIdles();
1346 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1347 DALI_TEST_CHECK( !inputStyleChangedSignal );
1352 int utcDaliTextFieldInputStyleChanged02(void)
1354 ToolkitTestApplication application;
1355 tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1357 // The text-field emits signals when the input style changes. These changes of style are
1358 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1359 // can't be emitted during the size negotiation as the callbacks may update the UI.
1360 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1361 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1362 application.CreateAdaptor();
1366 char* pathNamePtr = get_current_dir_name();
1367 const std::string pathName( pathNamePtr );
1368 free( pathNamePtr );
1370 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1371 fontClient.SetDpi( 93u, 93u );
1373 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1374 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1376 TextField field = TextField::New();
1377 DALI_TEST_CHECK( field );
1380 field.SetSize( 300.f, 50.f );
1381 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1382 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1384 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1385 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>" );
1387 // connect to the text changed signal.
1388 ConnectionTracker* testTracker = new ConnectionTracker();
1389 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1390 bool inputStyleChangedSignal = false;
1391 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1393 Stage::GetCurrent().Add( field );
1395 // Render and notify
1396 application.SendNotification();
1397 application.Render();
1399 // Executes the idle callbacks added by the text control on the change of input style.
1400 application.RunIdles();
1402 gInputStyleChangedCallbackCalled = false;
1403 gInputStyleMask = TextField::InputStyle::NONE;
1404 inputStyleChangedSignal = false;
1406 // Create a tap event to touch the text field.
1407 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1408 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1409 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1410 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1412 // Render and notify
1413 application.SendNotification();
1414 application.Render();
1416 // Executes the idle callbacks added by the text control on the change of input style.
1417 application.RunIdles();
1419 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1420 if( gInputStyleChangedCallbackCalled )
1422 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1423 static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1424 TextField::InputStyle::POINT_SIZE |
1425 TextField::InputStyle::COLOR ),
1428 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1429 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1431 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1432 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1434 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1435 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1437 DALI_TEST_CHECK( inputStyleChangedSignal );
1439 gInputStyleChangedCallbackCalled = false;
1440 gInputStyleMask = TextField::InputStyle::NONE;
1441 inputStyleChangedSignal = false;
1443 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1445 // Render and notify
1446 application.SendNotification();
1447 application.Render();
1449 // Executes the idle callbacks added by the text control on the change of input style.
1450 application.RunIdles();
1452 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1453 if( gInputStyleChangedCallbackCalled )
1455 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1456 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1459 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1460 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1462 DALI_TEST_CHECK( inputStyleChangedSignal );
1464 gInputStyleChangedCallbackCalled = false;
1465 gInputStyleMask = TextField::InputStyle::NONE;
1466 inputStyleChangedSignal = false;
1468 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1470 // Render and notify
1471 application.SendNotification();
1472 application.Render();
1474 // Executes the idle callbacks added by the text control on the change of input style.
1475 application.RunIdles();
1477 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1478 DALI_TEST_CHECK( !inputStyleChangedSignal );
1480 gInputStyleChangedCallbackCalled = false;
1481 gInputStyleMask = TextField::InputStyle::NONE;
1482 inputStyleChangedSignal = false;
1484 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1486 // Render and notify
1487 application.SendNotification();
1488 application.Render();
1490 // Executes the idle callbacks added by the text control on the change of input style.
1491 application.RunIdles();
1493 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1494 if( gInputStyleChangedCallbackCalled )
1496 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1497 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1500 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1501 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1503 DALI_TEST_CHECK( inputStyleChangedSignal );
1505 gInputStyleChangedCallbackCalled = false;
1506 gInputStyleMask = TextField::InputStyle::NONE;
1507 inputStyleChangedSignal = false;
1509 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1511 Property::Map fontStyleMapSet;
1512 fontStyleMapSet.Insert( "weight", "thin" );
1513 fontStyleMapSet.Insert( "width", "condensed" );
1514 fontStyleMapSet.Insert( "slant", "italic" );
1516 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1517 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1519 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1520 field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1521 field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1522 field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1524 // Render and notify
1525 application.SendNotification();
1526 application.Render();
1528 // Executes the idle callbacks added by the text control on the change of input style.
1529 application.RunIdles();
1531 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1532 DALI_TEST_CHECK( !inputStyleChangedSignal );
1534 // Create a tap event to touch the text field.
1535 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1536 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1538 // Render and notify
1539 application.SendNotification();
1540 application.Render();
1542 // Executes the idle callbacks added by the text control on the change of input style.
1543 application.RunIdles();
1545 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1546 if( gInputStyleChangedCallbackCalled )
1548 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1549 static_cast<unsigned int>( TextField::InputStyle::COLOR |
1550 TextField::InputStyle::POINT_SIZE |
1551 TextField::InputStyle::FONT_STYLE |
1552 TextField::InputStyle::UNDERLINE |
1553 TextField::InputStyle::SHADOW |
1554 TextField::InputStyle::EMBOSS |
1555 TextField::InputStyle::OUTLINE ),
1558 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1559 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1561 DALI_TEST_CHECK( inputStyleChangedSignal );
1566 int utcDaliTextFieldEvent01(void)
1568 ToolkitTestApplication application;
1569 tet_infoline(" utcDaliTextFieldEvent01");
1571 // Creates a tap event. After creating a tap event the text field should
1572 // have the focus and add text with key events should be possible.
1574 TextField field = TextField::New();
1575 DALI_TEST_CHECK( field );
1577 Stage::GetCurrent().Add( field );
1579 field.SetSize( 300.f, 50.f );
1580 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1581 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1583 // Avoid a crash when core load gl resources.
1584 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1586 // Render and notify
1587 application.SendNotification();
1588 application.Render();
1590 // Add a key event but as the text field has not the focus it should do nothing.
1591 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1593 // Render and notify
1594 application.SendNotification();
1595 application.Render();
1597 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1599 // Create a tap event to touch the text field.
1600 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1601 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1603 // Render and notify
1604 application.SendNotification();
1605 application.Render();
1607 // Now the text field has the focus, so it can handle the key events.
1608 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1609 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1611 // Render and notify
1612 application.SendNotification();
1613 application.Render();
1615 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1617 // Create a second text field and send key events to it.
1618 TextField field2 = TextField::New();
1620 field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1621 field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1622 field2.SetSize( 100.f, 100.f );
1623 field2.SetPosition( 100.f, 100.f );
1625 Stage::GetCurrent().Add( field2 );
1627 // Render and notify
1628 application.SendNotification();
1629 application.Render();
1631 // Create a tap event on the second text field.
1632 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1633 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1635 // Render and notify
1636 application.SendNotification();
1637 application.Render();
1639 // The second text field has the focus. It should handle the key events.
1640 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1641 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1643 // Render and notify
1644 application.SendNotification();
1645 application.Render();
1647 // Check the text has been added to the second text field.
1648 DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1653 int utcDaliTextFieldEvent02(void)
1655 ToolkitTestApplication application;
1656 tet_infoline(" utcDaliTextFieldEvent02");
1658 // Checks if the right number of actors are created.
1660 TextField field = TextField::New();
1661 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1662 DALI_TEST_CHECK( field );
1663 LoadMarkerImages(application, field);
1665 Stage::GetCurrent().Add( field );
1667 field.SetSize( 300.f, 50.f );
1668 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1669 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1671 // Avoid a crash when core load gl resources.
1672 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1674 // Render and notify
1675 application.SendNotification();
1676 application.Render();
1678 // Check there are the expected number of children ( stencil ).
1679 DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1681 Actor stencil = field.GetChildAt( 0u );
1682 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1684 // Create a tap event to touch the text field.
1685 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1686 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1688 // Render and notify
1689 application.SendNotification();
1690 application.Render();
1692 Actor layer = field.GetChildAt( 1u );
1693 DALI_TEST_CHECK( layer.IsLayer() );
1695 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1696 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1698 // Now the text field has the focus, so it can handle the key events.
1699 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1700 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1702 // Render and notify
1703 application.SendNotification();
1704 application.Render();
1706 // Checks the cursor and the renderer have been created.
1707 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1708 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1710 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1711 DALI_TEST_CHECK( cursor );
1713 // The offscreen root actor has a container with all the actors which contain the text renderers.
1714 Actor container = stencil.GetChildAt( 0u );
1715 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1717 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1718 DALI_TEST_CHECK( renderer );
1721 // Move the cursor and check the position changes.
1722 Vector3 position1 = cursor.GetCurrentPosition();
1724 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1725 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1727 // Render and notify
1728 application.SendNotification();
1729 application.Render();
1731 Vector3 position2 = cursor.GetCurrentPosition();
1733 DALI_TEST_CHECK( position2.x < position1.x );
1735 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1736 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1738 // Render and notify
1739 application.SendNotification();
1740 application.Render();
1742 Vector3 position3 = cursor.GetCurrentPosition();
1744 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1746 // Send some taps and check the cursor positions.
1748 // Try to tap at the beginning.
1749 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1750 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1752 // Render and notify
1753 application.SendNotification();
1754 application.Render();
1756 // Cursor position should be the same than position1.
1757 Vector3 position4 = cursor.GetCurrentPosition();
1759 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1761 // Tap away from the start position.
1762 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1763 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1765 // Render and notify
1766 application.SendNotification();
1767 application.Render();
1769 Vector3 position5 = cursor.GetCurrentPosition();
1771 DALI_TEST_CHECK( position5.x > position4.x );
1773 // Remove all the text.
1774 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1775 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1776 field.SetProperty( TextField::Property::TEXT, "" );
1778 // Render and notify
1779 application.SendNotification();
1780 application.Render();
1782 // Cursor position should be the same than position2.
1783 Vector3 position6 = cursor.GetCurrentPosition();
1785 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1787 // Should not be a renderer.
1788 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1790 // Chanege exceed policy (EXCEED_POLICY_ORIGINAL doesn't use stencil )
1791 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1792 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
1794 application.SendNotification();
1795 application.Render();
1797 // There are renderer and decorator layer
1798 DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
1803 int utcDaliTextFieldEvent03(void)
1805 ToolkitTestApplication application;
1806 tet_infoline(" utcDaliTextFieldEvent03");
1808 // Checks if the highlight actor is created.
1810 TextField field = TextField::New();
1811 DALI_TEST_CHECK( field );
1813 Stage::GetCurrent().Add( field );
1815 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1816 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1817 field.SetSize( 30.f, 50.f );
1818 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1819 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1821 // Avoid a crash when core load gl resources.
1822 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1823 LoadMarkerImages(application, field);
1825 // Render and notify
1826 application.SendNotification();
1827 application.Render();
1829 // Tap first to get the focus.
1830 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1831 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1833 // Render and notify
1834 application.SendNotification();
1835 application.Render();
1837 // Double tap to select a word.
1838 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1839 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1841 // Render and notify
1842 application.SendNotification();
1843 application.Render();
1845 // The offscreen root actor should have two actors: the renderer and the highlight actor.
1846 Actor stencil = field.GetChildAt( 0u );
1848 // The highlight actor is drawn first, so is the first actor in the list
1849 Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
1850 DALI_TEST_CHECK( highlight );
1852 // The offscreen root actor has a container with all the actors which contain the text renderers.
1853 Actor container = stencil.GetChildAt( 1u );
1854 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1856 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1857 DALI_TEST_CHECK( renderer );
1863 int utcDaliTextFieldEvent04(void)
1865 ToolkitTestApplication application;
1866 tet_infoline(" utcDaliTextFieldEvent04");
1868 // Checks if the highlight actor is created.
1870 TextField field = TextField::New();
1871 DALI_TEST_CHECK( field );
1872 Stage::GetCurrent().Add( field );
1873 LoadMarkerImages(application, field);
1874 // Render and notify
1875 application.SendNotification();
1876 application.Render();
1878 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1879 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1880 field.SetSize( 300.f, 50.f );
1881 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1882 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1884 // Avoid a crash when core load gl resources.
1885 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1886 // Render and notify
1887 application.SendNotification();
1888 application.Render();
1890 // Create a tap event to touch the text field.
1891 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1892 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1893 // Render and notify
1894 application.SendNotification();
1895 application.Render();
1898 // Tap first to get the focus.
1899 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1900 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1902 // Render and notify
1903 application.SendNotification();
1904 application.Render();
1906 // Double tap to select a word.
1907 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1908 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1910 // Render and notify
1911 application.SendNotification();
1912 application.Render();
1915 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1916 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1920 int utcDaliTextFieldEvent05(void)
1922 ToolkitTestApplication application;
1923 tet_infoline(" utcDaliTextFieldEvent05");
1925 // Checks dragging of cursor/grab handle
1927 TextField field = TextField::New();
1928 DALI_TEST_CHECK( field );
1929 Stage::GetCurrent().Add( field );
1930 LoadMarkerImages(application, field);
1931 // Render and notify
1932 application.SendNotification();
1933 application.Render();
1935 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1936 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1937 field.SetSize( 300.f, 50.f );
1938 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1939 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1941 // Avoid a crash when core load gl resources.
1942 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1943 // Render and notify
1944 application.SendNotification();
1945 application.Render();
1947 // Create a tap event to touch the text field.
1948 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1949 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1950 // Render and notify
1951 application.SendNotification();
1952 application.Render();
1955 // Tap first to get the focus.
1956 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1957 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1959 // Render and notify
1960 application.SendNotification();
1961 application.Render();
1963 // Double tap to select a word.
1964 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1965 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1967 // Render and notify
1968 application.SendNotification();
1969 application.Render();
1971 // drag grab handle right
1972 Vector2 pos(0.0f, 40.0f);
1973 SendPan(application, Gesture::Possible, pos);
1974 SendPan(application, Gesture::Started, pos);
1976 Wait(application, 100);
1978 for(int i = 0;i<20;i++)
1980 SendPan(application, Gesture::Continuing, pos);
1985 SendPan(application, Gesture::Finished, pos);
1986 Wait(application, RENDER_FRAME_INTERVAL);
1988 Actor stencil = field.GetChildAt( 1u );
1992 int utcDaliTextFieldEvent06(void)
1994 ToolkitTestApplication application;
1995 tet_infoline(" utcDaliTextFieldEvent06");
1997 // Checks Longpress when in edit mode
1999 TextField field = TextField::New();
2000 DALI_TEST_CHECK( field );
2001 Stage::GetCurrent().Add( field );
2002 LoadMarkerImages(application, field);
2003 // Render and notify
2004 application.SendNotification();
2005 application.Render();
2007 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
2008 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2009 field.SetSize( 300.f, 50.f );
2010 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2011 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2013 // Avoid a crash when core load gl resources.
2014 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2015 // Render and notify
2016 application.SendNotification();
2017 application.Render();
2019 // Create a tap event to touch the text field.
2020 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2021 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2022 // Render and notify
2023 application.SendNotification();
2024 application.Render();
2027 // Tap first to get the focus.
2028 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2029 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2031 // Render and notify
2032 application.SendNotification();
2033 application.Render();
2036 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2037 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2039 // Render and notify
2040 application.SendNotification();
2041 application.Render();
2046 int utcDaliTextFieldEvent07(void)
2048 ToolkitTestApplication application;
2049 tet_infoline(" utcDaliTextFieldEvent07");
2051 // Checks Longpress to start edit mode
2053 TextField field = TextField::New();
2054 DALI_TEST_CHECK( field );
2055 Stage::GetCurrent().Add( field );
2056 LoadMarkerImages(application, field);
2057 // Render and notify
2058 application.SendNotification();
2059 application.Render();
2061 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
2062 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2063 field.SetSize( 300.f, 50.f );
2064 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2065 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2066 Property::Map propertyMap;
2067 propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD;
2068 field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
2070 // Avoid a crash when core load gl resources.
2071 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2072 // Render and notify
2073 application.SendNotification();
2074 application.Render();
2077 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2078 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2080 // Render and notify
2081 application.SendNotification();
2082 application.Render();
2087 int utcDaliTextFieldEvent08(void)
2089 ToolkitTestApplication application;
2090 tet_infoline(" utcDaliTextFieldEvent08");
2092 Dali::Clipboard clipboard = Clipboard::Get();
2093 clipboard.SetItem("testTextFieldEvent");
2095 // Checks Longpress when only place holder text
2097 TextField field = TextField::New();
2098 DALI_TEST_CHECK( field );
2099 Stage::GetCurrent().Add( field );
2100 LoadMarkerImages(application, field);
2101 // Render and notify
2102 application.SendNotification();
2103 application.Render();
2105 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
2106 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2107 field.SetSize( 300.f, 50.f );
2108 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2109 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2111 // Avoid a crash when core load gl resources.
2112 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2113 // Render and notify
2114 application.SendNotification();
2115 application.Render();
2118 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2119 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2121 // Render and notify
2122 application.SendNotification();
2123 application.Render();
2125 Wait(application, 500);
2128 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2129 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2131 // Render and notify
2132 application.SendNotification();
2133 application.Render();
2135 Wait(application, 500);
2137 Stage stage = Stage::GetCurrent();
2138 Layer layer = stage.GetRootLayer();
2139 Actor actor = layer.FindChildByName("optionPaste");
2143 Vector3 worldPosition = actor.GetCurrentWorldPosition();
2144 Vector2 halfStageSize = stage.GetSize() / 2.0f;
2145 Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
2147 Dali::Integration::TouchEvent event;
2148 event = Dali::Integration::TouchEvent();
2149 event.AddPoint( GetPointDownInside( position ) );
2150 application.ProcessEvent( event );
2152 event = Dali::Integration::TouchEvent();
2153 event.AddPoint( GetPointUpInside( position ) );
2154 application.ProcessEvent( event );
2156 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
2161 int utcDaliTextFieldEvent09(void)
2163 ToolkitTestApplication application;
2164 tet_infoline(" utcDaliTextFieldEvent09");
2166 TextField field = TextField::New();
2167 DALI_TEST_CHECK( field );
2168 Stage::GetCurrent().Add( field );
2169 LoadMarkerImages(application, field);
2170 // Render and notify
2171 application.SendNotification();
2172 application.Render();
2174 field.SetProperty( TextField::Property::TEXT, "Hello" );
2175 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2176 field.SetSize( 300.f, 50.f );
2177 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2178 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2180 // Avoid a crash when core load gl resources.
2181 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2183 // Create a tap event to touch the text field.
2184 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2185 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2186 application.SendNotification();
2187 application.Render();
2190 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE;
2191 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2192 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2193 application.SendNotification();
2194 application.Render();
2196 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
2197 map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
2198 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2199 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2200 application.SendNotification();
2201 application.Render();
2203 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_COUNT;
2204 map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2205 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2206 for( unsigned int index = 0u; index < 5u; ++index )
2208 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2209 application.SendNotification();
2210 application.Render();
2213 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT;
2214 map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2215 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2216 for( unsigned int index = 0u; index < 5u; ++index )
2218 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2219 application.SendNotification();
2220 application.Render();
2223 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER;
2224 map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 0;
2225 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2226 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2227 application.SendNotification();
2228 application.Render();
2229 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2230 application.SendNotification();
2231 application.Render();
2233 map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 100;
2234 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2235 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2236 application.SendNotification();
2237 application.Render();
2239 Property::Map mapGet;
2240 mapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
2241 DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION );
2242 DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION );
2247 int utcDaliTextFieldStyleWhilstSelected(void)
2249 ToolkitTestApplication application;
2250 tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
2252 // Change font and styles whilst text is selected whilst word selected
2254 TextField field = TextField::New();
2255 DALI_TEST_CHECK( field );
2256 Stage::GetCurrent().Add( field );
2257 LoadMarkerImages(application, field);
2258 // Render and notify
2259 application.SendNotification();
2260 application.Render();
2262 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2263 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2264 field.SetSize( 300.f, 50.f );
2265 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2266 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2268 // Avoid a crash when core load gl resources.
2269 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2270 // Render and notify
2271 application.SendNotification();
2272 application.Render();
2274 // Create a tap event to touch the text field.
2275 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2276 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2277 // Render and notify
2278 application.SendNotification();
2279 application.Render();
2282 // Tap first to get the focus.
2283 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2284 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2286 // Render and notify
2287 application.SendNotification();
2288 application.Render();
2290 // Double tap to select a word.
2291 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2292 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2294 // Render and notify
2295 application.SendNotification();
2296 application.Render();
2298 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
2299 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
2301 Property::Map fontStyleMapSet;
2302 Property::Map fontStyleMapGet;
2304 fontStyleMapSet.Insert( "weight", "bold" );
2305 fontStyleMapSet.Insert( "slant", "italic" );
2306 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2308 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2309 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2310 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2312 fontStyleMapSet.Clear();
2313 fontStyleMapSet.Insert( "width", "expanded" );
2314 fontStyleMapSet.Insert( "slant", "italic" );
2315 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2317 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2318 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2319 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2321 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2322 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2324 field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2325 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2327 fontStyleMapSet.Clear();
2328 fontStyleMapSet.Insert( "weight", "bold" );
2329 fontStyleMapSet.Insert( "slant", "italic" );
2331 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2333 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2334 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2335 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2337 fontStyleMapSet.Clear();
2338 fontStyleMapSet.Insert( "width", "expanded" );
2340 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2342 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2343 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2344 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2346 // Press Escape to increase coverage
2347 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2348 application.SendNotification();
2349 application.Render();
2351 DALI_TEST_CHECK( !field.HasKeyInputFocus() );
2356 int utcDaliTextFieldEscKeyLoseFocus(void)
2358 ToolkitTestApplication application;
2359 tet_infoline(" utcDaliTextFieldEscKeyLoseFocus");
2361 // Creates a tap event. After creating a tap event the text field should
2362 // have the focus and add text with key events should be possible.
2364 TextField field = TextField::New();
2365 DALI_TEST_CHECK( field );
2367 Stage::GetCurrent().Add( field );
2369 field.SetSize( 300.f, 50.f );
2370 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2371 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2373 // Avoid a crash when core load gl resources.
2374 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2376 // Render and notify
2377 application.SendNotification();
2378 application.Render();
2380 // Add a key event but as the text field has not the focus it should do nothing.
2381 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2382 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2384 // Render and notify
2385 application.SendNotification();
2386 application.Render();
2388 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2390 // Create a tap event to touch the text field.
2391 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2392 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2394 // Render and notify
2395 application.SendNotification();
2396 application.Render();
2398 // Now the text field has the focus, so it can handle the key events.
2399 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2400 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2401 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2402 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2404 // Render and notify
2405 application.SendNotification();
2406 application.Render();
2408 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2410 // Generate a Esc key event. The text field should lose the focus.
2411 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2412 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2414 // Render and notify
2415 application.SendNotification();
2416 application.Render();
2418 DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2420 // No more text should be introduced
2421 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2422 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2424 // Render and notify
2425 application.SendNotification();
2426 application.Render();
2428 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2433 int utcDaliTextFieldSomeSpecialKeys(void)
2435 ToolkitTestApplication application;
2436 tet_infoline(" utcDaliTextFieldSomeSpecialKeys");
2438 // Checks some special keys when the text is selected.
2440 TextField field = TextField::New();
2441 DALI_TEST_CHECK( field );
2442 Stage::GetCurrent().Add( field );
2443 LoadMarkerImages(application, field);
2444 // Render and notify
2445 application.SendNotification();
2446 application.Render();
2448 const std::string longText( "This is a long text for the size of the text-field." );
2450 field.SetProperty( TextField::Property::TEXT, longText );
2451 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2452 field.SetSize( 300.f, 50.f );
2453 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2454 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2456 // Avoid a crash when core load gl resources.
2457 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2458 // Render and notify
2459 application.SendNotification();
2460 application.Render();
2462 // Create a tap event to touch the text field.
2463 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2464 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2466 // Render and notify
2467 application.SendNotification();
2468 application.Render();
2470 // Tap first to get the focus.
2471 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2472 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2474 // Render and notify
2475 application.SendNotification();
2476 application.Render();
2478 // Double tap to select a word.
2479 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2480 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2482 // Render and notify
2483 application.SendNotification();
2484 application.Render();
2486 // Generate a Esc key event. The text field should lose the focus.
2487 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2488 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2490 // Render and notify
2491 application.SendNotification();
2492 application.Render();
2494 // Generate a Esc key event. The text field should lose the focus.
2495 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2496 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2498 // Render and notify
2499 application.SendNotification();
2500 application.Render();
2502 // Generate a Esc key event. The text field should lose the focus.
2503 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2504 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2506 // Render and notify
2507 application.SendNotification();
2508 application.Render();
2510 // The text shouldn't be deleted.
2511 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), longText, TEST_LOCATION );
2516 int utcDaliTextFieldSizeUpdate(void)
2518 ToolkitTestApplication application;
2519 tet_infoline("utcDaliTextFieldSizeUpdate");
2521 // Checks some special keys when the text is selected.
2522 TextField field = TextField::New();
2523 DALI_TEST_CHECK( field );
2524 Stage::GetCurrent().Add( field );
2526 float previousHeight = 0.0f;
2527 float currentHeight = 0.0f;
2528 const float fieldWidth = 1920.0f;
2531 // "ㅁ" is bigger then "ኢ"
2532 field.SetSize( Vector2( fieldWidth ,10.0f ) );
2533 field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH );
2534 field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT );
2536 field.SetProperty( TextField::Property::TEXT, "ኢ");
2537 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2538 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2540 field.SetKeyboardFocusable(true);
2541 KeyboardFocusManager::Get().SetCurrentFocusActor( field );
2543 application.SendNotification();
2544 application.Render();
2546 previousHeight = field.GetHeightForWidth( fieldWidth );
2547 DALI_TEST_EQUALS( previousHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION );
2549 // Add another script characters ( glyph height is defferent )
2550 application.ProcessEvent( GenerateKey( "ㅁ", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2551 application.ProcessEvent( GenerateKey( "ㅁ", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2553 application.SendNotification();
2554 application.Render();
2556 currentHeight = field.GetHeightForWidth( fieldWidth );
2557 DALI_TEST_EQUALS( currentHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ), TEST_LOCATION );
2558 DALI_TEST_EQUALS( (previousHeight < currentHeight), true , TEST_LOCATION );
2563 int utcDaliTextFieldExtremlyLargePointSize(void)
2565 ToolkitTestApplication application;
2566 tet_infoline(" utcDaliTextFieldExtremlyLargePointSize");
2568 TextField field = TextField::New();
2570 field.SetProperty( TextField::Property::TEXT, "Text" );
2571 field.SetSize( 300.f, 50.f );
2572 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2573 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2574 Stage::GetCurrent().Add( field );
2578 field.SetProperty( TextField::Property::POINT_SIZE, 160.0f );
2579 application.SendNotification();
2580 DALI_TEST_CHECK( field );
2584 tet_result(TET_FAIL);
2589 int UtcDaliTextFieldDefaultFontStylePropertyCoverage(void)
2591 ToolkitTestApplication application;
2592 tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage");
2593 TextField field = TextField::New();
2594 DALI_TEST_CHECK( field );
2595 Stage::GetCurrent().Add( field );
2597 Property::Map fontStyleMapGet;
2599 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2601 Property::Value* weightValue = NULL;
2602 Property::Value* widthValue = NULL;
2603 Property::Value* slantValue = NULL;
2604 weightValue = fontStyleMapGet.Find( "weight" );
2605 widthValue = fontStyleMapGet.Find( "width" );
2606 slantValue = fontStyleMapGet.Find( "slant" );
2607 DALI_TEST_CHECK( !weightValue );
2608 DALI_TEST_CHECK( !widthValue );
2609 DALI_TEST_CHECK( !slantValue );
2614 int UtcDaliTextFieldSettingPlaceholder(void)
2616 ToolkitTestApplication application;
2617 tet_infoline("UtcDaliTextFieldSettingPlaceholder");
2619 TextField field = TextField::New();
2620 DALI_TEST_CHECK( field );
2621 Stage::GetCurrent().Add( field );
2623 // Check the placeholder property with pixel size
2624 Property::Map placeholderPixelSizeMapSet;
2625 Property::Map placeholderPixelSizeMapGet;
2626 Property::Map placeholderFontstyleMap;
2627 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2628 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2629 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::BLUE;
2630 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2631 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::PIXEL_SIZE ] = 15.0f;
2632 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
2634 placeholderFontstyleMap.Insert( "weight", "bold" );
2635 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2636 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
2638 placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2639 DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
2640 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION );
2642 // Check the placeholder property with point size
2643 Property::Map placeholderMapSet;
2644 Property::Map placeholderMapGet;
2645 placeholderMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2646 placeholderMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2647 placeholderMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::RED;
2648 placeholderMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2649 placeholderMapSet[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
2650 placeholderMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = false;
2652 // Check the placeholder font style property
2653 placeholderFontstyleMap.Clear();
2655 placeholderFontstyleMap.Insert( "weight", "bold" );
2656 placeholderFontstyleMap.Insert( "width", "condensed" );
2657 placeholderFontstyleMap.Insert( "slant", "italic" );
2658 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2659 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2661 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2662 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2663 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2665 // Reset font style.
2666 placeholderFontstyleMap.Clear();
2667 placeholderFontstyleMap.Insert( "weight", "normal" );
2668 placeholderFontstyleMap.Insert( "slant", "oblique" );
2669 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2670 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2672 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2673 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2674 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2676 placeholderFontstyleMap.Clear();
2677 placeholderFontstyleMap.Insert( "slant", "roman" );
2678 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2679 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2681 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2683 placeholderFontstyleMap.Clear();
2684 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2686 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2687 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2688 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2689 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2694 int UtcDaliTextFieldSetPaddingProperty(void)
2696 ToolkitTestApplication application;
2697 tet_infoline("UtcDaliTextFieldSetPaddingProperty\n");
2699 TextField field = TextField::New();
2700 DALI_TEST_CHECK( field );
2701 field.SetSize( 300.f, 50.f );
2702 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2703 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2704 Stage::GetCurrent().Add( field );
2706 application.SendNotification();
2707 application.Render();
2709 Vector3 originalSize = field.GetNaturalSize();
2711 field.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
2713 application.SendNotification();
2714 application.Render();
2716 DALI_TEST_EQUALS( field.GetProperty<Extents>( Toolkit::Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
2718 Vector3 paddingAddedSize = field.GetNaturalSize();
2720 DALI_TEST_EQUALS( originalSize.width + 10 + 10 , paddingAddedSize.width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2722 DALI_TEST_EQUALS( originalSize.height + 10 + 10 , paddingAddedSize.height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );