2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/tap-gesture-event.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/pan-gesture-event.h>
27 #include <dali/integration-api/events/long-press-gesture-event.h>
28 #include <dali-toolkit-test-suite-utils.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include "toolkit-clipboard.h"
33 using namespace Toolkit;
35 void dali_textfield_startup(void)
37 test_return_value = TET_UNDEF;
40 void dali_textfield_cleanup(void)
42 test_return_value = TET_PASS;
48 const char* const PROPERTY_NAME_RENDERING_BACKEND = "renderingBackend";
49 const char* const PROPERTY_NAME_TEXT = "text";
50 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT = "placeholderText";
51 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED = "placeholderTextFocused";
52 const char* const PROPERTY_NAME_FONT_FAMILY = "fontFamily";
53 const char* const PROPERTY_NAME_FONT_STYLE = "fontStyle";
54 const char* const PROPERTY_NAME_POINT_SIZE = "pointSize";
55 const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength";
56 const char* const PROPERTY_NAME_EXCEED_POLICY = "exceedPolicy";
57 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT = "horizontalAlignment";
58 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT = "verticalAlignment";
59 const char* const PROPERTY_NAME_TEXT_COLOR = "textColor";
60 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR = "placeholderTextColor";
61 const char* const PROPERTY_NAME_SHADOW_OFFSET = "shadowOffset";
62 const char* const PROPERTY_NAME_SHADOW_COLOR = "shadowColor";
63 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR = "primaryCursorColor";
64 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR = "secondaryCursorColor";
65 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK = "enableCursorBlink";
66 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL = "cursorBlinkInterval";
67 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION = "cursorBlinkDuration";
68 const char* const PROPERTY_NAME_CURSOR_WIDTH = "cursorWidth";
69 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE = "grabHandleImage";
70 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE = "grabHandlePressedImage";
71 const char* const PROPERTY_NAME_SCROLL_THRESHOLD = "scrollThreshold";
72 const char* const PROPERTY_NAME_SCROLL_SPEED = "scrollSpeed";
73 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT = "selectionHandleImageLeft";
74 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT = "selectionHandleImageRight";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT = "selectionHandlePressedImageLeft";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT = "selectionHandleMarkerImageLeft";
78 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT = "selectionHandleMarkerImageRight";
79 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR = "selectionHighlightColor";
80 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX = "decorationBoundingBox";
81 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS = "inputMethodSettings";
82 const char* const PROPERTY_NAME_INPUT_COLOR = "inputColor";
83 const char* const PROPERTY_NAME_ENABLE_MARKUP = "enableMarkup";
84 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY = "inputFontFamily";
85 const char* const PROPERTY_NAME_INPUT_FONT_STYLE = "inputFontStyle";
86 const char* const PROPERTY_NAME_INPUT_POINT_SIZE = "inputPointSize";
88 const char* const PROPERTY_NAME_UNDERLINE = "underline";
89 const char* const PROPERTY_NAME_INPUT_UNDERLINE = "inputUnderline";
90 const char* const PROPERTY_NAME_SHADOW = "shadow";
91 const char* const PROPERTY_NAME_INPUT_SHADOW = "inputShadow";
92 const char* const PROPERTY_NAME_EMBOSS = "emboss";
93 const char* const PROPERTY_NAME_INPUT_EMBOSS = "inputEmboss";
94 const char* const PROPERTY_NAME_OUTLINE = "outline";
95 const char* const PROPERTY_NAME_INPUT_OUTLINE = "inputOutline";
97 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
99 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
100 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
102 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
103 const float RENDER_FRAME_INTERVAL = 16.66f;
105 const float TO_MILLISECONDS = 1000.f;
106 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
108 const float SCROLL_THRESHOLD = 10.f;
109 const float SCROLL_SPEED = 300.f;
111 const unsigned int DEFAULT_FONT_SIZE = 1152u;
112 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
114 const int KEY_A_CODE = 38;
115 const int KEY_D_CODE = 40;
117 static bool gTextChangedCallBackCalled;
118 static bool gMaxCharactersCallBackCalled;
119 static bool gInputStyleChangedCallbackCalled;
120 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
122 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
124 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
125 Integration::ResourcePointer resource(bitmap);
126 bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
129 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
133 LoadBitmapResource( app.GetPlatform(), width, height );
135 Property::Map propertyMap;
136 propertyMap["filename"] = "image.png";
137 propertyMap["width"] = width;
138 propertyMap["height"] = height;
139 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
140 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
141 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
142 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
143 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
144 textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
145 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
146 textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
149 // Generate a PanGestureEvent to send to Core
150 static Integration::PanGestureEvent GeneratePan(
151 Gesture::State state,
152 const Vector2& previousPosition,
153 const Vector2& currentPosition,
154 unsigned long timeDelta,
155 unsigned int numberOfTouches = 1)
157 Integration::PanGestureEvent pan(state);
159 pan.previousPosition = previousPosition;
160 pan.currentPosition = currentPosition;
161 pan.timeDelta = timeDelta;
162 pan.numberOfTouches = numberOfTouches;
168 * Helper to generate PanGestureEvent
170 * @param[in] application Application instance
171 * @param[in] state The Gesture State
172 * @param[in] pos The current position of touch.
174 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
178 if( (state == Gesture::Started) ||
179 (state == Gesture::Possible) )
185 application.ProcessEvent(GeneratePan(state, last, pos, 16));
192 * Simulate time passed by.
194 * @note this will always process at least 1 frame (1/60 sec)
196 * @param application Test application instance
197 * @param duration Time to pass in milliseconds.
198 * @return The actual time passed in milliseconds
200 static int Wait(ToolkitTestApplication& application, int duration = 0)
204 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
206 application.SendNotification();
207 application.Render(RENDER_FRAME_INTERVAL);
208 time += RENDER_FRAME_INTERVAL;
214 Dali::Integration::Point GetPointDownInside( Vector2& pos )
216 Dali::Integration::Point point;
217 point.SetState( PointState::DOWN );
218 point.SetScreenPosition( pos );
222 Dali::Integration::Point GetPointUpInside( Vector2& pos )
224 Dali::Integration::Point point;
225 point.SetState( PointState::UP );
226 point.SetScreenPosition( pos );
230 struct CallbackFunctor
232 CallbackFunctor(bool* callbackFlag)
233 : mCallbackFlag( callbackFlag )
239 *mCallbackFlag = true;
244 static void TestTextChangedCallback( TextField control )
246 tet_infoline(" TestTextChangedCallback");
248 gTextChangedCallBackCalled = true;
251 static void TestMaxLengthReachedCallback( TextField control )
253 tet_infoline(" TestMaxLengthReachedCallback");
255 gMaxCharactersCallBackCalled = true;
258 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
260 tet_infoline(" TestInputStyleChangedCallback");
262 gInputStyleChangedCallbackCalled = true;
263 gInputStyleMask = mask;
266 // Generate a TapGestureEvent to send to Core.
267 Integration::TapGestureEvent GenerateTap(
268 Gesture::State state,
269 unsigned int numberOfTaps,
270 unsigned int numberOfTouches,
273 Integration::TapGestureEvent tap( state );
275 tap.numberOfTaps = numberOfTaps;
276 tap.numberOfTouches = numberOfTouches;
282 Integration::LongPressGestureEvent GenerateLongPress(
283 Gesture::State state,
284 unsigned int numberOfTouches,
287 Integration::LongPressGestureEvent longPress( state );
289 longPress.numberOfTouches = numberOfTouches;
290 longPress.point = point;
294 // Generate a KeyEvent to send to Core.
295 Integration::KeyEvent GenerateKey( const std::string& keyName,
296 const std::string& keyString,
299 unsigned long timeStamp,
300 const Integration::KeyEvent::State& keyState )
302 return Integration::KeyEvent( keyName,
310 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
312 if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
314 for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
316 const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
318 Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
319 if( NULL != valueSet )
321 if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
323 tet_printf( " Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
329 tet_printf( " The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
340 int UtcDaliToolkitTextFieldConstructorP(void)
342 ToolkitTestApplication application;
343 tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
345 DALI_TEST_CHECK( !textField );
349 int UtcDaliToolkitTextFieldNewP(void)
351 ToolkitTestApplication application;
352 tet_infoline(" UtcDaliToolkitTextFieldNewP");
353 TextField textField = TextField::New();
354 DALI_TEST_CHECK( textField );
358 int UtcDaliToolkitTextFieldDownCastP(void)
360 ToolkitTestApplication application;
361 tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
362 TextField textField1 = TextField::New();
363 BaseHandle object( textField1 );
365 TextField textField2 = TextField::DownCast( object );
366 DALI_TEST_CHECK( textField2 );
368 TextField textField3 = DownCast< TextField >( object );
369 DALI_TEST_CHECK( textField3 );
373 int UtcDaliToolkitTextFieldDownCastN(void)
375 ToolkitTestApplication application;
376 tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
377 BaseHandle uninitializedObject;
378 TextField textField1 = TextField::DownCast( uninitializedObject );
379 DALI_TEST_CHECK( !textField1 );
381 TextField textField2 = DownCast< TextField >( uninitializedObject );
382 DALI_TEST_CHECK( !textField2 );
386 int UtcDaliToolkitTextFieldCopyConstructorP(void)
388 ToolkitTestApplication application;
389 tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
390 TextField textField = TextField::New();
391 textField.SetProperty( TextField::Property::TEXT, "Test" );
393 TextField copy( textField );
394 DALI_TEST_CHECK( copy );
395 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
399 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
401 ToolkitTestApplication application;
402 tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
403 TextField textField = TextField::New();
404 textField.SetProperty( TextField::Property::TEXT, "Test" );
406 TextField copy = textField;
407 DALI_TEST_CHECK( copy );
408 DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
412 int UtcDaliTextFieldNewP(void)
414 ToolkitTestApplication application;
415 tet_infoline(" UtcDaliToolkitTextFieldNewP");
416 TextField textField = TextField::New();
417 DALI_TEST_CHECK( textField );
421 // Positive test case for a method
422 int UtcDaliTextFieldGetPropertyP(void)
424 ToolkitTestApplication application;
425 tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
426 TextField field = TextField::New();
427 DALI_TEST_CHECK( field );
429 // Check Property Indices are correct
430 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND );
431 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
432 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
433 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
434 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
435 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
436 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
437 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
438 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
439 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
440 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
441 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
442 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
443 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextField::Property::SHADOW_OFFSET );
444 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextField::Property::SHADOW_COLOR );
445 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
446 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
447 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
448 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
449 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
450 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
451 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
452 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
453 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
454 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
455 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
456 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
457 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
458 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
459 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
460 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
461 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
462 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
463 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
464 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
465 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
466 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
467 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
468 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
469 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
470 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
471 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
472 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
473 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
474 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
475 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
476 DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
481 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
484 Property::Map imageMap;
485 imageMap[mapKey] =mapValue;
487 field.SetProperty( property , imageMap );
488 Property::Value propValue = field.GetProperty( property );
489 Property::Map* resultMap = propValue.GetMap();
491 if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
499 // Positive test case for a method
500 int UtcDaliTextFieldSetPropertyP(void)
502 ToolkitTestApplication application;
503 tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
504 TextField field = TextField::New();
505 DALI_TEST_CHECK( field );
506 Stage::GetCurrent().Add( field );
508 // Note - we can't check the defaults since the stylesheets are platform-specific
510 // Check the render backend property.
511 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
512 DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty<int>( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
514 // Check text property.
515 field.SetProperty( TextField::Property::TEXT, "Setting Text" );
516 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
518 // Check placeholder text properties.
519 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
520 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
522 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
523 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
525 // Check font properties.
526 field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
527 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
529 Property::Map fontStyleMapSet;
530 Property::Map fontStyleMapGet;
531 Property::Value* slantValue = NULL;
533 fontStyleMapSet.Insert( "weight", "bold" );
534 fontStyleMapSet.Insert( "width", "condensed" );
535 fontStyleMapSet.Insert( "slant", "italic" );
536 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
538 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
539 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
540 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
542 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
543 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
546 fontStyleMapSet.Clear();
547 fontStyleMapSet.Insert( "weight", "normal" );
548 fontStyleMapSet.Insert( "slant", "oblique" );
549 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
551 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
552 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
553 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
555 fontStyleMapSet.Clear();
556 fontStyleMapSet.Insert( "slant", "roman" );
557 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
558 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
560 // Replace 'roman' for 'normal'.
561 slantValue = fontStyleMapGet.Find( "slant" );
562 if( NULL != slantValue )
564 if( "normal" == slantValue->Get<std::string>() )
566 fontStyleMapGet["slant"] = "roman";
569 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
570 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
572 fontStyleMapSet.Clear();
574 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
575 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
576 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
577 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
579 // Check that the MAX_LENGTH property can be correctly set
580 const int maxNumberOfCharacters = 20;
581 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
582 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
584 // Check exceed policy
585 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP );
586 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION );
587 field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
588 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
590 // Check that the Alignment properties can be correctly set
591 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
592 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
593 field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
594 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
596 // Check text's color property
597 field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
598 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
600 // Check placeholder text's color property.
601 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
602 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
604 // Check shadow properties.
605 field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
606 DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
607 field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
608 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
610 // Check cursor properties
611 field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
612 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
613 field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
614 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
616 field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
617 DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
618 field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
619 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
620 field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
621 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
622 field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
623 DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
625 // Check scroll properties.
626 field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
627 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
628 field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
629 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
631 // Check handle images
632 field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
633 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
634 field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
635 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
636 field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
638 // Check handle images
639 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" ) );
640 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" ) );
641 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" ) );
642 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" ) );
643 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" ) );
644 DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" ) );
646 // Check the highlight color
647 field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
648 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
650 // Decoration bounding box
651 field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
652 DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
654 // Check the input method setting
655 Property::Map propertyMap;
656 InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
657 InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
658 InputMethod::ActionButtonTitle::Type actionButton = InputMethod::ActionButtonTitle::GO;
659 int inputVariation = 1;
660 propertyMap["PANEL_LAYOUT"] = panelLayout;
661 propertyMap["AUTO_CAPITALISE"] = autoCapital;
662 propertyMap["ACTION_BUTTON"] = actionButton;
663 propertyMap["VARIATION"] = inputVariation;
664 field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
666 Property::Value value = field.GetProperty( TextField::Property::INPUT_METHOD_SETTINGS );
668 DALI_TEST_CHECK( value.Get( map ) );
671 DALI_TEST_CHECK( map[ "PANEL_LAYOUT" ].Get( layout ) );
672 DALI_TEST_EQUALS( static_cast<int>(panelLayout), layout, TEST_LOCATION );
675 DALI_TEST_CHECK( map[ "AUTO_CAPITALISE" ].Get( capital ) );
676 DALI_TEST_EQUALS( static_cast<int>(autoCapital), capital, TEST_LOCATION );
679 DALI_TEST_CHECK( map[ "ACTION_BUTTON" ].Get( action ) );
680 DALI_TEST_EQUALS( static_cast<int>(actionButton), action, TEST_LOCATION );
683 DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) );
684 DALI_TEST_EQUALS( inputVariation, variation, TEST_LOCATION );
686 // Check input color property.
687 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
688 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
690 // Check the enable markup property.
691 DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
692 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
693 DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
695 // Check input font properties.
696 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
697 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
699 fontStyleMapSet.Clear();
700 fontStyleMapSet.Insert( "weight", "bold" );
701 fontStyleMapSet.Insert( "width", "condensed" );
702 fontStyleMapSet.Insert( "slant", "italic" );
704 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
705 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
706 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
707 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
709 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
710 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
712 // Reset input font style.
713 fontStyleMapSet.Clear();
714 fontStyleMapSet.Insert( "weight", "normal" );
715 fontStyleMapSet.Insert( "slant", "oblique" );
717 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
718 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
719 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
720 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
722 fontStyleMapSet.Clear();
723 fontStyleMapSet.Insert( "slant", "roman" );
725 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
726 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
728 // Replace 'roman' for 'normal'.
729 slantValue = fontStyleMapGet.Find( "slant" );
730 if( NULL != slantValue )
732 if( "normal" == slantValue->Get<std::string>() )
734 fontStyleMapGet["slant"] = "roman";
737 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
738 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
740 fontStyleMapSet.Clear();
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 Property::Map underlineMapSet;
748 Property::Map underlineMapGet;
750 underlineMapSet.Insert( "enable", "true" );
751 underlineMapSet.Insert( "color", "red" );
752 underlineMapSet.Insert( "height", "1" );
754 // Check the underline property
755 field.SetProperty( TextField::Property::UNDERLINE, underlineMapSet );
757 underlineMapGet = field.GetProperty<Property::Map>( TextField::Property::UNDERLINE );
758 DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
759 DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
761 // Check the input underline property
762 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
763 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
765 // Check the shadow property
766 Property::Map shadowMapSet;
767 Property::Map shadowMapGet;
769 shadowMapSet.Insert( "color", "green" );
770 shadowMapSet.Insert( "offset", "2 2" );
772 field.SetProperty( TextField::Property::SHADOW, shadowMapSet );
774 shadowMapGet = field.GetProperty<Property::Map>( TextField::Property::SHADOW );
775 DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
776 DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
778 // Check the input shadow property
779 field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
780 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
782 // Check the emboss property
783 field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
784 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
786 // Check the input emboss property
787 field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
788 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
790 // Check the outline property
791 field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
792 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
794 // Check the input outline property
795 field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
796 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
801 // Positive Atlas Text Renderer test
802 int utcDaliTextFieldAtlasRenderP(void)
804 ToolkitTestApplication application;
805 tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
806 StyleManager styleManager = StyleManager::Get();
807 styleManager.ApplyDefaultTheme();
808 TextField field = TextField::New();
809 DALI_TEST_CHECK( field );
811 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
813 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
815 Stage::GetCurrent().Add( field );
819 // Render some text with the shared atlas backend
820 field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
821 application.SendNotification();
822 application.Render();
826 tet_result(TET_FAIL);
831 // Positive test for the textChanged signal.
832 int utcDaliTextFieldTextChangedP(void)
834 ToolkitTestApplication application;
835 tet_infoline(" utcDaliTextFieldTextChangedP");
836 TextField field = TextField::New();
837 DALI_TEST_CHECK( field );
839 Stage::GetCurrent().Add( field );
841 // connect to the text changed signal.
842 ConnectionTracker* testTracker = new ConnectionTracker();
843 field.TextChangedSignal().Connect(&TestTextChangedCallback);
844 bool textChangedSignal = false;
845 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
847 gTextChangedCallBackCalled = false;
848 field.SetProperty( TextField::Property::TEXT, "ABC" );
849 DALI_TEST_CHECK( gTextChangedCallBackCalled );
850 DALI_TEST_CHECK( textChangedSignal );
852 application.SendNotification();
854 field.SetKeyInputFocus();
856 gTextChangedCallBackCalled = false;
857 application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
858 DALI_TEST_CHECK( gTextChangedCallBackCalled );
863 // Negative test for the textChanged signal.
864 int utcDaliTextFieldTextChangedN(void)
866 ToolkitTestApplication application;
867 tet_infoline(" utcDaliTextFieldTextChangedN");
868 TextField field = TextField::New();
869 DALI_TEST_CHECK( field );
871 Stage::GetCurrent().Add( field );
873 // connect to the text changed signal.
874 ConnectionTracker* testTracker = new ConnectionTracker();
875 field.TextChangedSignal().Connect(&TestTextChangedCallback);
876 bool textChangedSignal = false;
877 field.ConnectSignal( testTracker, "textChanged", CallbackFunctor(&textChangedSignal) );
879 gTextChangedCallBackCalled = false;
880 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
881 DALI_TEST_CHECK( !gTextChangedCallBackCalled );
882 DALI_TEST_CHECK( !textChangedSignal );
887 // Positive test for Max Characters reached signal.
888 int utcDaliTextFieldMaxCharactersReachedP(void)
890 ToolkitTestApplication application;
891 tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
892 TextField field = TextField::New();
893 DALI_TEST_CHECK( field );
895 Stage::GetCurrent().Add( field );
897 const int maxNumberOfCharacters = 1;
898 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
900 field.SetKeyInputFocus();
902 // connect to the text changed signal.
903 ConnectionTracker* testTracker = new ConnectionTracker();
904 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
905 bool maxLengthReachedSignal = false;
906 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
908 gMaxCharactersCallBackCalled = false;
910 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
911 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
913 DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
914 DALI_TEST_CHECK( maxLengthReachedSignal );
919 // Negative test for Max Characters reached signal.
920 int utcDaliTextFieldMaxCharactersReachedN(void)
922 ToolkitTestApplication application;
923 tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
924 TextField field = TextField::New();
925 DALI_TEST_CHECK( field );
927 Stage::GetCurrent().Add( field );
929 const int maxNumberOfCharacters = 3;
930 field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
932 field.SetKeyInputFocus();
934 // connect to the text changed signal.
935 ConnectionTracker* testTracker = new ConnectionTracker();
936 field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
937 bool maxLengthReachedSignal = false;
938 field.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) );
940 gMaxCharactersCallBackCalled = false;
942 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
943 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
945 DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
946 DALI_TEST_CHECK( !maxLengthReachedSignal );
951 int utcDaliTextFieldInputStyleChanged01(void)
953 ToolkitTestApplication application;
954 tet_infoline(" utcDaliTextFieldInputStyleChanged01");
956 // The text-field emits signals when the input style changes. These changes of style are
957 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
958 // can't be emitted during the size negotiation as the callbacks may update the UI.
959 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
960 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
961 application.CreateAdaptor();
965 char* pathNamePtr = get_current_dir_name();
966 const std::string pathName( pathNamePtr );
969 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
970 fontClient.SetDpi( 93u, 93u );
972 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
973 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
975 TextField field = TextField::New();
976 DALI_TEST_CHECK( field );
979 field.SetSize( 300.f, 50.f );
980 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
981 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
983 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
984 field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
986 // connect to the text changed signal.
987 ConnectionTracker* testTracker = new ConnectionTracker();
988 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
989 bool inputStyleChangedSignal = false;
990 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
992 Stage::GetCurrent().Add( field );
995 application.SendNotification();
996 application.Render();
998 // Executes the idle callbacks added by the text control on the change of input style.
999 application.RunIdles();
1001 gInputStyleChangedCallbackCalled = false;
1002 gInputStyleMask = TextField::InputStyle::NONE;
1003 inputStyleChangedSignal = false;
1005 // Create a tap event to touch the text field.
1006 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1007 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
1009 // Render and notify
1010 application.SendNotification();
1011 application.Render();
1013 // Executes the idle callbacks added by the text control on the change of input style.
1014 application.RunIdles();
1016 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1017 if( gInputStyleChangedCallbackCalled )
1019 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
1021 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1022 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1024 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1025 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1027 DALI_TEST_CHECK( inputStyleChangedSignal );
1029 gInputStyleChangedCallbackCalled = false;
1030 gInputStyleMask = TextField::InputStyle::NONE;
1031 inputStyleChangedSignal = false;
1033 // Create a tap event to touch the text field.
1034 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1035 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1037 // Render and notify
1038 application.SendNotification();
1039 application.Render();
1041 // Executes the idle callbacks added by the text control on the change of input style.
1042 application.RunIdles();
1044 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1045 DALI_TEST_CHECK( !inputStyleChangedSignal );
1047 gInputStyleChangedCallbackCalled = false;
1048 gInputStyleMask = TextField::InputStyle::NONE;
1049 inputStyleChangedSignal = false;
1051 // Create a tap event to touch the text field.
1052 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1053 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1055 // Render and notify
1056 application.SendNotification();
1057 application.Render();
1059 // Executes the idle callbacks added by the text control on the change of input style.
1060 application.RunIdles();
1062 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1063 if( gInputStyleChangedCallbackCalled )
1065 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1067 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1068 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1070 DALI_TEST_CHECK( inputStyleChangedSignal );
1072 gInputStyleChangedCallbackCalled = false;
1073 gInputStyleMask = TextField::InputStyle::NONE;
1074 inputStyleChangedSignal = false;
1076 // Create a tap event to touch the text field.
1077 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1078 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1080 // Render and notify
1081 application.SendNotification();
1082 application.Render();
1084 // Executes the idle callbacks added by the text control on the change of input style.
1085 application.RunIdles();
1087 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1088 if( gInputStyleChangedCallbackCalled )
1090 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1092 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1093 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1095 const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1097 Property::Map fontStyleMapSet;
1098 fontStyleMapSet.Insert( "weight", "bold" );
1100 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1101 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1103 DALI_TEST_CHECK( inputStyleChangedSignal );
1105 gInputStyleChangedCallbackCalled = false;
1106 gInputStyleMask = TextField::InputStyle::NONE;
1107 inputStyleChangedSignal = false;
1109 // Create a tap event to touch the text field.
1110 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1111 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1113 // Render and notify
1114 application.SendNotification();
1115 application.Render();
1117 // Executes the idle callbacks added by the text control on the change of input style.
1118 application.RunIdles();
1120 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1121 DALI_TEST_CHECK( !inputStyleChangedSignal );
1123 gInputStyleChangedCallbackCalled = false;
1124 gInputStyleMask = TextField::InputStyle::NONE;
1125 inputStyleChangedSignal = false;
1127 // Create a tap event to touch the text field.
1128 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1129 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1131 // Render and notify
1132 application.SendNotification();
1133 application.Render();
1135 // Executes the idle callbacks added by the text control on the change of input style.
1136 application.RunIdles();
1138 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1139 if( gInputStyleChangedCallbackCalled )
1141 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1143 const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1144 DALI_TEST_CHECK( style.empty() );
1146 DALI_TEST_CHECK( inputStyleChangedSignal );
1148 gInputStyleChangedCallbackCalled = false;
1149 gInputStyleMask = TextField::InputStyle::NONE;
1150 inputStyleChangedSignal = false;
1152 // Create a tap event to touch the text field.
1153 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1154 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1156 // Render and notify
1157 application.SendNotification();
1158 application.Render();
1160 // Executes the idle callbacks added by the text control on the change of input style.
1161 application.RunIdles();
1163 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1164 DALI_TEST_CHECK( !inputStyleChangedSignal );
1169 int utcDaliTextFieldInputStyleChanged02(void)
1171 ToolkitTestApplication application;
1172 tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1174 // The text-field emits signals when the input style changes. These changes of style are
1175 // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1176 // can't be emitted during the size negotiation as the callbacks may update the UI.
1177 // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1178 // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1179 application.CreateAdaptor();
1183 char* pathNamePtr = get_current_dir_name();
1184 const std::string pathName( pathNamePtr );
1185 free( pathNamePtr );
1187 TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1188 fontClient.SetDpi( 93u, 93u );
1190 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1191 fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1193 TextField field = TextField::New();
1194 DALI_TEST_CHECK( field );
1197 field.SetSize( 300.f, 50.f );
1198 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1199 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1201 field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1202 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>" );
1204 // connect to the text changed signal.
1205 ConnectionTracker* testTracker = new ConnectionTracker();
1206 field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1207 bool inputStyleChangedSignal = false;
1208 field.ConnectSignal( testTracker, "inputStyleChanged", CallbackFunctor(&inputStyleChangedSignal) );
1210 Stage::GetCurrent().Add( field );
1212 // Render and notify
1213 application.SendNotification();
1214 application.Render();
1216 // Executes the idle callbacks added by the text control on the change of input style.
1217 application.RunIdles();
1219 gInputStyleChangedCallbackCalled = false;
1220 gInputStyleMask = TextField::InputStyle::NONE;
1221 inputStyleChangedSignal = false;
1223 // Create a tap event to touch the text field.
1224 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1225 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1226 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1227 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1229 // Render and notify
1230 application.SendNotification();
1231 application.Render();
1233 // Executes the idle callbacks added by the text control on the change of input style.
1234 application.RunIdles();
1236 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1237 if( gInputStyleChangedCallbackCalled )
1239 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1240 static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1241 TextField::InputStyle::POINT_SIZE |
1242 TextField::InputStyle::COLOR ),
1245 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1246 DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1248 const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1249 DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1251 const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1252 DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1254 DALI_TEST_CHECK( inputStyleChangedSignal );
1256 gInputStyleChangedCallbackCalled = false;
1257 gInputStyleMask = TextField::InputStyle::NONE;
1258 inputStyleChangedSignal = false;
1260 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1262 // Render and notify
1263 application.SendNotification();
1264 application.Render();
1266 // Executes the idle callbacks added by the text control on the change of input style.
1267 application.RunIdles();
1269 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1270 if( gInputStyleChangedCallbackCalled )
1272 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1273 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1276 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1277 DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1279 DALI_TEST_CHECK( inputStyleChangedSignal );
1281 gInputStyleChangedCallbackCalled = false;
1282 gInputStyleMask = TextField::InputStyle::NONE;
1283 inputStyleChangedSignal = false;
1285 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1287 // Render and notify
1288 application.SendNotification();
1289 application.Render();
1291 // Executes the idle callbacks added by the text control on the change of input style.
1292 application.RunIdles();
1294 DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1295 DALI_TEST_CHECK( !inputStyleChangedSignal );
1297 gInputStyleChangedCallbackCalled = false;
1298 gInputStyleMask = TextField::InputStyle::NONE;
1299 inputStyleChangedSignal = false;
1301 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1303 // Render and notify
1304 application.SendNotification();
1305 application.Render();
1307 // Executes the idle callbacks added by the text control on the change of input style.
1308 application.RunIdles();
1310 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1311 if( gInputStyleChangedCallbackCalled )
1313 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1314 static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1317 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1318 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1320 DALI_TEST_CHECK( inputStyleChangedSignal );
1322 gInputStyleChangedCallbackCalled = false;
1323 gInputStyleMask = TextField::InputStyle::NONE;
1324 inputStyleChangedSignal = false;
1326 field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1328 Property::Map fontStyleMapSet;
1329 fontStyleMapSet.Insert( "weight", "thin" );
1330 fontStyleMapSet.Insert( "width", "condensed" );
1331 fontStyleMapSet.Insert( "slant", "italic" );
1333 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1334 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1336 field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1337 field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1338 field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1339 field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
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 DALI_TEST_CHECK( !inputStyleChangedSignal );
1351 // Create a tap event to touch the text field.
1352 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1353 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1355 // Render and notify
1356 application.SendNotification();
1357 application.Render();
1359 // Executes the idle callbacks added by the text control on the change of input style.
1360 application.RunIdles();
1362 DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1363 if( gInputStyleChangedCallbackCalled )
1365 DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1366 static_cast<unsigned int>( TextField::InputStyle::COLOR |
1367 TextField::InputStyle::POINT_SIZE |
1368 TextField::InputStyle::FONT_STYLE |
1369 TextField::InputStyle::UNDERLINE |
1370 TextField::InputStyle::SHADOW |
1371 TextField::InputStyle::EMBOSS |
1372 TextField::InputStyle::OUTLINE ),
1375 const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1376 DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1378 DALI_TEST_CHECK( inputStyleChangedSignal );
1383 int utcDaliTextFieldEvent01(void)
1385 ToolkitTestApplication application;
1386 tet_infoline(" utcDaliTextFieldEvent01");
1388 // Creates a tap event. After creating a tap event the text field should
1389 // have the focus and add text with key events should be possible.
1391 TextField field = TextField::New();
1392 DALI_TEST_CHECK( field );
1394 Stage::GetCurrent().Add( field );
1396 field.SetSize( 300.f, 50.f );
1397 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1398 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1400 // Avoid a crash when core load gl resources.
1401 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1403 // Render and notify
1404 application.SendNotification();
1405 application.Render();
1407 // Add a key event but as the text field has not the focus it should do nothing.
1408 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1410 // Render and notify
1411 application.SendNotification();
1412 application.Render();
1414 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1416 // Create a tap event to touch the text field.
1417 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1418 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1420 // Render and notify
1421 application.SendNotification();
1422 application.Render();
1424 // Now the text field has the focus, so it can handle the key events.
1425 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1426 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1428 // Render and notify
1429 application.SendNotification();
1430 application.Render();
1432 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1434 // Create a second text field and send key events to it.
1435 TextField field2 = TextField::New();
1437 field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1438 field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1439 field2.SetSize( 100.f, 100.f );
1440 field2.SetPosition( 100.f, 100.f );
1442 Stage::GetCurrent().Add( field2 );
1444 // Render and notify
1445 application.SendNotification();
1446 application.Render();
1448 // Create a tap event on the second text field.
1449 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1450 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1452 // Render and notify
1453 application.SendNotification();
1454 application.Render();
1456 // The second text field has the focus. It should handle the key events.
1457 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1458 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1460 // Render and notify
1461 application.SendNotification();
1462 application.Render();
1464 // Check the text has been added to the second text field.
1465 DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1470 int utcDaliTextFieldEvent02(void)
1472 ToolkitTestApplication application;
1473 tet_infoline(" utcDaliTextFieldEvent02");
1475 // Checks if the right number of actors are created.
1477 TextField field = TextField::New();
1478 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1479 DALI_TEST_CHECK( field );
1480 LoadMarkerImages(application, field);
1482 Stage::GetCurrent().Add( field );
1484 field.SetSize( 300.f, 50.f );
1485 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1486 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1488 // Avoid a crash when core load gl resources.
1489 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1491 // Render and notify
1492 application.SendNotification();
1493 application.Render();
1495 // Check there are the expected number of children ( stencil ).
1496 DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1498 Actor stencil = field.GetChildAt( 0u );
1499 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1501 // Create a tap event to touch the text field.
1502 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1503 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1505 // Render and notify
1506 application.SendNotification();
1507 application.Render();
1509 Actor layer = field.GetChildAt( 1u );
1510 DALI_TEST_CHECK( layer.IsLayer() );
1512 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1513 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1515 // Now the text field has the focus, so it can handle the key events.
1516 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1517 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1519 // Render and notify
1520 application.SendNotification();
1521 application.Render();
1523 // Checks the cursor and the renderer have been created.
1524 DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1525 DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1527 Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1528 DALI_TEST_CHECK( cursor );
1530 // The offscreen root actor has a container with all the actors which contain the text renderers.
1531 Actor container = stencil.GetChildAt( 0u );
1532 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1534 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1535 DALI_TEST_CHECK( renderer );
1538 // Move the cursor and check the position changes.
1539 Vector3 position1 = cursor.GetCurrentPosition();
1541 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1542 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1544 // Render and notify
1545 application.SendNotification();
1546 application.Render();
1548 Vector3 position2 = cursor.GetCurrentPosition();
1550 DALI_TEST_CHECK( position2.x < position1.x );
1552 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1553 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1555 // Render and notify
1556 application.SendNotification();
1557 application.Render();
1559 Vector3 position3 = cursor.GetCurrentPosition();
1561 DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1563 // Send some taps and check the cursor positions.
1565 // Try to tap at the beginning.
1566 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1567 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1569 // Render and notify
1570 application.SendNotification();
1571 application.Render();
1573 // Cursor position should be the same than position1.
1574 Vector3 position4 = cursor.GetCurrentPosition();
1576 DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1578 // Tap away from the start position.
1579 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1580 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1582 // Render and notify
1583 application.SendNotification();
1584 application.Render();
1586 Vector3 position5 = cursor.GetCurrentPosition();
1588 DALI_TEST_CHECK( position5.x > position4.x );
1590 // Remove all the text.
1591 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1592 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1593 field.SetProperty( TextField::Property::TEXT, "" );
1595 // Render and notify
1596 application.SendNotification();
1597 application.Render();
1599 // Cursor position should be the same than position2.
1600 Vector3 position6 = cursor.GetCurrentPosition();
1602 DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1604 // Should not be a renderer.
1605 DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1610 int utcDaliTextFieldEvent03(void)
1612 ToolkitTestApplication application;
1613 tet_infoline(" utcDaliTextFieldEvent03");
1615 // Checks if the highlight actor is created.
1617 TextField field = TextField::New();
1618 DALI_TEST_CHECK( field );
1620 Stage::GetCurrent().Add( field );
1622 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1623 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1624 field.SetSize( 30.f, 50.f );
1625 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1626 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1628 // Avoid a crash when core load gl resources.
1629 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1630 LoadMarkerImages(application, field);
1632 // Render and notify
1633 application.SendNotification();
1634 application.Render();
1636 // Tap first to get the focus.
1637 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1638 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1640 // Render and notify
1641 application.SendNotification();
1642 application.Render();
1644 // Double tap to select a word.
1645 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1646 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1648 // Render and notify
1649 application.SendNotification();
1650 application.Render();
1652 // The offscreen root actor should have two actors: the renderer and the highlight actor.
1653 Actor stencil = field.GetChildAt( 0u );
1655 // The offscreen root actor has a container with all the actors which contain the text renderers.
1656 Actor container = stencil.GetChildAt( 0u );
1657 for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1659 Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1660 DALI_TEST_CHECK( renderer );
1663 Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1664 DALI_TEST_CHECK( highlight );
1669 int utcDaliTextFieldEvent04(void)
1671 ToolkitTestApplication application;
1672 tet_infoline(" utcDaliTextFieldEvent04");
1674 // Checks if the highlight actor is created.
1676 TextField field = TextField::New();
1677 DALI_TEST_CHECK( field );
1678 Stage::GetCurrent().Add( field );
1679 LoadMarkerImages(application, field);
1680 // Render and notify
1681 application.SendNotification();
1682 application.Render();
1684 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1685 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1686 field.SetSize( 300.f, 50.f );
1687 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1688 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1690 // Avoid a crash when core load gl resources.
1691 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1692 // Render and notify
1693 application.SendNotification();
1694 application.Render();
1696 // Create a tap event to touch the text field.
1697 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1698 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1699 // Render and notify
1700 application.SendNotification();
1701 application.Render();
1704 // Tap first to get the focus.
1705 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1706 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1708 // Render and notify
1709 application.SendNotification();
1710 application.Render();
1712 // Double tap to select a word.
1713 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1714 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1716 // Render and notify
1717 application.SendNotification();
1718 application.Render();
1721 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1722 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1726 int utcDaliTextFieldEvent05(void)
1728 ToolkitTestApplication application;
1729 tet_infoline(" utcDaliTextFieldEvent05");
1731 // Checks dragging of cursor/grab handle
1733 TextField field = TextField::New();
1734 DALI_TEST_CHECK( field );
1735 Stage::GetCurrent().Add( field );
1736 LoadMarkerImages(application, field);
1737 // Render and notify
1738 application.SendNotification();
1739 application.Render();
1741 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1742 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1743 field.SetSize( 300.f, 50.f );
1744 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1745 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1747 // Avoid a crash when core load gl resources.
1748 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1749 // Render and notify
1750 application.SendNotification();
1751 application.Render();
1753 // Create a tap event to touch the text field.
1754 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1755 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1756 // Render and notify
1757 application.SendNotification();
1758 application.Render();
1761 // Tap first to get the focus.
1762 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1763 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1765 // Render and notify
1766 application.SendNotification();
1767 application.Render();
1769 // Double tap to select a word.
1770 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1771 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1773 // Render and notify
1774 application.SendNotification();
1775 application.Render();
1777 // drag grab handle right
1778 Vector2 pos(0.0f, 40.0f);
1779 SendPan(application, Gesture::Possible, pos);
1780 SendPan(application, Gesture::Started, pos);
1782 Wait(application, 100);
1784 for(int i = 0;i<20;i++)
1786 SendPan(application, Gesture::Continuing, pos);
1791 SendPan(application, Gesture::Finished, pos);
1792 Wait(application, RENDER_FRAME_INTERVAL);
1794 Actor stencil = field.GetChildAt( 1u );
1798 int utcDaliTextFieldEvent06(void)
1800 ToolkitTestApplication application;
1801 tet_infoline(" utcDaliTextFieldEvent06");
1803 // Checks Longpress when in edit mode
1805 TextField field = TextField::New();
1806 DALI_TEST_CHECK( field );
1807 Stage::GetCurrent().Add( field );
1808 LoadMarkerImages(application, field);
1809 // Render and notify
1810 application.SendNotification();
1811 application.Render();
1813 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1814 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1815 field.SetSize( 300.f, 50.f );
1816 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1817 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1819 // Avoid a crash when core load gl resources.
1820 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1821 // Render and notify
1822 application.SendNotification();
1823 application.Render();
1825 // Create a tap event to touch the text field.
1826 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1827 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1828 // Render and notify
1829 application.SendNotification();
1830 application.Render();
1833 // Tap first to get the focus.
1834 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1835 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1837 // Render and notify
1838 application.SendNotification();
1839 application.Render();
1842 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1843 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1845 // Render and notify
1846 application.SendNotification();
1847 application.Render();
1852 int utcDaliTextFieldEvent07(void)
1854 ToolkitTestApplication application;
1855 tet_infoline(" utcDaliTextFieldEvent07");
1857 // Checks Longpress to start edit mode
1859 TextField field = TextField::New();
1860 DALI_TEST_CHECK( field );
1861 Stage::GetCurrent().Add( field );
1862 LoadMarkerImages(application, field);
1863 // Render and notify
1864 application.SendNotification();
1865 application.Render();
1867 field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1868 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1869 field.SetSize( 300.f, 50.f );
1870 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1871 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1872 Property::Map propertyMap;
1873 propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD;
1874 field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
1876 // Avoid a crash when core load gl resources.
1877 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1878 // Render and notify
1879 application.SendNotification();
1880 application.Render();
1883 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1884 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1886 // Render and notify
1887 application.SendNotification();
1888 application.Render();
1893 int utcDaliTextFieldEvent08(void)
1895 ToolkitTestApplication application;
1896 tet_infoline(" utcDaliTextFieldEvent08");
1898 Dali::Clipboard clipboard = Clipboard::Get();
1899 clipboard.SetItem("testTextFieldEvent");
1901 // Checks Longpress when only place holder text
1903 TextField field = TextField::New();
1904 DALI_TEST_CHECK( field );
1905 Stage::GetCurrent().Add( field );
1906 LoadMarkerImages(application, field);
1907 // Render and notify
1908 application.SendNotification();
1909 application.Render();
1911 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
1912 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1913 field.SetSize( 300.f, 50.f );
1914 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1915 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1917 // Avoid a crash when core load gl resources.
1918 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1919 // Render and notify
1920 application.SendNotification();
1921 application.Render();
1924 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1925 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1927 // Render and notify
1928 application.SendNotification();
1929 application.Render();
1931 Wait(application, 500);
1934 application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1935 application.ProcessEvent( GenerateLongPress( Gesture::Started, 1u, Vector2( 1.f, 25.0f ) ) );
1937 // Render and notify
1938 application.SendNotification();
1939 application.Render();
1941 Wait(application, 500);
1943 Stage stage = Stage::GetCurrent();
1944 Layer layer = stage.GetRootLayer();
1945 Actor actor = layer.FindChildByName("optionPaste");
1949 Vector3 worldPosition = actor.GetCurrentWorldPosition();
1950 Vector2 halfStageSize = stage.GetSize() / 2.0f;
1951 Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
1953 Dali::Integration::TouchEvent event;
1954 event = Dali::Integration::TouchEvent();
1955 event.AddPoint( GetPointDownInside( position ) );
1956 application.ProcessEvent( event );
1958 event = Dali::Integration::TouchEvent();
1959 event.AddPoint( GetPointUpInside( position ) );
1960 application.ProcessEvent( event );
1962 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
1967 int utcDaliTextFieldStyleWhilstSelected(void)
1969 ToolkitTestApplication application;
1970 tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
1972 // Change font and styles whilst text is selected whilst word selected
1974 TextField field = TextField::New();
1975 DALI_TEST_CHECK( field );
1976 Stage::GetCurrent().Add( field );
1977 LoadMarkerImages(application, field);
1978 // Render and notify
1979 application.SendNotification();
1980 application.Render();
1982 field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1983 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1984 field.SetSize( 300.f, 50.f );
1985 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1986 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1988 // Avoid a crash when core load gl resources.
1989 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1990 // Render and notify
1991 application.SendNotification();
1992 application.Render();
1994 // Create a tap event to touch the text field.
1995 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1996 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1997 // Render and notify
1998 application.SendNotification();
1999 application.Render();
2002 // Tap first to get the focus.
2003 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2004 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2006 // Render and notify
2007 application.SendNotification();
2008 application.Render();
2010 // Double tap to select a word.
2011 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2012 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2014 // Render and notify
2015 application.SendNotification();
2016 application.Render();
2018 field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
2019 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
2021 Property::Map fontStyleMapSet;
2022 Property::Map fontStyleMapGet;
2024 fontStyleMapSet.Insert( "weight", "bold" );
2025 fontStyleMapSet.Insert( "slant", "italic" );
2026 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2028 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2029 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2030 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2032 fontStyleMapSet.Clear();
2033 fontStyleMapSet.Insert( "width", "expanded" );
2034 fontStyleMapSet.Insert( "slant", "italic" );
2035 field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2037 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2038 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2039 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2041 field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2042 DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2044 field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2045 DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2047 fontStyleMapSet.Clear();
2048 fontStyleMapSet.Insert( "weight", "bold" );
2049 fontStyleMapSet.Insert( "slant", "italic" );
2051 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2053 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2054 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2055 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2057 fontStyleMapSet.Clear();
2058 fontStyleMapSet.Insert( "width", "expanded" );
2060 field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2062 fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2063 DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2064 DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2066 // Press Escape to increase coverage
2067 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
2068 application.SendNotification();
2069 application.Render();
2071 DALI_TEST_CHECK( !field.HasKeyInputFocus() );
2076 int utcDaliTextFieldEscKeyLoseFocus(void)
2078 ToolkitTestApplication application;
2079 tet_infoline(" utcDaliTextFieldEscKeyLoseFocus");
2081 // Creates a tap event. After creating a tap event the text field should
2082 // have the focus and add text with key events should be possible.
2084 TextField field = TextField::New();
2085 DALI_TEST_CHECK( field );
2087 Stage::GetCurrent().Add( field );
2089 field.SetSize( 300.f, 50.f );
2090 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2091 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2093 // Avoid a crash when core load gl resources.
2094 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2096 // Render and notify
2097 application.SendNotification();
2098 application.Render();
2100 // Add a key event but as the text field has not the focus it should do nothing.
2101 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
2102 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up ) );
2104 // Render and notify
2105 application.SendNotification();
2106 application.Render();
2108 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2110 // Create a tap event to touch the text field.
2111 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2112 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2114 // Render and notify
2115 application.SendNotification();
2116 application.Render();
2118 // Now the text field has the focus, so it can handle the key events.
2119 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
2120 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up ) );
2121 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
2122 application.ProcessEvent( GenerateKey( "d", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Up ) );
2124 // Render and notify
2125 application.SendNotification();
2126 application.Render();
2128 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2130 // Generate a Esc key event. The text field should lose the focus.
2131 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down ) );
2132 application.ProcessEvent( GenerateKey( "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up ) );
2134 // Render and notify
2135 application.SendNotification();
2136 application.Render();
2138 DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2140 // No more text should be introduced
2141 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
2142 application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up ) );
2144 // Render and notify
2145 application.SendNotification();
2146 application.Render();
2148 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2153 int utcDaliTextFieldSomeSpecialKeys(void)
2155 ToolkitTestApplication application;
2156 tet_infoline(" utcDaliTextFieldSomeSpecialKeys");
2158 // Checks some special keys when the text is selected.
2160 TextField field = TextField::New();
2161 DALI_TEST_CHECK( field );
2162 Stage::GetCurrent().Add( field );
2163 LoadMarkerImages(application, field);
2164 // Render and notify
2165 application.SendNotification();
2166 application.Render();
2168 const std::string longText( "This is a long text for the size of the text-field." );
2170 field.SetProperty( TextField::Property::TEXT, longText );
2171 field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2172 field.SetSize( 300.f, 50.f );
2173 field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2174 field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2176 // Avoid a crash when core load gl resources.
2177 application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2178 // Render and notify
2179 application.SendNotification();
2180 application.Render();
2182 // Create a tap event to touch the text field.
2183 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2184 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
2186 // Render and notify
2187 application.SendNotification();
2188 application.Render();
2190 // Tap first to get the focus.
2191 application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2192 application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
2194 // Render and notify
2195 application.SendNotification();
2196 application.Render();
2198 // Double tap to select a word.
2199 application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2200 application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
2202 // Render and notify
2203 application.SendNotification();
2204 application.Render();
2206 // Generate a Esc key event. The text field should lose the focus.
2207 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Down ) );
2208 application.ProcessEvent( GenerateKey( "XF86PowerOff", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Up ) );
2210 // Render and notify
2211 application.SendNotification();
2212 application.Render();
2214 // Generate a Esc key event. The text field should lose the focus.
2215 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Down ) );
2216 application.ProcessEvent( GenerateKey( "XF86Menu", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Up ) );
2218 // Render and notify
2219 application.SendNotification();
2220 application.Render();
2222 // Generate a Esc key event. The text field should lose the focus.
2223 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Down ) );
2224 application.ProcessEvent( GenerateKey( "XF86Home", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Up ) );
2226 // Render and notify
2227 application.SendNotification();
2228 application.Render();
2230 // The text shouldn't be deleted.
2231 DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), longText, TEST_LOCATION );