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", "green" );
809 shadowMapSet.Insert( "offset", "2 2" );
811 field.SetProperty( TextField::Property::SHADOW, shadowMapSet );
813 shadowMapGet = field.GetProperty<Property::Map>( TextField::Property::SHADOW );
814 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
815 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
817 // Check the input shadow property
818 field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
819 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
821 // Check the emboss property
822 field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
823 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
825 // Check the input emboss property
826 field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
827 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
829 // Check the outline property
831 // Test string type first
832 // This is purely to maintain backward compatibility, but we don't support string as the outline property type.
833 field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
834 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
836 // Then test the property map type
837 Property::Map outlineMapSet;
838 Property::Map outlineMapGet;
840 outlineMapSet["color"] = Color::RED;
841 outlineMapSet["width"] = 2.0f;
843 field.SetProperty( TextField::Property::OUTLINE, outlineMapSet );
845 outlineMapSet["color"] = "red";
846 outlineMapSet["width"] = "2";
847 outlineMapGet = field.GetProperty<Property::Map>( TextField::Property::OUTLINE );
848 DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION );
849 DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION );
851 // Check the input outline property
852 field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
853 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
855 // Check the hidden input settings property
856 Property::Map hiddenMapSet;
857 Property::Map hiddenMapGet;
858 hiddenMapSet[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
859 hiddenMapSet[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 2;
860 hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 4;
861 hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
862 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, hiddenMapSet );
864 hiddenMapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
865 DALI_TEST_EQUALS( hiddenMapSet.Count(), hiddenMapGet.Count(), TEST_LOCATION );
866 DALI_TEST_EQUALS( DaliTestCheckMaps( hiddenMapSet, hiddenMapGet ), true, TEST_LOCATION );
868 // Check the pixel size of font
869 field.SetProperty( TextField::Property::PIXEL_SIZE, 20.f );
870 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
872 // Check the enable selection property
873 field.SetProperty( TextField::Property::ENABLE_SELECTION, false );
874 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_SELECTION ), false, TEST_LOCATION );
876 // Check the placeholder property with pixel size
877 Property::Map placeholderPixelSizeMapSet;
878 Property::Map placeholderPixelSizeMapGet;
879 Property::Map placeholderFontstyleMap;
880 placeholderPixelSizeMapSet["text"] = "Setting Placeholder Text";
881 placeholderPixelSizeMapSet["textFocused"] = "Setting Placeholder Text Focused";
882 placeholderPixelSizeMapSet["color"] = Color::BLUE;
883 placeholderPixelSizeMapSet["fontFamily"] = "Arial";
884 placeholderPixelSizeMapSet["pixelSize"] = 15.0f;
885 placeholderPixelSizeMapSet["ellipsis"] = true;
887 placeholderFontstyleMap.Insert( "weight", "bold" );
888 placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap;
889 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
891 placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
892 DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
894 tet_infoline("Test Placeholder settings set as strings is converted correctly to Property Index key and holds set value");
895 Property::Map placeholderConversionMap;
896 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
897 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
898 placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
899 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
900 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
901 placeholderConversionMap[ Text::PlaceHolder::Property::PIXEL_SIZE ] = placeholderPixelSizeMapSet["pixelSize"];
903 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderConversionMap ), true, TEST_LOCATION );
905 // Check the placeholder property with point size
906 Property::Map placeholderMapSet;
907 Property::Map placeholderMapGet;
908 placeholderMapSet["text"] = "Setting Placeholder Text";
909 placeholderMapSet["textFocused"] = "Setting Placeholder Text Focused";
910 placeholderMapSet["color"] = Color::RED;
911 placeholderMapSet["fontFamily"] = "Arial";
912 placeholderMapSet["pointSize"] = 12.0f;
913 placeholderMapSet["ellipsis"] = false;
915 // Check the placeholder font style property
916 placeholderFontstyleMap.Clear();
918 placeholderFontstyleMap.Insert( "weight", "bold" );
919 placeholderFontstyleMap.Insert( "width", "condensed" );
920 placeholderFontstyleMap.Insert( "slant", "italic" );
921 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
922 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
924 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
925 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
927 placeholderConversionMap.Clear();
928 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
929 placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
930 placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
931 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
932 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
933 placeholderConversionMap[ Text::PlaceHolder::Property::POINT_SIZE ] = placeholderPixelSizeMapSet["pointSize"];
935 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
938 placeholderFontstyleMap.Clear();
939 placeholderFontstyleMap.Insert( "weight", "normal" );
940 placeholderFontstyleMap.Insert( "slant", "oblique" );
941 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
942 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
944 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
945 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
947 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
948 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
950 placeholderFontstyleMap.Clear();
951 placeholderFontstyleMap.Insert( "slant", "roman" );
952 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
953 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
955 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
957 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
959 placeholderFontstyleMap.Clear();
960 placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
961 placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
963 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
964 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
965 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
967 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
969 // Check the ellipsis property
970 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
971 field.SetProperty( TextField::Property::ELLIPSIS, true );
972 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
977 // Positive Atlas Text Renderer test
978 int utcDaliTextFieldAtlasRenderP(void)
980 ToolkitTestApplication application;
981 tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
982 StyleManager styleManager = StyleManager::Get();
983 styleManager.ApplyDefaultTheme();
984 TextField field = TextField::New();
985 DALI_TEST_CHECK( field );
987 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
989 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
991 Stage::GetCurrent().Add( field );
995 // Render some text with the shared atlas backend
996 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
997 application.SendNotification();
998 application.Render();
1002 tet_result(TET_FAIL);
1007 // Positive test for the textChanged signal.
1008 int utcDaliTextFieldTextChangedP(void)
1010 ToolkitTestApplication application;
1011 tet_infoline(" utcDaliTextFieldTextChangedP");
1012 TextField field = TextField::New();
1013 DALI_TEST_CHECK( field );
1015 Stage::GetCurrent().Add( field );
1017 // connect to the text changed signal.
1018 ConnectionTracker* testTracker = new ConnectionTracker();
1019 field.TextChangedSignal().Connect(&TestTextChangedCallback);
1020 bool textChangedSignal = false;
1021 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
1023 gTextChangedCallBackCalled = false;
1024 field.SetProperty( TextField::Property::TEXT, "ABC" );
1025 DALI_TEST_CHECK( gTextChangedCallBackCalled );
1026 DALI_TEST_CHECK( textChangedSignal );
1028 application.SendNotification();
1030 field.SetKeyInputFocus();
1032 gTextChangedCallBackCalled = false;
1033 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1034 DALI_TEST_CHECK( gTextChangedCallBackCalled );
1039 // Negative test for the textChanged signal.
1040 int utcDaliTextFieldTextChangedN(void)
1042 ToolkitTestApplication application;
1043 tet_infoline(" utcDaliTextFieldTextChangedN");
1044 TextField field = TextField::New();
1045 DALI_TEST_CHECK( field );
1047 Stage::GetCurrent().Add( field );
1049 // connect to the text changed signal.
1050 ConnectionTracker* testTracker = new ConnectionTracker();
1051 field.TextChangedSignal().Connect(&TestTextChangedCallback);
1052 bool textChangedSignal = false;
1053 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
1055 gTextChangedCallBackCalled = false;
1056 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
1057 DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1058 DALI_TEST_CHECK( !textChangedSignal );
1063 // Positive test for Max Characters reached signal.
1064 int utcDaliTextFieldMaxCharactersReachedP(void)
1066 ToolkitTestApplication application;
1067 tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
1068 TextField field = TextField::New();
1069 DALI_TEST_CHECK( field );
1071 Stage::GetCurrent().Add( field );
1073 const int maxNumberOfCharacters = 1;
1074 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1076 field.SetKeyInputFocus();
1078 // connect to the text changed signal.
1079 ConnectionTracker* testTracker = new ConnectionTracker();
1080 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1081 bool maxLengthReachedSignal = false;
1082 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
1084 gMaxCharactersCallBackCalled = false;
1086 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1087 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1089 DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
1090 DALI_TEST_CHECK( maxLengthReachedSignal );
1095 // Negative test for Max Characters reached signal.
1096 int utcDaliTextFieldMaxCharactersReachedN(void)
1098 ToolkitTestApplication application;
1099 tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
1100 TextField field = TextField::New();
1101 DALI_TEST_CHECK( field );
1103 Stage::GetCurrent().Add( field );
1105 const int maxNumberOfCharacters = 3;
1106 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1108 field.SetKeyInputFocus();
1110 // connect to the text changed signal.
1111 ConnectionTracker* testTracker = new ConnectionTracker();
1112 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1113 bool maxLengthReachedSignal = false;
1114 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
1116 gMaxCharactersCallBackCalled = false;
1118 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1119 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1121 DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1122 DALI_TEST_CHECK( !maxLengthReachedSignal );
1127 int utcDaliTextFieldInputStyleChanged01(void)
1129 ToolkitTestApplication application;
1130 tet_infoline(" utcDaliTextFieldInputStyleChanged01");
1132 // The text-field emits signals when the input style changes. These changes of style are
1133 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1134 // can't be emitted during the size negotiation as the callbacks may update the UI.
1135 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1136 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1137 application.CreateAdaptor();
1141 char* pathNamePtr = get_current_dir_name();
1142 const std::string pathName( pathNamePtr );
1143 free( pathNamePtr );
1145 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1146 fontClient.SetDpi( 93u, 93u );
1148 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1149 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1151 TextField field = TextField::New();
1152 DALI_TEST_CHECK( field );
1155 field.SetSize( 300.f, 50.f );
1156 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1157 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1159 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1160 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
1162 // connect to the text changed signal.
1163 ConnectionTracker* testTracker = new ConnectionTracker();
1164 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1165 bool inputStyleChangedSignal = false;
1166 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1168 Stage::GetCurrent().Add( field );
1170 // Render and notify
1171 application.SendNotification();
1172 application.Render();
1174 // Executes the idle callbacks added by the text control on the change of input style.
1175 application.RunIdles();
1177 gInputStyleChangedCallbackCalled = false;
1178 gInputStyleMask = TextField::InputStyle::NONE;
1179 inputStyleChangedSignal = false;
1181 // Create a tap event to touch the text field.
1182 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1183 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1185 // Render and notify
1186 application.SendNotification();
1187 application.Render();
1189 // Executes the idle callbacks added by the text control on the change of input style.
1190 application.RunIdles();
1192 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1193 if( gInputStyleChangedCallbackCalled )
1195 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
1197 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1198 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1200 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1201 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1203 DALI_TEST_CHECK( inputStyleChangedSignal );
1205 gInputStyleChangedCallbackCalled = false;
1206 gInputStyleMask = TextField::InputStyle::NONE;
1207 inputStyleChangedSignal = false;
1209 // Create a tap event to touch the text field.
1210 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1211 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1213 // Render and notify
1214 application.SendNotification();
1215 application.Render();
1217 // Executes the idle callbacks added by the text control on the change of input style.
1218 application.RunIdles();
1220 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1221 DALI_TEST_CHECK( !inputStyleChangedSignal );
1223 gInputStyleChangedCallbackCalled = false;
1224 gInputStyleMask = TextField::InputStyle::NONE;
1225 inputStyleChangedSignal = false;
1227 // Create a tap event to touch the text field.
1228 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1229 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1231 // Render and notify
1232 application.SendNotification();
1233 application.Render();
1235 // Executes the idle callbacks added by the text control on the change of input style.
1236 application.RunIdles();
1238 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1239 if( gInputStyleChangedCallbackCalled )
1241 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1243 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1244 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1246 DALI_TEST_CHECK( inputStyleChangedSignal );
1248 gInputStyleChangedCallbackCalled = false;
1249 gInputStyleMask = TextField::InputStyle::NONE;
1250 inputStyleChangedSignal = false;
1252 // Create a tap event to touch the text field.
1253 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1254 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1256 // Render and notify
1257 application.SendNotification();
1258 application.Render();
1260 // Executes the idle callbacks added by the text control on the change of input style.
1261 application.RunIdles();
1263 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1264 if( gInputStyleChangedCallbackCalled )
1266 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1268 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1269 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1271 const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1273 Property::Map fontStyleMapSet;
1274 fontStyleMapSet.Insert( "weight", "bold" );
1276 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1277 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1279 DALI_TEST_CHECK( inputStyleChangedSignal );
1281 gInputStyleChangedCallbackCalled = false;
1282 gInputStyleMask = TextField::InputStyle::NONE;
1283 inputStyleChangedSignal = false;
1285 // Create a tap event to touch the text field.
1286 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1287 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1289 // Render and notify
1290 application.SendNotification();
1291 application.Render();
1293 // Executes the idle callbacks added by the text control on the change of input style.
1294 application.RunIdles();
1296 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1297 DALI_TEST_CHECK( !inputStyleChangedSignal );
1299 gInputStyleChangedCallbackCalled = false;
1300 gInputStyleMask = TextField::InputStyle::NONE;
1301 inputStyleChangedSignal = false;
1303 // Create a tap event to touch the text field.
1304 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1305 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1307 // Render and notify
1308 application.SendNotification();
1309 application.Render();
1311 // Executes the idle callbacks added by the text control on the change of input style.
1312 application.RunIdles();
1314 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1315 if( gInputStyleChangedCallbackCalled )
1317 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1319 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1320 DALI_TEST_CHECK( style.empty() );
1322 DALI_TEST_CHECK( inputStyleChangedSignal );
1324 gInputStyleChangedCallbackCalled = false;
1325 gInputStyleMask = TextField::InputStyle::NONE;
1326 inputStyleChangedSignal = false;
1328 // Create a tap event to touch the text field.
1329 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1330 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1332 // Render and notify
1333 application.SendNotification();
1334 application.Render();
1336 // Executes the idle callbacks added by the text control on the change of input style.
1337 application.RunIdles();
1339 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1340 DALI_TEST_CHECK( !inputStyleChangedSignal );
1345 int utcDaliTextFieldInputStyleChanged02(void)
1347 ToolkitTestApplication application;
1348 tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1350 // The text-field emits signals when the input style changes. These changes of style are
1351 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1352 // can't be emitted during the size negotiation as the callbacks may update the UI.
1353 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1354 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1355 application.CreateAdaptor();
1359 char* pathNamePtr = get_current_dir_name();
1360 const std::string pathName( pathNamePtr );
1361 free( pathNamePtr );
1363 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1364 fontClient.SetDpi( 93u, 93u );
1366 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1367 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1369 TextField field = TextField::New();
1370 DALI_TEST_CHECK( field );
1373 field.SetSize( 300.f, 50.f );
1374 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1375 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1377 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1378 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>" );
1380 // connect to the text changed signal.
1381 ConnectionTracker* testTracker = new ConnectionTracker();
1382 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1383 bool inputStyleChangedSignal = false;
1384 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1386 Stage::GetCurrent().Add( field );
1388 // Render and notify
1389 application.SendNotification();
1390 application.Render();
1392 // Executes the idle callbacks added by the text control on the change of input style.
1393 application.RunIdles();
1395 gInputStyleChangedCallbackCalled = false;
1396 gInputStyleMask = TextField::InputStyle::NONE;
1397 inputStyleChangedSignal = false;
1399 // Create a tap event to touch the text field.
1400 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1401 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1402 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1403 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1405 // Render and notify
1406 application.SendNotification();
1407 application.Render();
1409 // Executes the idle callbacks added by the text control on the change of input style.
1410 application.RunIdles();
1412 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1413 if( gInputStyleChangedCallbackCalled )
1415 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1416 static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1417 TextField::InputStyle::POINT_SIZE |
1418 TextField::InputStyle::COLOR ),
1421 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1422 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1424 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1425 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1427 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1428 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1430 DALI_TEST_CHECK( inputStyleChangedSignal );
1432 gInputStyleChangedCallbackCalled = false;
1433 gInputStyleMask = TextField::InputStyle::NONE;
1434 inputStyleChangedSignal = false;
1436 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1438 // Render and notify
1439 application.SendNotification();
1440 application.Render();
1442 // Executes the idle callbacks added by the text control on the change of input style.
1443 application.RunIdles();
1445 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1446 if( gInputStyleChangedCallbackCalled )
1448 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1449 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1452 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1453 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1455 DALI_TEST_CHECK( inputStyleChangedSignal );
1457 gInputStyleChangedCallbackCalled = false;
1458 gInputStyleMask = TextField::InputStyle::NONE;
1459 inputStyleChangedSignal = false;
1461 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1463 // Render and notify
1464 application.SendNotification();
1465 application.Render();
1467 // Executes the idle callbacks added by the text control on the change of input style.
1468 application.RunIdles();
1470 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1471 DALI_TEST_CHECK( !inputStyleChangedSignal );
1473 gInputStyleChangedCallbackCalled = false;
1474 gInputStyleMask = TextField::InputStyle::NONE;
1475 inputStyleChangedSignal = false;
1477 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1479 // Render and notify
1480 application.SendNotification();
1481 application.Render();
1483 // Executes the idle callbacks added by the text control on the change of input style.
1484 application.RunIdles();
1486 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1487 if( gInputStyleChangedCallbackCalled )
1489 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1490 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1493 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1494 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1496 DALI_TEST_CHECK( inputStyleChangedSignal );
1498 gInputStyleChangedCallbackCalled = false;
1499 gInputStyleMask = TextField::InputStyle::NONE;
1500 inputStyleChangedSignal = false;
1502 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1504 Property::Map fontStyleMapSet;
1505 fontStyleMapSet.Insert( "weight", "thin" );
1506 fontStyleMapSet.Insert( "width", "condensed" );
1507 fontStyleMapSet.Insert( "slant", "italic" );
1509 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1510 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1512 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1513 field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1514 field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1515 field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1517 // Render and notify
1518 application.SendNotification();
1519 application.Render();
1521 // Executes the idle callbacks added by the text control on the change of input style.
1522 application.RunIdles();
1524 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1525 DALI_TEST_CHECK( !inputStyleChangedSignal );
1527 // Create a tap event to touch the text field.
1528 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1529 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1531 // Render and notify
1532 application.SendNotification();
1533 application.Render();
1535 // Executes the idle callbacks added by the text control on the change of input style.
1536 application.RunIdles();
1538 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1539 if( gInputStyleChangedCallbackCalled )
1541 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1542 static_cast<unsigned int>( TextField::InputStyle::COLOR |
1543 TextField::InputStyle::POINT_SIZE |
1544 TextField::InputStyle::FONT_STYLE |
1545 TextField::InputStyle::UNDERLINE |
1546 TextField::InputStyle::SHADOW |
1547 TextField::InputStyle::EMBOSS |
1548 TextField::InputStyle::OUTLINE ),
1551 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1552 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1554 DALI_TEST_CHECK( inputStyleChangedSignal );
1559 int utcDaliTextFieldEvent01(void)
1561 ToolkitTestApplication application;
1562 tet_infoline(" utcDaliTextFieldEvent01");
1564 // Creates a tap event. After creating a tap event the text field should
1565 // have the focus and add text with key events should be possible.
1567 TextField field = TextField::New();
1568 DALI_TEST_CHECK( field );
1570 Stage::GetCurrent().Add( field );
1572 field.SetSize( 300.f, 50.f );
1573 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1574 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1576 // Avoid a crash when core load gl resources.
1577 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1579 // Render and notify
1580 application.SendNotification();
1581 application.Render();
1583 // Add a key event but as the text field has not the focus it should do nothing.
1584 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1586 // Render and notify
1587 application.SendNotification();
1588 application.Render();
1590 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1592 // Create a tap event to touch the text field.
1593 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1594 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1596 // Render and notify
1597 application.SendNotification();
1598 application.Render();
1600 // Now the text field has the focus, so it can handle the key events.
1601 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1602 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1604 // Render and notify
1605 application.SendNotification();
1606 application.Render();
1608 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1610 // Create a second text field and send key events to it.
1611 TextField field2 = TextField::New();
1613 field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1614 field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1615 field2.SetSize( 100.f, 100.f );
1616 field2.SetPosition( 100.f, 100.f );
1618 Stage::GetCurrent().Add( field2 );
1620 // Render and notify
1621 application.SendNotification();
1622 application.Render();
1624 // Create a tap event on the second text field.
1625 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1626 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1628 // Render and notify
1629 application.SendNotification();
1630 application.Render();
1632 // The second text field has the focus. It should handle the key events.
1633 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1634 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1636 // Render and notify
1637 application.SendNotification();
1638 application.Render();
1640 // Check the text has been added to the second text field.
1641 DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1646 int utcDaliTextFieldEvent02(void)
1648 ToolkitTestApplication application;
1649 tet_infoline(" utcDaliTextFieldEvent02");
1651 // Checks if the right number of actors are created.
1653 TextField field = TextField::New();
1654 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1655 DALI_TEST_CHECK( field );
1656 LoadMarkerImages(application, field);
1658 Stage::GetCurrent().Add( field );
1660 field.SetSize( 300.f, 50.f );
1661 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1662 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1664 // Avoid a crash when core load gl resources.
1665 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1667 // Render and notify
1668 application.SendNotification();
1669 application.Render();
1671 // Check there are the expected number of children ( stencil ).
1672 DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1674 Actor stencil = field.GetChildAt( 0u );
1675 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1677 // Create a tap event to touch the text field.
1678 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1679 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1681 // Render and notify
1682 application.SendNotification();
1683 application.Render();
1685 Actor layer = field.GetChildAt( 1u );
1686 DALI_TEST_CHECK( layer.IsLayer() );
1688 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1689 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1691 // Now the text field has the focus, so it can handle the key events.
1692 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1693 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1695 // Render and notify
1696 application.SendNotification();
1697 application.Render();
1699 // Checks the cursor and the renderer have been created.
1700 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1701 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1703 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1704 DALI_TEST_CHECK( cursor );
1706 // The offscreen root actor has a container with all the actors which contain the text renderers.
1707 Actor container = stencil.GetChildAt( 0u );
1708 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1710 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1711 DALI_TEST_CHECK( renderer );
1714 // Move the cursor and check the position changes.
1715 Vector3 position1 = cursor.GetCurrentPosition();
1717 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1718 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1720 // Render and notify
1721 application.SendNotification();
1722 application.Render();
1724 Vector3 position2 = cursor.GetCurrentPosition();
1726 DALI_TEST_CHECK( position2.x < position1.x );
1728 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1729 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1731 // Render and notify
1732 application.SendNotification();
1733 application.Render();
1735 Vector3 position3 = cursor.GetCurrentPosition();
1737 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1739 // Send some taps and check the cursor positions.
1741 // Try to tap at the beginning.
1742 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1743 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1745 // Render and notify
1746 application.SendNotification();
1747 application.Render();
1749 // Cursor position should be the same than position1.
1750 Vector3 position4 = cursor.GetCurrentPosition();
1752 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1754 // Tap away from the start position.
1755 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1756 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1758 // Render and notify
1759 application.SendNotification();
1760 application.Render();
1762 Vector3 position5 = cursor.GetCurrentPosition();
1764 DALI_TEST_CHECK( position5.x > position4.x );
1766 // Remove all the text.
1767 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1768 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1769 field.SetProperty( TextField::Property::TEXT, "" );
1771 // Render and notify
1772 application.SendNotification();
1773 application.Render();
1775 // Cursor position should be the same than position2.
1776 Vector3 position6 = cursor.GetCurrentPosition();
1778 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1780 // Should not be a renderer.
1781 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1783 // Chanege exceed policy (EXCEED_POLICY_ORIGINAL doesn't use stencil )
1784 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1785 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
1787 application.SendNotification();
1788 application.Render();
1790 // There are renderer and decorator layer
1791 DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
1796 int utcDaliTextFieldEvent03(void)
1798 ToolkitTestApplication application;
1799 tet_infoline(" utcDaliTextFieldEvent03");
1801 // Checks if the highlight actor is created.
1803 TextField field = TextField::New();
1804 DALI_TEST_CHECK( field );
1806 Stage::GetCurrent().Add( field );
1808 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1809 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1810 field.SetSize( 30.f, 50.f );
1811 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1812 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1814 // Avoid a crash when core load gl resources.
1815 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1816 LoadMarkerImages(application, field);
1818 // Render and notify
1819 application.SendNotification();
1820 application.Render();
1822 // Tap first to get the focus.
1823 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1824 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1826 // Render and notify
1827 application.SendNotification();
1828 application.Render();
1830 // Double tap to select a word.
1831 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1832 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1834 // Render and notify
1835 application.SendNotification();
1836 application.Render();
1838 // The offscreen root actor should have two actors: the renderer and the highlight actor.
1839 Actor stencil = field.GetChildAt( 0u );
1841 // The highlight actor is drawn first, so is the first actor in the list
1842 Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
1843 DALI_TEST_CHECK( highlight );
1845 // The offscreen root actor has a container with all the actors which contain the text renderers.
1846 Actor container = stencil.GetChildAt( 1u );
1847 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1849 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1850 DALI_TEST_CHECK( renderer );
1856 int utcDaliTextFieldEvent04(void)
1858 ToolkitTestApplication application;
1859 tet_infoline(" utcDaliTextFieldEvent04");
1861 // Checks if the highlight actor is created.
1863 TextField field = TextField::New();
1864 DALI_TEST_CHECK( field );
1865 Stage::GetCurrent().Add( field );
1866 LoadMarkerImages(application, field);
1867 // Render and notify
1868 application.SendNotification();
1869 application.Render();
1871 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1872 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1873 field.SetSize( 300.f, 50.f );
1874 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1875 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1877 // Avoid a crash when core load gl resources.
1878 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1879 // Render and notify
1880 application.SendNotification();
1881 application.Render();
1883 // Create a tap event to touch the text field.
1884 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1885 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1886 // Render and notify
1887 application.SendNotification();
1888 application.Render();
1891 // Tap first to get the focus.
1892 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1893 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1895 // Render and notify
1896 application.SendNotification();
1897 application.Render();
1899 // Double tap to select a word.
1900 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1901 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1903 // Render and notify
1904 application.SendNotification();
1905 application.Render();
1908 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1909 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1913 int utcDaliTextFieldEvent05(void)
1915 ToolkitTestApplication application;
1916 tet_infoline(" utcDaliTextFieldEvent05");
1918 // Checks dragging of cursor/grab handle
1920 TextField field = TextField::New();
1921 DALI_TEST_CHECK( field );
1922 Stage::GetCurrent().Add( field );
1923 LoadMarkerImages(application, field);
1924 // Render and notify
1925 application.SendNotification();
1926 application.Render();
1928 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1929 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1930 field.SetSize( 300.f, 50.f );
1931 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1932 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1934 // Avoid a crash when core load gl resources.
1935 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1936 // Render and notify
1937 application.SendNotification();
1938 application.Render();
1940 // Create a tap event to touch the text field.
1941 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1942 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1943 // Render and notify
1944 application.SendNotification();
1945 application.Render();
1948 // Tap first to get the focus.
1949 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1950 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1952 // Render and notify
1953 application.SendNotification();
1954 application.Render();
1956 // Double tap to select a word.
1957 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1958 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1960 // Render and notify
1961 application.SendNotification();
1962 application.Render();
1964 // drag grab handle right
1965 Vector2 pos(0.0f, 40.0f);
1966 SendPan(application, Gesture::Possible, pos);
1967 SendPan(application, Gesture::Started, pos);
1969 Wait(application, 100);
1971 for(int i = 0;i<20;i++)
1973 SendPan(application, Gesture::Continuing, pos);
1978 SendPan(application, Gesture::Finished, pos);
1979 Wait(application, RENDER_FRAME_INTERVAL);
1981 Actor stencil = field.GetChildAt( 1u );
1985 int utcDaliTextFieldEvent06(void)
1987 ToolkitTestApplication application;
1988 tet_infoline(" utcDaliTextFieldEvent06");
1990 // Checks Longpress when in edit mode
1992 TextField field = TextField::New();
1993 DALI_TEST_CHECK( field );
1994 Stage::GetCurrent().Add( field );
1995 LoadMarkerImages(application, field);
1996 // Render and notify
1997 application.SendNotification();
1998 application.Render();
2000 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
2001 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2002 field.SetSize( 300.f, 50.f );
2003 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2004 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2006 // Avoid a crash when core load gl resources.
2007 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2008 // Render and notify
2009 application.SendNotification();
2010 application.Render();
2012 // Create a tap event to touch the text field.
2013 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2014 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2015 // Render and notify
2016 application.SendNotification();
2017 application.Render();
2020 // Tap first to get the focus.
2021 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2022 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2024 // Render and notify
2025 application.SendNotification();
2026 application.Render();
2029 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2030 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2032 // Render and notify
2033 application.SendNotification();
2034 application.Render();
2039 int utcDaliTextFieldEvent07(void)
2041 ToolkitTestApplication application;
2042 tet_infoline(" utcDaliTextFieldEvent07");
2044 // Checks Longpress to start edit mode
2046 TextField field = TextField::New();
2047 DALI_TEST_CHECK( field );
2048 Stage::GetCurrent().Add( field );
2049 LoadMarkerImages(application, field);
2050 // Render and notify
2051 application.SendNotification();
2052 application.Render();
2054 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
2055 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2056 field.SetSize( 300.f, 50.f );
2057 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2058 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2059 Property::Map propertyMap;
2060 propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD;
2061 field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
2063 // Avoid a crash when core load gl resources.
2064 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2065 // Render and notify
2066 application.SendNotification();
2067 application.Render();
2070 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2071 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2073 // Render and notify
2074 application.SendNotification();
2075 application.Render();
2080 int utcDaliTextFieldEvent08(void)
2082 ToolkitTestApplication application;
2083 tet_infoline(" utcDaliTextFieldEvent08");
2085 Dali::Clipboard clipboard = Clipboard::Get();
2086 clipboard.SetItem("testTextFieldEvent");
2088 // Checks Longpress when only place holder text
2090 TextField field = TextField::New();
2091 DALI_TEST_CHECK( field );
2092 Stage::GetCurrent().Add( field );
2093 LoadMarkerImages(application, field);
2094 // Render and notify
2095 application.SendNotification();
2096 application.Render();
2098 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
2099 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2100 field.SetSize( 300.f, 50.f );
2101 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2102 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2104 // Avoid a crash when core load gl resources.
2105 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2106 // Render and notify
2107 application.SendNotification();
2108 application.Render();
2111 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2112 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2114 // Render and notify
2115 application.SendNotification();
2116 application.Render();
2118 Wait(application, 500);
2121 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
2122 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
2124 // Render and notify
2125 application.SendNotification();
2126 application.Render();
2128 Wait(application, 500);
2130 Stage stage = Stage::GetCurrent();
2131 Layer layer = stage.GetRootLayer();
2132 Actor actor = layer.FindChildByName("optionPaste");
2136 Vector3 worldPosition = actor.GetCurrentWorldPosition();
2137 Vector2 halfStageSize = stage.GetSize() / 2.0f;
2138 Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
2140 Dali::Integration::TouchEvent event;
2141 event = Dali::Integration::TouchEvent();
2142 event.AddPoint( GetPointDownInside( position ) );
2143 application.ProcessEvent( event );
2145 event = Dali::Integration::TouchEvent();
2146 event.AddPoint( GetPointUpInside( position ) );
2147 application.ProcessEvent( event );
2149 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
2154 int utcDaliTextFieldEvent09(void)
2156 ToolkitTestApplication application;
2157 tet_infoline(" utcDaliTextFieldEvent09");
2159 TextField field = TextField::New();
2160 DALI_TEST_CHECK( field );
2161 Stage::GetCurrent().Add( field );
2162 LoadMarkerImages(application, field);
2163 // Render and notify
2164 application.SendNotification();
2165 application.Render();
2167 field.SetProperty( TextField::Property::TEXT, "Hello" );
2168 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2169 field.SetSize( 300.f, 50.f );
2170 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2171 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2173 // Avoid a crash when core load gl resources.
2174 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2176 // Create a tap event to touch the text field.
2177 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2178 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2179 application.SendNotification();
2180 application.Render();
2183 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE;
2184 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2185 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2186 application.SendNotification();
2187 application.Render();
2189 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
2190 map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
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_COUNT;
2197 map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2198 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2199 for( unsigned int index = 0u; index < 5u; ++index )
2201 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2202 application.SendNotification();
2203 application.Render();
2206 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT;
2207 map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2208 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2209 for( unsigned int index = 0u; index < 5u; ++index )
2211 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2212 application.SendNotification();
2213 application.Render();
2216 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER;
2217 map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 0;
2218 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2219 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2220 application.SendNotification();
2221 application.Render();
2222 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2223 application.SendNotification();
2224 application.Render();
2226 map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 100;
2227 field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2228 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2229 application.SendNotification();
2230 application.Render();
2232 Property::Map mapGet;
2233 mapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
2234 DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION );
2235 DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION );
2240 int utcDaliTextFieldStyleWhilstSelected(void)
2242 ToolkitTestApplication application;
2243 tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
2245 // Change font and styles whilst text is selected whilst word selected
2247 TextField field = TextField::New();
2248 DALI_TEST_CHECK( field );
2249 Stage::GetCurrent().Add( field );
2250 LoadMarkerImages(application, field);
2251 // Render and notify
2252 application.SendNotification();
2253 application.Render();
2255 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2256 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2257 field.SetSize( 300.f, 50.f );
2258 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2259 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2261 // Avoid a crash when core load gl resources.
2262 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2263 // Render and notify
2264 application.SendNotification();
2265 application.Render();
2267 // Create a tap event to touch the text field.
2268 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2269 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2270 // Render and notify
2271 application.SendNotification();
2272 application.Render();
2275 // Tap first to get the focus.
2276 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2277 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2279 // Render and notify
2280 application.SendNotification();
2281 application.Render();
2283 // Double tap to select a word.
2284 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2285 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2287 // Render and notify
2288 application.SendNotification();
2289 application.Render();
2291 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
2292 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
2294 Property::Map fontStyleMapSet;
2295 Property::Map fontStyleMapGet;
2297 fontStyleMapSet.Insert( "weight", "bold" );
2298 fontStyleMapSet.Insert( "slant", "italic" );
2299 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2301 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2302 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2303 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2305 fontStyleMapSet.Clear();
2306 fontStyleMapSet.Insert( "width", "expanded" );
2307 fontStyleMapSet.Insert( "slant", "italic" );
2308 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2310 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2311 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2312 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2314 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2315 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2317 field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2318 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2320 fontStyleMapSet.Clear();
2321 fontStyleMapSet.Insert( "weight", "bold" );
2322 fontStyleMapSet.Insert( "slant", "italic" );
2324 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2326 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2327 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2328 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2330 fontStyleMapSet.Clear();
2331 fontStyleMapSet.Insert( "width", "expanded" );
2333 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2335 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2336 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2337 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2339 // Press Escape to increase coverage
2340 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2341 application.SendNotification();
2342 application.Render();
2344 DALI_TEST_CHECK( !field.HasKeyInputFocus() );
2349 int utcDaliTextFieldEscKeyLoseFocus(void)
2351 ToolkitTestApplication application;
2352 tet_infoline(" utcDaliTextFieldEscKeyLoseFocus");
2354 // Creates a tap event. After creating a tap event the text field should
2355 // have the focus and add text with key events should be possible.
2357 TextField field = TextField::New();
2358 DALI_TEST_CHECK( field );
2360 Stage::GetCurrent().Add( field );
2362 field.SetSize( 300.f, 50.f );
2363 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2364 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2366 // Avoid a crash when core load gl resources.
2367 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2369 // Render and notify
2370 application.SendNotification();
2371 application.Render();
2373 // Add a key event but as the text field has not the focus it should do nothing.
2374 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2375 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2377 // Render and notify
2378 application.SendNotification();
2379 application.Render();
2381 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2383 // Create a tap event to touch the text field.
2384 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2385 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2387 // Render and notify
2388 application.SendNotification();
2389 application.Render();
2391 // Now the text field has the focus, so it can handle the key events.
2392 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2393 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2394 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2395 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2397 // Render and notify
2398 application.SendNotification();
2399 application.Render();
2401 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2403 // Generate a Esc key event. The text field should lose the focus.
2404 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2405 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2407 // Render and notify
2408 application.SendNotification();
2409 application.Render();
2411 DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2413 // No more text should be introduced
2414 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2415 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2417 // Render and notify
2418 application.SendNotification();
2419 application.Render();
2421 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2426 int utcDaliTextFieldSomeSpecialKeys(void)
2428 ToolkitTestApplication application;
2429 tet_infoline(" utcDaliTextFieldSomeSpecialKeys");
2431 // Checks some special keys when the text is selected.
2433 TextField field = TextField::New();
2434 DALI_TEST_CHECK( field );
2435 Stage::GetCurrent().Add( field );
2436 LoadMarkerImages(application, field);
2437 // Render and notify
2438 application.SendNotification();
2439 application.Render();
2441 const std::string longText( "This is a long text for the size of the text-field." );
2443 field.SetProperty( TextField::Property::TEXT, longText );
2444 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2445 field.SetSize( 300.f, 50.f );
2446 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2447 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2449 // Avoid a crash when core load gl resources.
2450 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2451 // Render and notify
2452 application.SendNotification();
2453 application.Render();
2455 // Create a tap event to touch the text field.
2456 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2457 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2459 // Render and notify
2460 application.SendNotification();
2461 application.Render();
2463 // Tap first to get the focus.
2464 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2465 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2467 // Render and notify
2468 application.SendNotification();
2469 application.Render();
2471 // Double tap to select a word.
2472 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2473 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2475 // Render and notify
2476 application.SendNotification();
2477 application.Render();
2479 // Generate a Esc key event. The text field should lose the focus.
2480 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2481 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2483 // Render and notify
2484 application.SendNotification();
2485 application.Render();
2487 // Generate a Esc key event. The text field should lose the focus.
2488 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2489 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2491 // Render and notify
2492 application.SendNotification();
2493 application.Render();
2495 // Generate a Esc key event. The text field should lose the focus.
2496 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2497 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2499 // Render and notify
2500 application.SendNotification();
2501 application.Render();
2503 // The text shouldn't be deleted.
2504 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), longText, TEST_LOCATION );
2509 int utcDaliTextFieldSizeUpdate(void)
2511 ToolkitTestApplication application;
2512 tet_infoline("utcDaliTextFieldSizeUpdate");
2514 // Checks some special keys when the text is selected.
2515 TextField field = TextField::New();
2516 DALI_TEST_CHECK( field );
2517 Stage::GetCurrent().Add( field );
2519 float previousHeight = 0.0f;
2520 float currentHeight = 0.0f;
2521 const float fieldWidth = 1920.0f;
2524 // "ㅁ" is bigger then "ኢ"
2525 field.SetSize( Vector2( fieldWidth ,10.0f ) );
2526 field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH );
2527 field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT );
2529 field.SetProperty( TextField::Property::TEXT, "ኢ");
2530 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2531 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2533 field.SetKeyboardFocusable(true);
2534 KeyboardFocusManager::Get().SetCurrentFocusActor( field );
2536 application.SendNotification();
2537 application.Render();
2539 previousHeight = field.GetHeightForWidth( fieldWidth );
2540 DALI_TEST_EQUALS( previousHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION );
2542 // Add another script characters ( glyph height is defferent )
2543 application.ProcessEvent( GenerateKey( "ㅁ", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2544 application.ProcessEvent( GenerateKey( "ㅁ", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2546 application.SendNotification();
2547 application.Render();
2549 currentHeight = field.GetHeightForWidth( fieldWidth );
2550 DALI_TEST_EQUALS( currentHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ), TEST_LOCATION );
2551 DALI_TEST_EQUALS( (previousHeight < currentHeight), true , TEST_LOCATION );
2556 int utcDaliTextFieldExtremlyLargePointSize(void)
2558 ToolkitTestApplication application;
2559 tet_infoline(" utcDaliTextFieldExtremlyLargePointSize");
2561 TextField field = TextField::New();
2563 field.SetProperty( TextField::Property::TEXT, "Text" );
2564 field.SetSize( 300.f, 50.f );
2565 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2566 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2567 Stage::GetCurrent().Add( field );
2571 field.SetProperty( TextField::Property::POINT_SIZE, 160.0f );
2572 application.SendNotification();
2573 DALI_TEST_CHECK( field );
2577 tet_result(TET_FAIL);
2582 int UtcDaliTextFieldDefaultFontStylePropertyCoverage(void)
2584 ToolkitTestApplication application;
2585 tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage");
2586 TextField field = TextField::New();
2587 DALI_TEST_CHECK( field );
2588 Stage::GetCurrent().Add( field );
2590 Property::Map fontStyleMapGet;
2592 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2594 Property::Value* weightValue = NULL;
2595 Property::Value* widthValue = NULL;
2596 Property::Value* slantValue = NULL;
2597 weightValue = fontStyleMapGet.Find( "weight" );
2598 widthValue = fontStyleMapGet.Find( "width" );
2599 slantValue = fontStyleMapGet.Find( "slant" );
2600 DALI_TEST_CHECK( !weightValue );
2601 DALI_TEST_CHECK( !widthValue );
2602 DALI_TEST_CHECK( !slantValue );
2607 int UtcDaliTextFieldSettingPlaceholder(void)
2609 ToolkitTestApplication application;
2610 tet_infoline("UtcDaliTextFieldSettingPlaceholder");
2612 TextField field = TextField::New();
2613 DALI_TEST_CHECK( field );
2614 Stage::GetCurrent().Add( field );
2616 // Check the placeholder property with pixel size
2617 Property::Map placeholderPixelSizeMapSet;
2618 Property::Map placeholderPixelSizeMapGet;
2619 Property::Map placeholderFontstyleMap;
2620 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2621 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2622 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::BLUE;
2623 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2624 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::PIXEL_SIZE ] = 15.0f;
2625 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
2627 placeholderFontstyleMap.Insert( "weight", "bold" );
2628 placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2629 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
2631 placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2632 DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
2633 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION );
2635 // Check the placeholder property with point size
2636 Property::Map placeholderMapSet;
2637 Property::Map placeholderMapGet;
2638 placeholderMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2639 placeholderMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2640 placeholderMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::RED;
2641 placeholderMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2642 placeholderMapSet[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
2643 placeholderMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = false;
2645 // Check the placeholder font style property
2646 placeholderFontstyleMap.Clear();
2648 placeholderFontstyleMap.Insert( "weight", "bold" );
2649 placeholderFontstyleMap.Insert( "width", "condensed" );
2650 placeholderFontstyleMap.Insert( "slant", "italic" );
2651 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2652 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2654 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2655 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2656 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2658 // Reset font style.
2659 placeholderFontstyleMap.Clear();
2660 placeholderFontstyleMap.Insert( "weight", "normal" );
2661 placeholderFontstyleMap.Insert( "slant", "oblique" );
2662 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2663 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2665 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2666 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2667 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2669 placeholderFontstyleMap.Clear();
2670 placeholderFontstyleMap.Insert( "slant", "roman" );
2671 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2672 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2674 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2676 placeholderFontstyleMap.Clear();
2677 placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2679 field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2680 placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2681 DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2682 DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );