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 <dali-toolkit/devel-api/controls/text-controls/hidden-input-properties.h>
31 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
32 #include "toolkit-clipboard.h"
35 using namespace Toolkit;
37 void dali_textfield_startup(void)
39 test_return_value = TET_UNDEF;
42 void dali_textfield_cleanup(void)
44 test_return_value = TET_PASS;
50 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
51 const char* const PROPERTY_NAME_TEXT = "text";
52 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT = "placeholderText";
53 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
54 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
55 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
56 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
57 const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength";
58 const char* const PROPERTY_NAME_EXCEED_POLICY = "exceedPolicy";
59 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
60 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment";
61 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
62 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor";
63 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset";
64 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor";
65 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
66 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
67 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
68 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
69 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
70 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
71 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
72 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
73 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
74 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
78 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
79 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
80 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
81 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
82 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
83 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "inputMethodSettings";
84 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
85 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
86 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
87 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
88 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
90 const char* const PROPERTY_NAME_UNDERLINE = "underline";
91 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
92 const char* const PROPERTY_NAME_SHADOW = "shadow";
93 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
94 const char* const PROPERTY_NAME_EMBOSS = "emboss";
95 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
96 const char* const PROPERTY_NAME_OUTLINE = "outline";
97 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
99 const char* const PROPERTY_NAME_HIDDEN_INPUT_SETTINGS = "hiddenInputSettings";
101 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
103 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
104 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
106 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
107 const float RENDER_FRAME_INTERVAL = 16.66f;
109 const float TO_MILLISECONDS = 1000.f;
110 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
112 const float SCROLL_THRESHOLD = 10.f;
113 const float SCROLL_SPEED = 300.f;
115 const unsigned int DEFAULT_FONT_SIZE = 1152u;
116 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
118 const int KEY_A_CODE = 38;
119 const int KEY_D_CODE = 40;
121 static bool gTextChangedCallBackCalled;
122 static bool gMaxCharactersCallBackCalled;
123 static bool gInputStyleChangedCallbackCalled;
124 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
126 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
128 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
129 Integration::ResourcePointer resource(bitmap);
130 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
133 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
137 LoadBitmapResource( app.GetPlatform(), width, height );
139 Property::Map propertyMap;
140 propertyMap["filename"] = "image.png";
141 propertyMap["width"] = width;
142 propertyMap["height"] = height;
143 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
144 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
145 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
146 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
147 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
148 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
149 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
150 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
153 // Generate a PanGestureEvent to send to Core
154 static Integration::PanGestureEvent GeneratePan(
155 Gesture::State state,
156 const Vector2& previousPosition,
157 const Vector2& currentPosition,
158 unsigned long timeDelta,
159 unsigned int numberOfTouches = 1)
161 Integration::PanGestureEvent pan(state);
163 pan.previousPosition = previousPosition;
164 pan.currentPosition = currentPosition;
165 pan.timeDelta = timeDelta;
166 pan.numberOfTouches = numberOfTouches;
172 * Helper to generate PanGestureEvent
174 * @param[in] application Application instance
175 * @param[in] state The Gesture State
176 * @param[in] pos The current position of touch.
178 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
182 if( (state == Gesture::Started) ||
183 (state == Gesture::Possible) )
189 application.ProcessEvent(GeneratePan(state, last, pos, 16));
196 * Simulate time passed by.
198 * @note this will always process at least 1 frame (1/60 sec)
200 * @param application Test application instance
201 * @param duration Time to pass in milliseconds.
202 * @return The actual time passed in milliseconds
204 static int Wait(ToolkitTestApplication& application, int duration = 0)
208 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
210 application.SendNotification();
211 application.Render(RENDER_FRAME_INTERVAL);
212 time += RENDER_FRAME_INTERVAL;
218 Dali::Integration::Point GetPointDownInside( Vector2& pos )
220 Dali::Integration::Point point;
221 point.SetState( PointState::DOWN );
222 point.SetScreenPosition( pos );
226 Dali::Integration::Point GetPointUpInside( Vector2& pos )
228 Dali::Integration::Point point;
229 point.SetState( PointState::UP );
230 point.SetScreenPosition( pos );
234 struct CallbackFunctor
236 CallbackFunctor(bool* callbackFlag)
237 : mCallbackFlag( callbackFlag )
243 *mCallbackFlag = true;
248 static void TestTextChangedCallback( TextField control )
250 tet_infoline(" TestTextChangedCallback");
252 gTextChangedCallBackCalled = true;
255 static void TestMaxLengthReachedCallback( TextField control )
257 tet_infoline(" TestMaxLengthReachedCallback");
259 gMaxCharactersCallBackCalled = true;
262 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
264 tet_infoline(" TestInputStyleChangedCallback");
266 gInputStyleChangedCallbackCalled = true;
267 gInputStyleMask = mask;
270 // Generate a TapGestureEvent to send to Core.
271 Integration::TapGestureEvent GenerateTap(
272 Gesture::State state,
273 unsigned int numberOfTaps,
274 unsigned int numberOfTouches,
277 Integration::TapGestureEvent tap( state );
279 tap.numberOfTaps = numberOfTaps;
280 tap.numberOfTouches = numberOfTouches;
286 Integration::LongPressGestureEvent GenerateLongPress(
287 Gesture::State state,
288 unsigned int numberOfTouches,
291 Integration::LongPressGestureEvent longPress( state );
293 longPress.numberOfTouches = numberOfTouches;
294 longPress.point = point;
298 // Generate a KeyEvent to send to Core.
299 Integration::KeyEvent GenerateKey( const std::string& keyName,
300 const std::string& keyString,
303 unsigned long timeStamp,
304 const Integration::KeyEvent::State& keyState )
306 return Integration::KeyEvent( keyName,
314 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
316 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
318 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
320 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
322 if( valueGet.first.type == Property::Key::STRING )
324 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
325 if( NULL != valueSet )
327 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
329 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
335 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
341 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.indexKey );
342 if( NULL != valueSet )
344 if( valueGet.second.Get<int>() != valueSet->Get<int>() )
346 tet_printf( " Integer Value got : [%d], expected : [%d]", valueGet.second.Get<int>(), valueSet->Get<int>() );
352 tet_printf( " The Int key %d doesn't exist.", valueGet.first.indexKey );
364 int UtcDaliToolkitTextFieldConstructorP(void)
366 ToolkitTestApplication application;
367 tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
369 DALI_TEST_CHECK( !textField );
373 int UtcDaliToolkitTextFieldNewP(void)
375 ToolkitTestApplication application;
376 tet_infoline(" UtcDaliToolkitTextFieldNewP");
377 TextField textField = TextField::New();
378 DALI_TEST_CHECK( textField );
382 int UtcDaliToolkitTextFieldDownCastP(void)
384 ToolkitTestApplication application;
385 tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
386 TextField textField1 = TextField::New();
387 BaseHandle object( textField1 );
389 TextField textField2 = TextField::DownCast( object );
390 DALI_TEST_CHECK( textField2 );
392 TextField textField3 = DownCast< TextField >( object );
393 DALI_TEST_CHECK( textField3 );
397 int UtcDaliToolkitTextFieldDownCastN(void)
399 ToolkitTestApplication application;
400 tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
401 BaseHandle uninitializedObject;
402 TextField textField1 = TextField::DownCast( uninitializedObject );
403 DALI_TEST_CHECK( !textField1 );
405 TextField textField2 = DownCast< TextField >( uninitializedObject );
406 DALI_TEST_CHECK( !textField2 );
410 int UtcDaliToolkitTextFieldCopyConstructorP(void)
412 ToolkitTestApplication application;
413 tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
414 TextField textField = TextField::New();
415 textField.SetProperty( TextField::Property::TEXT, "Test" );
417 TextField copy( textField );
418 DALI_TEST_CHECK( copy );
419 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
423 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
425 ToolkitTestApplication application;
426 tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
427 TextField textField = TextField::New();
428 textField.SetProperty( TextField::Property::TEXT, "Test" );
430 TextField copy = textField;
431 DALI_TEST_CHECK( copy );
432 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
436 int UtcDaliTextFieldNewP(void)
438 ToolkitTestApplication application;
439 tet_infoline(" UtcDaliToolkitTextFieldNewP");
440 TextField textField = TextField::New();
441 DALI_TEST_CHECK( textField );
445 // Positive test case for a method
446 int UtcDaliTextFieldGetPropertyP(void)
448 ToolkitTestApplication application;
449 tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
450 TextField field = TextField::New();
451 DALI_TEST_CHECK( field );
453 // Check Property Indices are correct
454 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND );
455 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
456 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
457 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
458 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
459 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
460 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
461 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
462 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
463 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
464 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
465 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
466 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
467 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextField::Property::SHADOW_OFFSET );
468 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextField::Property::SHADOW_COLOR );
469 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
470 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
471 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
472 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
473 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
474 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
475 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
476 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
477 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
478 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
479 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
480 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
481 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
482 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
483 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
484 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
485 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
486 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
487 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
488 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
489 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
490 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
491 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
492 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
493 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
494 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
495 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
496 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
497 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
498 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
499 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
500 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
501 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HIDDEN_INPUT_SETTINGS ) == DevelTextField::Property::HIDDEN_INPUT_SETTINGS );
506 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
509 Property::Map imageMap;
510 imageMap[mapKey] =mapValue;
512 field.SetProperty( property , imageMap );
513 Property::Value propValue = field.GetProperty( property );
514 Property::Map* resultMap = propValue.GetMap();
516 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
524 // Positive test case for a method
525 int UtcDaliTextFieldSetPropertyP(void)
527 ToolkitTestApplication application;
528 tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
529 TextField field = TextField::New();
530 DALI_TEST_CHECK( field );
531 Stage::GetCurrent().Add( field );
533 // Note - we can't check the defaults since the stylesheets are platform-specific
535 // Check the render backend property.
536 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
537 DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty<int>( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
539 // Check text property.
540 field.SetProperty( TextField::Property::TEXT, "Setting Text" );
541 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
543 // Check placeholder text properties.
544 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
545 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
547 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
548 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
550 // Check font properties.
551 field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
552 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
554 Property::Map fontStyleMapSet;
555 Property::Map fontStyleMapGet;
556 Property::Value* slantValue = NULL;
558 fontStyleMapSet.Insert( "weight", "bold" );
559 fontStyleMapSet.Insert( "width", "condensed" );
560 fontStyleMapSet.Insert( "slant", "italic" );
561 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
563 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
564 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
565 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
567 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
568 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
571 fontStyleMapSet.Clear();
572 fontStyleMapSet.Insert( "weight", "normal" );
573 fontStyleMapSet.Insert( "slant", "oblique" );
574 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
576 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
577 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
578 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
580 fontStyleMapSet.Clear();
581 fontStyleMapSet.Insert( "slant", "roman" );
582 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
583 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
585 // Replace 'roman' for 'normal'.
586 slantValue = fontStyleMapGet.Find( "slant" );
587 if( NULL != slantValue )
589 if( "normal" == slantValue->Get<std::string>() )
591 fontStyleMapGet["slant"] = "roman";
594 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
595 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
597 fontStyleMapSet.Clear();
599 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
600 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
601 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
602 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
604 // Check that the MAX_LENGTH property can be correctly set
605 const int maxNumberOfCharacters = 20;
606 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
607 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
609 // Check exceed policy
610 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP );
611 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION );
612 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
613 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
615 // Check that the Alignment properties can be correctly set
616 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
617 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
618 field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
619 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
621 // Check text's color property
622 field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
623 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
625 // Check placeholder text's color property.
626 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
627 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
629 // Check shadow properties.
630 field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
631 DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
632 field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
633 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
635 // Check cursor properties
636 field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
637 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
638 field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
639 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
641 field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
642 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
643 field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
644 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
645 field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
646 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
647 field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
648 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
650 // Check scroll properties.
651 field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
652 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
653 field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
654 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
656 // Check handle images
657 field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
658 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
659 field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
660 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
661 field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
663 // Check handle images
664 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
665 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
666 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
667 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
668 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
669 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
671 // Check the highlight color
672 field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
673 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
675 // Decoration bounding box
676 field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
677 DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
679 // Check the input method setting
680 Property::Map propertyMap;
681 InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
682 InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
683 InputMethod::ActionButtonTitle::Type actionButton = InputMethod::ActionButtonTitle::GO;
684 int inputVariation = 1;
685 propertyMap["PANEL_LAYOUT"] = panelLayout;
686 propertyMap["AUTO_CAPITALISE"] = autoCapital;
687 propertyMap["ACTION_BUTTON"] = actionButton;
688 propertyMap["VARIATION"] = inputVariation;
689 field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
691 Property::Value value = field.GetProperty( TextField::Property::INPUT_METHOD_SETTINGS );
693 DALI_TEST_CHECK( value.Get( map ) );
696 DALI_TEST_CHECK( map[ "PANEL_LAYOUT" ].Get( layout ) );
697 DALI_TEST_EQUALS( static_cast<int>(panelLayout), layout, TEST_LOCATION );
700 DALI_TEST_CHECK( map[ "AUTO_CAPITALISE" ].Get( capital ) );
701 DALI_TEST_EQUALS( static_cast<int>(autoCapital), capital, TEST_LOCATION );
704 DALI_TEST_CHECK( map[ "ACTION_BUTTON" ].Get( action ) );
705 DALI_TEST_EQUALS( static_cast<int>(actionButton), action, TEST_LOCATION );
708 DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) );
709 DALI_TEST_EQUALS( inputVariation, variation, TEST_LOCATION );
711 // Check input color property.
712 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
713 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
715 // Check the enable markup property.
716 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
717 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
718 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
720 // Check input font properties.
721 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
722 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
724 fontStyleMapSet.Clear();
725 fontStyleMapSet.Insert( "weight", "bold" );
726 fontStyleMapSet.Insert( "width", "condensed" );
727 fontStyleMapSet.Insert( "slant", "italic" );
729 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
730 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
731 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
732 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
734 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
735 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
737 // Reset input font style.
738 fontStyleMapSet.Clear();
739 fontStyleMapSet.Insert( "weight", "normal" );
740 fontStyleMapSet.Insert( "slant", "oblique" );
742 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
743 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
744 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
745 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
747 fontStyleMapSet.Clear();
748 fontStyleMapSet.Insert( "slant", "roman" );
750 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
751 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
753 // Replace 'roman' for 'normal'.
754 slantValue = fontStyleMapGet.Find( "slant" );
755 if( NULL != slantValue )
757 if( "normal" == slantValue->Get<std::string>() )
759 fontStyleMapGet["slant"] = "roman";
762 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
763 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
765 fontStyleMapSet.Clear();
767 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
768 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
769 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
770 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
772 Property::Map underlineMapSet;
773 Property::Map underlineMapGet;
775 underlineMapSet.Insert( "enable", "true" );
776 underlineMapSet.Insert( "color", "red" );
777 underlineMapSet.Insert( "height", "1" );
779 // Check the underline property
780 field.SetProperty( TextField::Property::UNDERLINE, underlineMapSet );
782 underlineMapGet = field.GetProperty<Property::Map>( TextField::Property::UNDERLINE );
783 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
784 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
786 // Check the input underline property
787 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
788 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
790 // Check the shadow property
791 Property::Map shadowMapSet;
792 Property::Map shadowMapGet;
794 shadowMapSet.Insert( "color", "green" );
795 shadowMapSet.Insert( "offset", "2 2" );
797 field.SetProperty( TextField::Property::SHADOW, shadowMapSet );
799 shadowMapGet = field.GetProperty<Property::Map>( TextField::Property::SHADOW );
800 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
801 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
803 // Check the input shadow property
804 field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
805 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
807 // Check the emboss property
808 field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
809 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
811 // Check the input emboss property
812 field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
813 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
815 // Check the outline property
816 field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
817 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
819 // Check the input outline property
820 field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
821 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
823 // Check the hidden input settings property
824 Property::Map hiddenMapSet;
825 Property::Map hiddenMapGet;
826 hiddenMapSet[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
827 hiddenMapSet[ HiddenInput::Property::SHOW_DURATION ] = 2;
828 hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 4;
829 hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
830 field.SetProperty( DevelTextField::Property::HIDDEN_INPUT_SETTINGS, hiddenMapSet );
832 hiddenMapGet = field.GetProperty<Property::Map>( DevelTextField::Property::HIDDEN_INPUT_SETTINGS );
833 DALI_TEST_EQUALS( hiddenMapSet.Count(), hiddenMapGet.Count(), TEST_LOCATION );
834 DALI_TEST_EQUALS( DaliTestCheckMaps( hiddenMapSet, hiddenMapGet ), true, TEST_LOCATION );
839 // Positive Atlas Text Renderer test
840 int utcDaliTextFieldAtlasRenderP(void)
842 ToolkitTestApplication application;
843 tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
844 StyleManager styleManager = StyleManager::Get();
845 styleManager.ApplyDefaultTheme();
846 TextField field = TextField::New();
847 DALI_TEST_CHECK( field );
849 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
851 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
853 Stage::GetCurrent().Add( field );
857 // Render some text with the shared atlas backend
858 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
859 application.SendNotification();
860 application.Render();
864 tet_result(TET_FAIL);
869 // Positive test for the textChanged signal.
870 int utcDaliTextFieldTextChangedP(void)
872 ToolkitTestApplication application;
873 tet_infoline(" utcDaliTextFieldTextChangedP");
874 TextField field = TextField::New();
875 DALI_TEST_CHECK( field );
877 Stage::GetCurrent().Add( field );
879 // connect to the text changed signal.
880 ConnectionTracker* testTracker = new ConnectionTracker();
881 field.TextChangedSignal().Connect(&TestTextChangedCallback);
882 bool textChangedSignal = false;
883 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
885 gTextChangedCallBackCalled = false;
886 field.SetProperty( TextField::Property::TEXT, "ABC" );
887 DALI_TEST_CHECK( gTextChangedCallBackCalled );
888 DALI_TEST_CHECK( textChangedSignal );
890 application.SendNotification();
892 field.SetKeyInputFocus();
894 gTextChangedCallBackCalled = false;
895 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
896 DALI_TEST_CHECK( gTextChangedCallBackCalled );
901 // Negative test for the textChanged signal.
902 int utcDaliTextFieldTextChangedN(void)
904 ToolkitTestApplication application;
905 tet_infoline(" utcDaliTextFieldTextChangedN");
906 TextField field = TextField::New();
907 DALI_TEST_CHECK( field );
909 Stage::GetCurrent().Add( field );
911 // connect to the text changed signal.
912 ConnectionTracker* testTracker = new ConnectionTracker();
913 field.TextChangedSignal().Connect(&TestTextChangedCallback);
914 bool textChangedSignal = false;
915 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
917 gTextChangedCallBackCalled = false;
918 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
919 DALI_TEST_CHECK( !gTextChangedCallBackCalled );
920 DALI_TEST_CHECK( !textChangedSignal );
925 // Positive test for Max Characters reached signal.
926 int utcDaliTextFieldMaxCharactersReachedP(void)
928 ToolkitTestApplication application;
929 tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
930 TextField field = TextField::New();
931 DALI_TEST_CHECK( field );
933 Stage::GetCurrent().Add( field );
935 const int maxNumberOfCharacters = 1;
936 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
938 field.SetKeyInputFocus();
940 // connect to the text changed signal.
941 ConnectionTracker* testTracker = new ConnectionTracker();
942 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
943 bool maxLengthReachedSignal = false;
944 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
946 gMaxCharactersCallBackCalled = false;
948 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
949 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
951 DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
952 DALI_TEST_CHECK( maxLengthReachedSignal );
957 // Negative test for Max Characters reached signal.
958 int utcDaliTextFieldMaxCharactersReachedN(void)
960 ToolkitTestApplication application;
961 tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
962 TextField field = TextField::New();
963 DALI_TEST_CHECK( field );
965 Stage::GetCurrent().Add( field );
967 const int maxNumberOfCharacters = 3;
968 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
970 field.SetKeyInputFocus();
972 // connect to the text changed signal.
973 ConnectionTracker* testTracker = new ConnectionTracker();
974 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
975 bool maxLengthReachedSignal = false;
976 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
978 gMaxCharactersCallBackCalled = false;
980 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
981 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
983 DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
984 DALI_TEST_CHECK( !maxLengthReachedSignal );
989 int utcDaliTextFieldInputStyleChanged01(void)
991 ToolkitTestApplication application;
992 tet_infoline(" utcDaliTextFieldInputStyleChanged01");
994 // The text-field emits signals when the input style changes. These changes of style are
995 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
996 // can't be emitted during the size negotiation as the callbacks may update the UI.
997 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
998 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
999 application.CreateAdaptor();
1003 char* pathNamePtr = get_current_dir_name();
1004 const std::string pathName( pathNamePtr );
1005 free( pathNamePtr );
1007 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1008 fontClient.SetDpi( 93u, 93u );
1010 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1011 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1013 TextField field = TextField::New();
1014 DALI_TEST_CHECK( field );
1017 field.SetSize( 300.f, 50.f );
1018 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1019 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1021 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1022 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
1024 // connect to the text changed signal.
1025 ConnectionTracker* testTracker = new ConnectionTracker();
1026 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1027 bool inputStyleChangedSignal = false;
1028 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1030 Stage::GetCurrent().Add( field );
1032 // Render and notify
1033 application.SendNotification();
1034 application.Render();
1036 // Executes the idle callbacks added by the text control on the change of input style.
1037 application.RunIdles();
1039 gInputStyleChangedCallbackCalled = false;
1040 gInputStyleMask = TextField::InputStyle::NONE;
1041 inputStyleChangedSignal = false;
1043 // Create a tap event to touch the text field.
1044 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1045 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1047 // Render and notify
1048 application.SendNotification();
1049 application.Render();
1051 // Executes the idle callbacks added by the text control on the change of input style.
1052 application.RunIdles();
1054 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1055 if( gInputStyleChangedCallbackCalled )
1057 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
1059 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1060 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1062 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1063 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1065 DALI_TEST_CHECK( inputStyleChangedSignal );
1067 gInputStyleChangedCallbackCalled = false;
1068 gInputStyleMask = TextField::InputStyle::NONE;
1069 inputStyleChangedSignal = false;
1071 // Create a tap event to touch the text field.
1072 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1073 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1075 // Render and notify
1076 application.SendNotification();
1077 application.Render();
1079 // Executes the idle callbacks added by the text control on the change of input style.
1080 application.RunIdles();
1082 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1083 DALI_TEST_CHECK( !inputStyleChangedSignal );
1085 gInputStyleChangedCallbackCalled = false;
1086 gInputStyleMask = TextField::InputStyle::NONE;
1087 inputStyleChangedSignal = false;
1089 // Create a tap event to touch the text field.
1090 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1091 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1093 // Render and notify
1094 application.SendNotification();
1095 application.Render();
1097 // Executes the idle callbacks added by the text control on the change of input style.
1098 application.RunIdles();
1100 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1101 if( gInputStyleChangedCallbackCalled )
1103 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1105 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1106 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1108 DALI_TEST_CHECK( inputStyleChangedSignal );
1110 gInputStyleChangedCallbackCalled = false;
1111 gInputStyleMask = TextField::InputStyle::NONE;
1112 inputStyleChangedSignal = false;
1114 // Create a tap event to touch the text field.
1115 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1116 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1118 // Render and notify
1119 application.SendNotification();
1120 application.Render();
1122 // Executes the idle callbacks added by the text control on the change of input style.
1123 application.RunIdles();
1125 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1126 if( gInputStyleChangedCallbackCalled )
1128 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1130 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1131 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1133 const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1135 Property::Map fontStyleMapSet;
1136 fontStyleMapSet.Insert( "weight", "bold" );
1138 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1139 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1141 DALI_TEST_CHECK( inputStyleChangedSignal );
1143 gInputStyleChangedCallbackCalled = false;
1144 gInputStyleMask = TextField::InputStyle::NONE;
1145 inputStyleChangedSignal = false;
1147 // Create a tap event to touch the text field.
1148 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1149 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1151 // Render and notify
1152 application.SendNotification();
1153 application.Render();
1155 // Executes the idle callbacks added by the text control on the change of input style.
1156 application.RunIdles();
1158 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1159 DALI_TEST_CHECK( !inputStyleChangedSignal );
1161 gInputStyleChangedCallbackCalled = false;
1162 gInputStyleMask = TextField::InputStyle::NONE;
1163 inputStyleChangedSignal = false;
1165 // Create a tap event to touch the text field.
1166 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1167 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1169 // Render and notify
1170 application.SendNotification();
1171 application.Render();
1173 // Executes the idle callbacks added by the text control on the change of input style.
1174 application.RunIdles();
1176 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1177 if( gInputStyleChangedCallbackCalled )
1179 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1181 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1182 DALI_TEST_CHECK( style.empty() );
1184 DALI_TEST_CHECK( inputStyleChangedSignal );
1186 gInputStyleChangedCallbackCalled = false;
1187 gInputStyleMask = TextField::InputStyle::NONE;
1188 inputStyleChangedSignal = false;
1190 // Create a tap event to touch the text field.
1191 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1192 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1194 // Render and notify
1195 application.SendNotification();
1196 application.Render();
1198 // Executes the idle callbacks added by the text control on the change of input style.
1199 application.RunIdles();
1201 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1202 DALI_TEST_CHECK( !inputStyleChangedSignal );
1207 int utcDaliTextFieldInputStyleChanged02(void)
1209 ToolkitTestApplication application;
1210 tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1212 // The text-field emits signals when the input style changes. These changes of style are
1213 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1214 // can't be emitted during the size negotiation as the callbacks may update the UI.
1215 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1216 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1217 application.CreateAdaptor();
1221 char* pathNamePtr = get_current_dir_name();
1222 const std::string pathName( pathNamePtr );
1223 free( pathNamePtr );
1225 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1226 fontClient.SetDpi( 93u, 93u );
1228 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1229 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1231 TextField field = TextField::New();
1232 DALI_TEST_CHECK( field );
1235 field.SetSize( 300.f, 50.f );
1236 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1237 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1239 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1240 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>" );
1242 // connect to the text changed signal.
1243 ConnectionTracker* testTracker = new ConnectionTracker();
1244 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1245 bool inputStyleChangedSignal = false;
1246 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1248 Stage::GetCurrent().Add( field );
1250 // Render and notify
1251 application.SendNotification();
1252 application.Render();
1254 // Executes the idle callbacks added by the text control on the change of input style.
1255 application.RunIdles();
1257 gInputStyleChangedCallbackCalled = false;
1258 gInputStyleMask = TextField::InputStyle::NONE;
1259 inputStyleChangedSignal = false;
1261 // Create a tap event to touch the text field.
1262 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1263 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1264 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1265 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1267 // Render and notify
1268 application.SendNotification();
1269 application.Render();
1271 // Executes the idle callbacks added by the text control on the change of input style.
1272 application.RunIdles();
1274 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1275 if( gInputStyleChangedCallbackCalled )
1277 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1278 static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1279 TextField::InputStyle::POINT_SIZE |
1280 TextField::InputStyle::COLOR ),
1283 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1284 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1286 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1287 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1289 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1290 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1292 DALI_TEST_CHECK( inputStyleChangedSignal );
1294 gInputStyleChangedCallbackCalled = false;
1295 gInputStyleMask = TextField::InputStyle::NONE;
1296 inputStyleChangedSignal = false;
1298 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1300 // Render and notify
1301 application.SendNotification();
1302 application.Render();
1304 // Executes the idle callbacks added by the text control on the change of input style.
1305 application.RunIdles();
1307 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1308 if( gInputStyleChangedCallbackCalled )
1310 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1311 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1314 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1315 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1317 DALI_TEST_CHECK( inputStyleChangedSignal );
1319 gInputStyleChangedCallbackCalled = false;
1320 gInputStyleMask = TextField::InputStyle::NONE;
1321 inputStyleChangedSignal = false;
1323 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1325 // Render and notify
1326 application.SendNotification();
1327 application.Render();
1329 // Executes the idle callbacks added by the text control on the change of input style.
1330 application.RunIdles();
1332 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1333 DALI_TEST_CHECK( !inputStyleChangedSignal );
1335 gInputStyleChangedCallbackCalled = false;
1336 gInputStyleMask = TextField::InputStyle::NONE;
1337 inputStyleChangedSignal = false;
1339 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1341 // Render and notify
1342 application.SendNotification();
1343 application.Render();
1345 // Executes the idle callbacks added by the text control on the change of input style.
1346 application.RunIdles();
1348 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1349 if( gInputStyleChangedCallbackCalled )
1351 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1352 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1355 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1356 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1358 DALI_TEST_CHECK( inputStyleChangedSignal );
1360 gInputStyleChangedCallbackCalled = false;
1361 gInputStyleMask = TextField::InputStyle::NONE;
1362 inputStyleChangedSignal = false;
1364 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1366 Property::Map fontStyleMapSet;
1367 fontStyleMapSet.Insert( "weight", "thin" );
1368 fontStyleMapSet.Insert( "width", "condensed" );
1369 fontStyleMapSet.Insert( "slant", "italic" );
1371 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1372 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1374 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1375 field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1376 field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1377 field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1379 // Render and notify
1380 application.SendNotification();
1381 application.Render();
1383 // Executes the idle callbacks added by the text control on the change of input style.
1384 application.RunIdles();
1386 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1387 DALI_TEST_CHECK( !inputStyleChangedSignal );
1389 // Create a tap event to touch the text field.
1390 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1391 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1393 // Render and notify
1394 application.SendNotification();
1395 application.Render();
1397 // Executes the idle callbacks added by the text control on the change of input style.
1398 application.RunIdles();
1400 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1401 if( gInputStyleChangedCallbackCalled )
1403 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1404 static_cast<unsigned int>( TextField::InputStyle::COLOR |
1405 TextField::InputStyle::POINT_SIZE |
1406 TextField::InputStyle::FONT_STYLE |
1407 TextField::InputStyle::UNDERLINE |
1408 TextField::InputStyle::SHADOW |
1409 TextField::InputStyle::EMBOSS |
1410 TextField::InputStyle::OUTLINE ),
1413 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1414 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1416 DALI_TEST_CHECK( inputStyleChangedSignal );
1421 int utcDaliTextFieldEvent01(void)
1423 ToolkitTestApplication application;
1424 tet_infoline(" utcDaliTextFieldEvent01");
1426 // Creates a tap event. After creating a tap event the text field should
1427 // have the focus and add text with key events should be possible.
1429 TextField field = TextField::New();
1430 DALI_TEST_CHECK( field );
1432 Stage::GetCurrent().Add( field );
1434 field.SetSize( 300.f, 50.f );
1435 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1436 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1438 // Avoid a crash when core load gl resources.
1439 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1441 // Render and notify
1442 application.SendNotification();
1443 application.Render();
1445 // Add a key event but as the text field has not the focus it should do nothing.
1446 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1448 // Render and notify
1449 application.SendNotification();
1450 application.Render();
1452 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1454 // Create a tap event to touch the text field.
1455 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1456 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1458 // Render and notify
1459 application.SendNotification();
1460 application.Render();
1462 // Now the text field has the focus, so it can handle the key events.
1463 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1464 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1466 // Render and notify
1467 application.SendNotification();
1468 application.Render();
1470 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1472 // Create a second text field and send key events to it.
1473 TextField field2 = TextField::New();
1475 field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1476 field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1477 field2.SetSize( 100.f, 100.f );
1478 field2.SetPosition( 100.f, 100.f );
1480 Stage::GetCurrent().Add( field2 );
1482 // Render and notify
1483 application.SendNotification();
1484 application.Render();
1486 // Create a tap event on the second text field.
1487 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1488 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1490 // Render and notify
1491 application.SendNotification();
1492 application.Render();
1494 // The second text field has the focus. It should handle the key events.
1495 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1496 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1498 // Render and notify
1499 application.SendNotification();
1500 application.Render();
1502 // Check the text has been added to the second text field.
1503 DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1508 int utcDaliTextFieldEvent02(void)
1510 ToolkitTestApplication application;
1511 tet_infoline(" utcDaliTextFieldEvent02");
1513 // Checks if the right number of actors are created.
1515 TextField field = TextField::New();
1516 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1517 DALI_TEST_CHECK( field );
1518 LoadMarkerImages(application, field);
1520 Stage::GetCurrent().Add( field );
1522 field.SetSize( 300.f, 50.f );
1523 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1524 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1526 // Avoid a crash when core load gl resources.
1527 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1529 // Render and notify
1530 application.SendNotification();
1531 application.Render();
1533 // Check there are the expected number of children ( stencil ).
1534 DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1536 Actor stencil = field.GetChildAt( 0u );
1537 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1539 // Create a tap event to touch the text field.
1540 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1541 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1543 // Render and notify
1544 application.SendNotification();
1545 application.Render();
1547 Actor layer = field.GetChildAt( 1u );
1548 DALI_TEST_CHECK( layer.IsLayer() );
1550 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1551 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1553 // Now the text field has the focus, so it can handle the key events.
1554 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1555 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1557 // Render and notify
1558 application.SendNotification();
1559 application.Render();
1561 // Checks the cursor and the renderer have been created.
1562 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1563 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1565 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1566 DALI_TEST_CHECK( cursor );
1568 // The offscreen root actor has a container with all the actors which contain the text renderers.
1569 Actor container = stencil.GetChildAt( 0u );
1570 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1572 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1573 DALI_TEST_CHECK( renderer );
1576 // Move the cursor and check the position changes.
1577 Vector3 position1 = cursor.GetCurrentPosition();
1579 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1580 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1582 // Render and notify
1583 application.SendNotification();
1584 application.Render();
1586 Vector3 position2 = cursor.GetCurrentPosition();
1588 DALI_TEST_CHECK( position2.x < position1.x );
1590 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1591 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1593 // Render and notify
1594 application.SendNotification();
1595 application.Render();
1597 Vector3 position3 = cursor.GetCurrentPosition();
1599 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1601 // Send some taps and check the cursor positions.
1603 // Try to tap at the beginning.
1604 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1605 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1607 // Render and notify
1608 application.SendNotification();
1609 application.Render();
1611 // Cursor position should be the same than position1.
1612 Vector3 position4 = cursor.GetCurrentPosition();
1614 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1616 // Tap away from the start position.
1617 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1618 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1620 // Render and notify
1621 application.SendNotification();
1622 application.Render();
1624 Vector3 position5 = cursor.GetCurrentPosition();
1626 DALI_TEST_CHECK( position5.x > position4.x );
1628 // Remove all the text.
1629 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1630 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1631 field.SetProperty( TextField::Property::TEXT, "" );
1633 // Render and notify
1634 application.SendNotification();
1635 application.Render();
1637 // Cursor position should be the same than position2.
1638 Vector3 position6 = cursor.GetCurrentPosition();
1640 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1642 // Should not be a renderer.
1643 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1648 int utcDaliTextFieldEvent03(void)
1650 ToolkitTestApplication application;
1651 tet_infoline(" utcDaliTextFieldEvent03");
1653 // Checks if the highlight actor is created.
1655 TextField field = TextField::New();
1656 DALI_TEST_CHECK( field );
1658 Stage::GetCurrent().Add( field );
1660 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1661 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1662 field.SetSize( 30.f, 50.f );
1663 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1664 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1666 // Avoid a crash when core load gl resources.
1667 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1668 LoadMarkerImages(application, field);
1670 // Render and notify
1671 application.SendNotification();
1672 application.Render();
1674 // Tap first to get the focus.
1675 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1676 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1678 // Render and notify
1679 application.SendNotification();
1680 application.Render();
1682 // Double tap to select a word.
1683 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1684 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1686 // Render and notify
1687 application.SendNotification();
1688 application.Render();
1690 // The offscreen root actor should have two actors: the renderer and the highlight actor.
1691 Actor stencil = field.GetChildAt( 0u );
1693 // The offscreen root actor has a container with all the actors which contain the text renderers.
1694 Actor container = stencil.GetChildAt( 0u );
1695 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1697 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1698 DALI_TEST_CHECK( renderer );
1701 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1702 DALI_TEST_CHECK( highlight );
1707 int utcDaliTextFieldEvent04(void)
1709 ToolkitTestApplication application;
1710 tet_infoline(" utcDaliTextFieldEvent04");
1712 // Checks if the highlight actor is created.
1714 TextField field = TextField::New();
1715 DALI_TEST_CHECK( field );
1716 Stage::GetCurrent().Add( field );
1717 LoadMarkerImages(application, field);
1718 // Render and notify
1719 application.SendNotification();
1720 application.Render();
1722 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1723 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1724 field.SetSize( 300.f, 50.f );
1725 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1726 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1728 // Avoid a crash when core load gl resources.
1729 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1730 // Render and notify
1731 application.SendNotification();
1732 application.Render();
1734 // Create a tap event to touch the text field.
1735 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1736 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1737 // Render and notify
1738 application.SendNotification();
1739 application.Render();
1742 // Tap first to get the focus.
1743 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1744 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1746 // Render and notify
1747 application.SendNotification();
1748 application.Render();
1750 // Double tap to select a word.
1751 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1752 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1754 // Render and notify
1755 application.SendNotification();
1756 application.Render();
1759 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1760 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1764 int utcDaliTextFieldEvent05(void)
1766 ToolkitTestApplication application;
1767 tet_infoline(" utcDaliTextFieldEvent05");
1769 // Checks dragging of cursor/grab handle
1771 TextField field = TextField::New();
1772 DALI_TEST_CHECK( field );
1773 Stage::GetCurrent().Add( field );
1774 LoadMarkerImages(application, field);
1775 // Render and notify
1776 application.SendNotification();
1777 application.Render();
1779 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1780 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1781 field.SetSize( 300.f, 50.f );
1782 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1783 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1785 // Avoid a crash when core load gl resources.
1786 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1787 // Render and notify
1788 application.SendNotification();
1789 application.Render();
1791 // Create a tap event to touch the text field.
1792 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1793 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1794 // Render and notify
1795 application.SendNotification();
1796 application.Render();
1799 // Tap first to get the focus.
1800 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1801 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1803 // Render and notify
1804 application.SendNotification();
1805 application.Render();
1807 // Double tap to select a word.
1808 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1809 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1811 // Render and notify
1812 application.SendNotification();
1813 application.Render();
1815 // drag grab handle right
1816 Vector2 pos(0.0f, 40.0f);
1817 SendPan(application, Gesture::Possible, pos);
1818 SendPan(application, Gesture::Started, pos);
1820 Wait(application, 100);
1822 for(int i = 0;i<20;i++)
1824 SendPan(application, Gesture::Continuing, pos);
1829 SendPan(application, Gesture::Finished, pos);
1830 Wait(application, RENDER_FRAME_INTERVAL);
1832 Actor stencil = field.GetChildAt( 1u );
1836 int utcDaliTextFieldEvent06(void)
1838 ToolkitTestApplication application;
1839 tet_infoline(" utcDaliTextFieldEvent06");
1841 // Checks Longpress when in edit mode
1843 TextField field = TextField::New();
1844 DALI_TEST_CHECK( field );
1845 Stage::GetCurrent().Add( field );
1846 LoadMarkerImages(application, field);
1847 // Render and notify
1848 application.SendNotification();
1849 application.Render();
1851 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1852 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1853 field.SetSize( 300.f, 50.f );
1854 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1855 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1857 // Avoid a crash when core load gl resources.
1858 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1859 // Render and notify
1860 application.SendNotification();
1861 application.Render();
1863 // Create a tap event to touch the text field.
1864 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1865 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1866 // Render and notify
1867 application.SendNotification();
1868 application.Render();
1871 // Tap first to get the focus.
1872 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1873 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1875 // Render and notify
1876 application.SendNotification();
1877 application.Render();
1880 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1881 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1883 // Render and notify
1884 application.SendNotification();
1885 application.Render();
1890 int utcDaliTextFieldEvent07(void)
1892 ToolkitTestApplication application;
1893 tet_infoline(" utcDaliTextFieldEvent07");
1895 // Checks Longpress to start edit mode
1897 TextField field = TextField::New();
1898 DALI_TEST_CHECK( field );
1899 Stage::GetCurrent().Add( field );
1900 LoadMarkerImages(application, field);
1901 // Render and notify
1902 application.SendNotification();
1903 application.Render();
1905 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1906 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1907 field.SetSize( 300.f, 50.f );
1908 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1909 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1910 Property::Map propertyMap;
1911 propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD;
1912 field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
1914 // Avoid a crash when core load gl resources.
1915 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1916 // Render and notify
1917 application.SendNotification();
1918 application.Render();
1921 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1922 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1924 // Render and notify
1925 application.SendNotification();
1926 application.Render();
1931 int utcDaliTextFieldEvent08(void)
1933 ToolkitTestApplication application;
1934 tet_infoline(" utcDaliTextFieldEvent08");
1936 Dali::Clipboard clipboard = Clipboard::Get();
1937 clipboard.SetItem("testTextFieldEvent");
1939 // Checks Longpress when only place holder text
1941 TextField field = TextField::New();
1942 DALI_TEST_CHECK( field );
1943 Stage::GetCurrent().Add( field );
1944 LoadMarkerImages(application, field);
1945 // Render and notify
1946 application.SendNotification();
1947 application.Render();
1949 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
1950 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1951 field.SetSize( 300.f, 50.f );
1952 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1953 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1955 // Avoid a crash when core load gl resources.
1956 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1957 // Render and notify
1958 application.SendNotification();
1959 application.Render();
1962 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1963 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1965 // Render and notify
1966 application.SendNotification();
1967 application.Render();
1969 Wait(application, 500);
1972 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1973 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1975 // Render and notify
1976 application.SendNotification();
1977 application.Render();
1979 Wait(application, 500);
1981 Stage stage = Stage::GetCurrent();
1982 Layer layer = stage.GetRootLayer();
1983 Actor actor = layer.FindChildByName("optionPaste");
1987 Vector3 worldPosition = actor.GetCurrentWorldPosition();
1988 Vector2 halfStageSize = stage.GetSize() / 2.0f;
1989 Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
1991 Dali::Integration::TouchEvent event;
1992 event = Dali::Integration::TouchEvent();
1993 event.AddPoint( GetPointDownInside( position ) );
1994 application.ProcessEvent( event );
1996 event = Dali::Integration::TouchEvent();
1997 event.AddPoint( GetPointUpInside( position ) );
1998 application.ProcessEvent( event );
2000 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
2005 int utcDaliTextFieldEvent09(void)
2007 ToolkitTestApplication application;
2008 tet_infoline(" utcDaliTextFieldEvent09");
2010 TextField field = TextField::New();
2011 DALI_TEST_CHECK( field );
2012 Stage::GetCurrent().Add( field );
2013 LoadMarkerImages(application, field);
2014 // Render and notify
2015 application.SendNotification();
2016 application.Render();
2018 field.SetProperty( TextField::Property::TEXT, "Hello" );
2019 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2020 field.SetSize( 300.f, 50.f );
2021 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2022 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2024 // Avoid a crash when core load gl resources.
2025 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2027 // Create a tap event to touch the text field.
2028 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2029 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2030 application.SendNotification();
2031 application.Render();
2034 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE;
2035 field.SetProperty( DevelTextField::Property::HIDDEN_INPUT_SETTINGS, map );
2036 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
2037 application.SendNotification();
2038 application.Render();
2040 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
2041 map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
2042 field.SetProperty( DevelTextField::Property::HIDDEN_INPUT_SETTINGS, map );
2043 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
2044 application.SendNotification();
2045 application.Render();
2047 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_COUNT;
2048 map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2049 field.SetProperty( DevelTextField::Property::HIDDEN_INPUT_SETTINGS, map );
2050 for( unsigned int index = 0u; index < 5u; ++index )
2052 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
2053 application.SendNotification();
2054 application.Render();
2057 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT;
2058 map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2059 field.SetProperty( DevelTextField::Property::HIDDEN_INPUT_SETTINGS, map );
2060 for( unsigned int index = 0u; index < 5u; ++index )
2062 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
2063 application.SendNotification();
2064 application.Render();
2067 map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER;
2068 map[ HiddenInput::Property::SHOW_DURATION ] = 0;
2069 field.SetProperty( DevelTextField::Property::HIDDEN_INPUT_SETTINGS, map );
2070 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
2071 application.SendNotification();
2072 application.Render();
2073 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
2074 application.SendNotification();
2075 application.Render();
2077 map[ HiddenInput::Property::SHOW_DURATION ] = 100;
2078 field.SetProperty( DevelTextField::Property::HIDDEN_INPUT_SETTINGS, map );
2079 application.ProcessEvent( GenerateKey( "d", "d", 0, 0, 0, Integration::KeyEvent::Down ) );
2080 application.SendNotification();
2081 application.Render();
2083 Property::Map mapGet;
2084 mapGet = field.GetProperty<Property::Map>( DevelTextField::Property::HIDDEN_INPUT_SETTINGS );
2085 DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION );
2086 DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION );
2091 int utcDaliTextFieldStyleWhilstSelected(void)
2093 ToolkitTestApplication application;
2094 tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
2096 // Change font and styles whilst text is selected whilst word selected
2098 TextField field = TextField::New();
2099 DALI_TEST_CHECK( field );
2100 Stage::GetCurrent().Add( field );
2101 LoadMarkerImages(application, field);
2102 // Render and notify
2103 application.SendNotification();
2104 application.Render();
2106 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2107 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2108 field.SetSize( 300.f, 50.f );
2109 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2110 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2112 // Avoid a crash when core load gl resources.
2113 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2114 // Render and notify
2115 application.SendNotification();
2116 application.Render();
2118 // Create a tap event to touch the text field.
2119 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2120 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2121 // Render and notify
2122 application.SendNotification();
2123 application.Render();
2126 // Tap first to get the focus.
2127 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2128 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2130 // Render and notify
2131 application.SendNotification();
2132 application.Render();
2134 // Double tap to select a word.
2135 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2136 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2138 // Render and notify
2139 application.SendNotification();
2140 application.Render();
2142 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
2143 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
2145 Property::Map fontStyleMapSet;
2146 Property::Map fontStyleMapGet;
2148 fontStyleMapSet.Insert( "weight", "bold" );
2149 fontStyleMapSet.Insert( "slant", "italic" );
2150 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2152 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2153 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2154 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2156 fontStyleMapSet.Clear();
2157 fontStyleMapSet.Insert( "width", "expanded" );
2158 fontStyleMapSet.Insert( "slant", "italic" );
2159 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2161 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2162 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2163 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2165 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2166 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2168 field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2169 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2171 fontStyleMapSet.Clear();
2172 fontStyleMapSet.Insert( "weight", "bold" );
2173 fontStyleMapSet.Insert( "slant", "italic" );
2175 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2177 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2178 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2179 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2181 fontStyleMapSet.Clear();
2182 fontStyleMapSet.Insert( "width", "expanded" );
2184 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2186 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2187 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2188 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2190 // Press Escape to increase coverage
2191 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
2192 application.SendNotification();
2193 application.Render();
2195 DALI_TEST_CHECK( !field.HasKeyInputFocus() );
2200 int utcDaliTextFieldEscKeyLoseFocus(void)
2202 ToolkitTestApplication application;
2203 tet_infoline(" utcDaliTextFieldEscKeyLoseFocus");
2205 // Creates a tap event. After creating a tap event the text field should
2206 // have the focus and add text with key events should be possible.
2208 TextField field = TextField::New();
2209 DALI_TEST_CHECK( field );
2211 Stage::GetCurrent().Add( field );
2213 field.SetSize( 300.f, 50.f );
2214 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2215 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2217 // Avoid a crash when core load gl resources.
2218 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2220 // Render and notify
2221 application.SendNotification();
2222 application.Render();
2224 // Add a key event but as the text field has not the focus it should do nothing.
2225 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
2226 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up ) );
2228 // Render and notify
2229 application.SendNotification();
2230 application.Render();
2232 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2234 // Create a tap event to touch the text field.
2235 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2236 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2238 // Render and notify
2239 application.SendNotification();
2240 application.Render();
2242 // Now the text field has the focus, so it can handle the key events.
2243 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
2244 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up ) );
2245 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
2246 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Up ) );
2248 // Render and notify
2249 application.SendNotification();
2250 application.Render();
2252 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2254 // Generate a Esc key event. The text field should lose the focus.
2255 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down ) );
2256 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
2258 // Render and notify
2259 application.SendNotification();
2260 application.Render();
2262 DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2264 // No more text should be introduced
2265 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
2266 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up ) );
2268 // Render and notify
2269 application.SendNotification();
2270 application.Render();
2272 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2277 int utcDaliTextFieldSomeSpecialKeys(void)
2279 ToolkitTestApplication application;
2280 tet_infoline(" utcDaliTextFieldSomeSpecialKeys");
2282 // Checks some special keys when the text is selected.
2284 TextField field = TextField::New();
2285 DALI_TEST_CHECK( field );
2286 Stage::GetCurrent().Add( field );
2287 LoadMarkerImages(application, field);
2288 // Render and notify
2289 application.SendNotification();
2290 application.Render();
2292 const std::string longText( "This is a long text for the size of the text-field." );
2294 field.SetProperty( TextField::Property::TEXT, longText );
2295 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2296 field.SetSize( 300.f, 50.f );
2297 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2298 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2300 // Avoid a crash when core load gl resources.
2301 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2302 // Render and notify
2303 application.SendNotification();
2304 application.Render();
2306 // Create a tap event to touch the text field.
2307 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2308 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2310 // Render and notify
2311 application.SendNotification();
2312 application.Render();
2314 // Tap first to get the focus.
2315 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2316 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2318 // Render and notify
2319 application.SendNotification();
2320 application.Render();
2322 // Double tap to select a word.
2323 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2324 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2326 // Render and notify
2327 application.SendNotification();
2328 application.Render();
2330 // Generate a Esc key event. The text field should lose the focus.
2331 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Down ) );
2332 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Up ) );
2334 // Render and notify
2335 application.SendNotification();
2336 application.Render();
2338 // Generate a Esc key event. The text field should lose the focus.
2339 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Down ) );
2340 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Up ) );
2342 // Render and notify
2343 application.SendNotification();
2344 application.Render();
2346 // Generate a Esc key event. The text field should lose the focus.
2347 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Down ) );
2348 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Up ) );
2350 // Render and notify
2351 application.SendNotification();
2352 application.Render();
2354 // The text shouldn't be deleted.
2355 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), longText, TEST_LOCATION );