Add Text Preedit Style
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextField.cpp
1 /*
2  * Copyright (c) 2019 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <unistd.h>
21
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25
26 #include <dali/devel-api/adaptor-framework/key-devel.h>
27 #include <dali/devel-api/text-abstraction/font-client.h>
28 #include <dali-toolkit-test-suite-utils.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include <dali-toolkit/devel-api/controls/text-controls/text-field-devel.h>
31 #include "toolkit-clipboard.h"
32
33 using namespace Dali;
34 using namespace Toolkit;
35
36 void dali_textfield_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void dali_textfield_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 namespace
47 {
48
49 const char* const PROPERTY_NAME_RENDERING_BACKEND                    = "renderingBackend";
50 const char* const PROPERTY_NAME_TEXT                                 = "text";
51 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT                     = "placeholderText";
52 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED             = "placeholderTextFocused";
53 const char* const PROPERTY_NAME_FONT_FAMILY                          = "fontFamily";
54 const char* const PROPERTY_NAME_FONT_STYLE                           = "fontStyle";
55 const char* const PROPERTY_NAME_POINT_SIZE                           = "pointSize";
56 const char* const PROPERTY_NAME_MAX_LENGTH                           = "maxLength";
57 const char* const PROPERTY_NAME_EXCEED_POLICY                        = "exceedPolicy";
58 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT                 = "horizontalAlignment";
59 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT                   = "verticalAlignment";
60 const char* const PROPERTY_NAME_TEXT_COLOR                           = "textColor";
61 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR               = "placeholderTextColor";
62 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR                 = "primaryCursorColor";
63 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR               = "secondaryCursorColor";
64 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK                  = "enableCursorBlink";
65 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL                = "cursorBlinkInterval";
66 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION                = "cursorBlinkDuration";
67 const char* const PROPERTY_NAME_CURSOR_WIDTH                         = "cursorWidth";
68 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHandleImage";
69 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
70 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
71 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
72 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
73 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
74 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT   = "selectionHandleMarkerImageLeft";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = "selectionHandleMarkerImageRight";
78 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR            = "selectionHighlightColor";
79 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX              = "decorationBoundingBox";
80 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS                = "inputMethodSettings";
81 const char* const PROPERTY_NAME_INPUT_COLOR                          = "inputColor";
82 const char* const PROPERTY_NAME_ENABLE_MARKUP                        = "enableMarkup";
83 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY                    = "inputFontFamily";
84 const char* const PROPERTY_NAME_INPUT_FONT_STYLE                     = "inputFontStyle";
85 const char* const PROPERTY_NAME_INPUT_POINT_SIZE                     = "inputPointSize";
86
87 const char* const PROPERTY_NAME_UNDERLINE                            = "underline";
88 const char* const PROPERTY_NAME_INPUT_UNDERLINE                      = "inputUnderline";
89 const char* const PROPERTY_NAME_SHADOW                               = "shadow";
90 const char* const PROPERTY_NAME_INPUT_SHADOW                         = "inputShadow";
91 const char* const PROPERTY_NAME_EMBOSS                               = "emboss";
92 const char* const PROPERTY_NAME_INPUT_EMBOSS                         = "inputEmboss";
93 const char* const PROPERTY_NAME_OUTLINE                              = "outline";
94 const char* const PROPERTY_NAME_INPUT_OUTLINE                        = "inputOutline";
95
96 const char* const PROPERTY_NAME_HIDDEN_INPUT_SETTINGS                = "hiddenInputSettings";
97 const char* const PROPERTY_NAME_PIXEL_SIZE                           = "pixelSize";
98 const char* const PROPERTY_NAME_ENABLE_SELECTION                     = "enableSelection";
99 const char* const PROPERTY_NAME_PLACEHOLDER                          = "placeholder";
100 const char* const PROPERTY_NAME_ELLIPSIS                             = "ellipsis";
101 const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION               = "enableShiftSelection";
102 const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE                   = "enableGrabHandle";
103 const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION      = "matchSystemLanguageDirection";
104 const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP             = "enableGrabHandlePopup";
105
106 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
107 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
108
109 const float RENDER_FRAME_INTERVAL = 16.66f;
110
111 const unsigned int DEFAULT_FONT_SIZE = 1152u;
112 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
113
114 const int KEY_RETURN_CODE = 36;
115 const int KEY_A_CODE = 38;
116 const int KEY_D_CODE = 40;
117
118 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
119
120 static bool gTextChangedCallBackCalled;
121 static bool gMaxCharactersCallBackCalled;
122 static bool gInputStyleChangedCallbackCalled;
123 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
124
125 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
126 {
127   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
128   Integration::ResourcePointer resource(bitmap);
129   bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
130 }
131
132 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
133 {
134   int width(40);
135   int height(40);
136   LoadBitmapResource( app.GetPlatform(), width, height );
137
138   Property::Map propertyMap;
139   propertyMap["filename"] = "image.png";
140   propertyMap["width"] = width;
141   propertyMap["height"] = height;
142   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
143   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
144   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
145   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
146   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
147   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
148   textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
149   textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
150 }
151
152 /*
153  * Simulate time passed by.
154  *
155  * @note this will always process at least 1 frame (1/60 sec)
156  *
157  * @param application Test application instance
158  * @param duration Time to pass in milliseconds.
159  * @return The actual time passed in milliseconds
160  */
161 static int Wait(ToolkitTestApplication& application, int duration = 0)
162 {
163   int time = 0;
164
165   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
166   {
167     application.SendNotification();
168     application.Render(RENDER_FRAME_INTERVAL);
169     time += RENDER_FRAME_INTERVAL;
170   }
171
172   return time;
173 }
174
175 Dali::Integration::Point GetPointDownInside( Vector2& pos )
176 {
177   Dali::Integration::Point point;
178   point.SetState( PointState::DOWN );
179   point.SetScreenPosition( pos );
180   return point;
181 }
182
183 Dali::Integration::Point GetPointUpInside( Vector2& pos )
184 {
185   Dali::Integration::Point point;
186   point.SetState( PointState::UP );
187   point.SetScreenPosition( pos );
188   return point;
189 }
190
191 struct CallbackFunctor
192 {
193   CallbackFunctor(bool* callbackFlag)
194   : mCallbackFlag( callbackFlag )
195   {
196   }
197
198   void operator()()
199   {
200     *mCallbackFlag = true;
201   }
202   bool* mCallbackFlag;
203 };
204
205 static void TestTextChangedCallback( TextField control )
206 {
207   tet_infoline(" TestTextChangedCallback");
208
209   gTextChangedCallBackCalled = true;
210 }
211
212 static void TestMaxLengthReachedCallback( TextField control )
213 {
214   tet_infoline(" TestMaxLengthReachedCallback");
215
216   gMaxCharactersCallBackCalled = true;
217 }
218
219 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
220 {
221   tet_infoline(" TestInputStyleChangedCallback");
222
223   gInputStyleChangedCallbackCalled = true;
224   gInputStyleMask = mask;
225 }
226
227 // Generate a KeyEvent to send to Core.
228 Integration::KeyEvent GenerateKey( const std::string& keyName,
229                                    const std::string& logicalKey,
230                                    const std::string& keyString,
231                                    int keyCode,
232                                    int keyModifier,
233                                    unsigned long timeStamp,
234                                    const Integration::KeyEvent::State& keyState,
235                                    const std::string& compose = "",
236                                    const std::string& deviceName = DEFAULT_DEVICE_NAME,
237                                    const Device::Class::Type& deviceClass = Device::Class::NONE,
238                                    const Device::Subclass::Type& deviceSubclass = Device::Subclass::NONE )
239 {
240   return Integration::KeyEvent( keyName,
241                                 logicalKey,
242                                 keyString,
243                                 keyCode,
244                                 keyModifier,
245                                 timeStamp,
246                                 keyState,
247                                 compose,
248                                 deviceName,
249                                 deviceClass,
250                                 deviceSubclass );
251 }
252
253 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
254 {
255   if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
256   {
257     for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
258     {
259       const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
260
261       Property::Value* valueSet = NULL;
262       if ( valueGet.first.type == Property::Key::INDEX )
263       {
264         valueSet = fontStyleMapSet.Find( valueGet.first.indexKey );
265       }
266       else
267       {
268         // Get Key is a string so searching Set Map for a string key
269         valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
270       }
271
272       if( NULL != valueSet )
273       {
274         if( valueSet->GetType() == Dali::Property::STRING && ( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() ) )
275         {
276           tet_printf( "Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
277           return false;
278         }
279         else if( valueSet->GetType() == Dali::Property::BOOLEAN && ( valueGet.second.Get<bool>() != valueSet->Get<bool>() ) )
280         {
281           tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get<bool>(), valueSet->Get<bool>() );
282           return false;
283         }
284         else if( valueSet->GetType() == Dali::Property::INTEGER && ( valueGet.second.Get<int>() != valueSet->Get<int>() ) )
285         {
286           tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get<int>(), valueSet->Get<int>() );
287           return false;
288         }
289         else if( valueSet->GetType() == Dali::Property::FLOAT && ( valueGet.second.Get<float>() != valueSet->Get<float>() ) )
290         {
291           tet_printf( "Value got : [%f], expected : [%f]", valueGet.second.Get<float>(), valueSet->Get<float>() );
292           return false;
293         }
294         else if( valueSet->GetType() == Dali::Property::VECTOR2 && ( valueGet.second.Get<Vector2>() != valueSet->Get<Vector2>() ) )
295         {
296           Vector2 vector2Get = valueGet.second.Get<Vector2>();
297           Vector2 vector2Set = valueSet->Get<Vector2>();
298           tet_printf( "Value got : [%f, %f], expected : [%f, %f]", vector2Get.x, vector2Get.y, vector2Set.x, vector2Set.y );
299           return false;
300         }
301         else if( valueSet->GetType() == Dali::Property::VECTOR4 && ( valueGet.second.Get<Vector4>() != valueSet->Get<Vector4>() ) )
302         {
303           Vector4 vector4Get = valueGet.second.Get<Vector4>();
304           Vector4 vector4Set = valueSet->Get<Vector4>();
305           tet_printf( "Value got : [%f, %f, %f, %f], expected : [%f, %f, %f, %f]", vector4Get.r, vector4Get.g, vector4Get.b, vector4Get.a, vector4Set.r, vector4Set.g, vector4Set.b, vector4Set.a );
306           return false;
307         }
308       }
309       else
310       {
311         if ( valueGet.first.type == Property::Key::INDEX )
312         {
313           tet_printf( "  The key %d doesn't exist.", valueGet.first.indexKey );
314         }
315         else
316         {
317           tet_printf( "  The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
318         }
319         return false;
320       }
321     }
322   }
323
324   return true;
325 }
326
327 } // namespace
328
329 int UtcDaliToolkitTextFieldConstructorP(void)
330 {
331   ToolkitTestApplication application;
332   tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
333   TextField textField;
334   DALI_TEST_CHECK( !textField );
335   END_TEST;
336 }
337
338 int UtcDaliToolkitTextFieldNewP(void)
339 {
340   ToolkitTestApplication application;
341   tet_infoline(" UtcDaliToolkitTextFieldNewP");
342   TextField textField = TextField::New();
343   DALI_TEST_CHECK( textField );
344   END_TEST;
345 }
346
347 int UtcDaliToolkitTextFieldDownCastP(void)
348 {
349   ToolkitTestApplication application;
350   tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
351   TextField textField1 = TextField::New();
352   BaseHandle object( textField1 );
353
354   TextField textField2 = TextField::DownCast( object );
355   DALI_TEST_CHECK( textField2 );
356
357   TextField textField3 = DownCast< TextField >( object );
358   DALI_TEST_CHECK( textField3 );
359   END_TEST;
360 }
361
362 int UtcDaliToolkitTextFieldDownCastN(void)
363 {
364   ToolkitTestApplication application;
365   tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
366   BaseHandle uninitializedObject;
367   TextField textField1 = TextField::DownCast( uninitializedObject );
368   DALI_TEST_CHECK( !textField1 );
369
370   TextField textField2 = DownCast< TextField >( uninitializedObject );
371   DALI_TEST_CHECK( !textField2 );
372   END_TEST;
373 }
374
375 int UtcDaliToolkitTextFieldCopyConstructorP(void)
376 {
377   ToolkitTestApplication application;
378   tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
379   TextField textField = TextField::New();
380   textField.SetProperty( TextField::Property::TEXT, "Test" );
381
382   TextField copy( textField );
383   DALI_TEST_CHECK( copy );
384   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
385   END_TEST;
386 }
387
388 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
389 {
390   ToolkitTestApplication application;
391   tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
392   TextField textField = TextField::New();
393   textField.SetProperty( TextField::Property::TEXT, "Test" );
394
395   TextField copy = textField;
396   DALI_TEST_CHECK( copy );
397   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
398   END_TEST;
399 }
400
401 int UtcDaliTextFieldNewP(void)
402 {
403   ToolkitTestApplication application;
404   tet_infoline(" UtcDaliToolkitTextFieldNewP");
405   TextField textField = TextField::New();
406   DALI_TEST_CHECK( textField );
407   END_TEST;
408 }
409
410 // Positive test case for a method
411 int UtcDaliTextFieldGetPropertyP(void)
412 {
413   ToolkitTestApplication application;
414   tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
415   TextField field = TextField::New();
416   DALI_TEST_CHECK( field );
417
418   // Check Property Indices are correct
419   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND );
420   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
421   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
422   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
423   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
424   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
425   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
426   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
427   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
428   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
429   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
430   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
431   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
432   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
433   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
434   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
435   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
436   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
437   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
438   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
439   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
440   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
441   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
442   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
443   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
444   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
445   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
446   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
447   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
448   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
449   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
450   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
451   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
452   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
453   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
454   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
455   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
456   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
457   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
458   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
459   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
460   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
461   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
462   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
463   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
464   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HIDDEN_INPUT_SETTINGS ) == TextField::Property::HIDDEN_INPUT_SETTINGS );
465   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == TextField::Property::PIXEL_SIZE );
466   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == TextField::Property::ENABLE_SELECTION );
467   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextField::Property::PLACEHOLDER );
468   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextField::Property::ELLIPSIS );
469   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextField::Property::ENABLE_SHIFT_SELECTION );
470   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextField::Property::ENABLE_GRAB_HANDLE );
471   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION );
472   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP ) == DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP );
473
474   END_TEST;
475 }
476
477 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
478 {
479   bool result = false;
480   Property::Map imageMap;
481   imageMap[mapKey] =mapValue;
482
483   field.SetProperty( property , imageMap );
484   Property::Value propValue = field.GetProperty( property );
485   Property::Map* resultMap = propValue.GetMap();
486
487   if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
488   {
489     result = true;
490   }
491
492   return result;
493 }
494
495 // Positive test case for a method
496 int UtcDaliTextFieldSetPropertyP(void)
497 {
498   ToolkitTestApplication application;
499   tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
500   TextField field = TextField::New();
501   DALI_TEST_CHECK( field );
502   Stage::GetCurrent().Add( field );
503
504   // Note - we can't check the defaults since the stylesheets are platform-specific
505
506   // Check the render backend property.
507   field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
508   DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty<int>( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
509
510   // Check text property.
511   field.SetProperty( TextField::Property::TEXT, "Setting Text" );
512   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
513
514   // Check placeholder text properties.
515   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
516   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
517
518   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
519   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
520
521   // Check font properties.
522   field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
523   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
524
525   Property::Map fontStyleMapSet;
526   Property::Map fontStyleMapGet;
527   Property::Value* slantValue = NULL;
528
529   fontStyleMapSet.Insert( "weight", "bold" );
530   fontStyleMapSet.Insert( "width", "condensed" );
531   fontStyleMapSet.Insert( "slant", "italic" );
532   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
533
534   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
535   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
536   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
537
538   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
539   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
540
541   // Reset font style.
542   fontStyleMapSet.Clear();
543   fontStyleMapSet.Insert( "weight", "normal" );
544   fontStyleMapSet.Insert( "slant", "oblique" );
545   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
546
547   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
548   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
549   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
550
551   fontStyleMapSet.Clear();
552   fontStyleMapSet.Insert( "slant", "roman" );
553   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
554   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
555
556   // Replace 'roman' for 'normal'.
557   slantValue = fontStyleMapGet.Find( "slant" );
558   if( NULL != slantValue )
559   {
560     if( "normal" == slantValue->Get<std::string>() )
561     {
562       fontStyleMapGet["slant"] = "roman";
563     }
564   }
565   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
566   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
567
568   fontStyleMapSet.Clear();
569
570   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
571   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
572   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
573   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
574
575   // Check that the MAX_LENGTH property can be correctly set
576   const int maxNumberOfCharacters = 20;
577   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
578   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
579
580   // Check exceed policy
581   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP );
582   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION );
583   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
584   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
585
586   // Check that the Alignment properties can be correctly set
587   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
588   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
589   field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
590   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
591
592   // Check text's color property
593   field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
594   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
595
596   // Check placeholder text's color property.
597   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
598   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
599
600   // Check cursor properties
601   field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
602   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
603   field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
604   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
605
606   field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
607   DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
608   field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
609   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
610   field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
611   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
612   field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
613   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
614
615   // Check scroll properties.
616   field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
617   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
618   field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
619   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
620
621   // Check handle images
622   field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
623   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
624   field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
625   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
626   field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
627
628   // Check handle images
629   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" )  );
630   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" )  );
631   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" )  );
632   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" )  );
633   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" )  );
634   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" )  );
635
636   // Check the highlight color
637   field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
638   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
639
640   // Decoration bounding box
641   field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
642   DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
643
644   // Check the input method setting
645   Property::Map propertyMap;
646   InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
647   InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
648   InputMethod::ButtonAction::Type buttonAction = InputMethod::ButtonAction::GO;
649   int inputVariation = 1;
650   propertyMap["PANEL_LAYOUT"] = panelLayout;
651   propertyMap["AUTO_CAPITALIZE"] = autoCapital;
652   propertyMap["BUTTON_ACTION"] = buttonAction;
653   propertyMap["VARIATION"] = inputVariation;
654   field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
655
656   Property::Value value = field.GetProperty( TextField::Property::INPUT_METHOD_SETTINGS );
657   Property::Map map;
658   DALI_TEST_CHECK( value.Get( map ) );
659
660   int layout = 0;
661   DALI_TEST_CHECK( map[ "PANEL_LAYOUT" ].Get( layout ) );
662   DALI_TEST_EQUALS( static_cast<int>(panelLayout), layout, TEST_LOCATION );
663
664   int capital = 0;
665   DALI_TEST_CHECK( map[ "AUTO_CAPITALIZE" ].Get( capital ) );
666   DALI_TEST_EQUALS( static_cast<int>(autoCapital), capital, TEST_LOCATION );
667
668   int action = 0;
669   DALI_TEST_CHECK( map[ "BUTTON_ACTION" ].Get( action ) );
670   DALI_TEST_EQUALS( static_cast<int>(buttonAction), action, TEST_LOCATION );
671
672   int variation = 0;
673   DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) );
674   DALI_TEST_EQUALS( inputVariation, variation, TEST_LOCATION );
675
676   // Check input color property.
677   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
678   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
679
680   // Check the enable markup property.
681   DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
682   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
683   DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
684
685   // Check input font properties.
686   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
687   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
688
689   fontStyleMapSet.Clear();
690   fontStyleMapSet.Insert( "weight", "bold" );
691   fontStyleMapSet.Insert( "width", "condensed" );
692   fontStyleMapSet.Insert( "slant", "italic" );
693
694   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
695   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
696   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
697   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
698
699   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
700   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
701
702   // Reset input font style.
703   fontStyleMapSet.Clear();
704   fontStyleMapSet.Insert( "weight", "normal" );
705   fontStyleMapSet.Insert( "slant", "oblique" );
706
707   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
708   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
709   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
710   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
711
712   fontStyleMapSet.Clear();
713   fontStyleMapSet.Insert( "slant", "roman" );
714
715   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
716   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
717
718   // Replace 'roman' for 'normal'.
719   slantValue = fontStyleMapGet.Find( "slant" );
720   if( NULL != slantValue )
721   {
722     if( "normal" == slantValue->Get<std::string>() )
723     {
724       fontStyleMapGet["slant"] = "roman";
725     }
726   }
727   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
728   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
729
730   fontStyleMapSet.Clear();
731
732   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
733   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
734   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
735   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
736
737   Property::Map underlineMapSet;
738   Property::Map underlineMapGet;
739
740   underlineMapSet.Insert( "enable", true );
741   underlineMapSet.Insert( "color", Color::RED );
742   underlineMapSet.Insert( "height", 1 );
743
744   // Check the underline property
745   field.SetProperty( TextField::Property::UNDERLINE, underlineMapSet );
746
747   underlineMapGet = field.GetProperty<Property::Map>( TextField::Property::UNDERLINE );
748   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
749   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
750
751   // Check the input underline property
752   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
753   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
754
755   // Check the shadow property
756   Property::Map shadowMapSet;
757   Property::Map shadowMapGet;
758
759   shadowMapSet.Insert( "color", Color::GREEN );
760   shadowMapSet.Insert( "offset", Vector2(2.0f, 2.0f) );
761   shadowMapSet.Insert( "blurRadius", 3.0f );
762
763   field.SetProperty( TextField::Property::SHADOW, shadowMapSet );
764
765   shadowMapGet = field.GetProperty<Property::Map>( TextField::Property::SHADOW );
766   DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
767   DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
768
769   // Check the input shadow property
770   field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
771   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
772
773   // Check the emboss property
774   field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
775   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
776
777   // Check the input emboss property
778   field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
779   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
780
781   // Check the outline property
782
783   // Test string type first
784   // This is purely to maintain backward compatibility, but we don't support string as the outline property type.
785   field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
786   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
787
788   // Then test the property map type
789   Property::Map outlineMapSet;
790   Property::Map outlineMapGet;
791
792   outlineMapSet["color"] = Color::RED;
793   outlineMapSet["width"] = 2.0f;
794
795   field.SetProperty( TextField::Property::OUTLINE, outlineMapSet );
796
797   outlineMapGet = field.GetProperty<Property::Map>( TextField::Property::OUTLINE );
798   DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION );
799   DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION );
800
801   // Check the input outline property
802   field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
803   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
804
805   // Check the hidden input settings property
806   Property::Map hiddenMapSet;
807   Property::Map hiddenMapGet;
808   hiddenMapSet[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
809   hiddenMapSet[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 2;
810   hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 4;
811   hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
812   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, hiddenMapSet );
813
814   hiddenMapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
815   DALI_TEST_EQUALS( hiddenMapSet.Count(), hiddenMapGet.Count(), TEST_LOCATION );
816   DALI_TEST_EQUALS( DaliTestCheckMaps( hiddenMapSet, hiddenMapGet ), true, TEST_LOCATION );
817
818   // Check the pixel size of font
819   field.SetProperty( TextField::Property::PIXEL_SIZE, 20.f );
820   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
821
822   // Check the enable selection property
823   field.SetProperty( TextField::Property::ENABLE_SELECTION, false );
824   DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_SELECTION ), false, TEST_LOCATION );
825
826   // Check the placeholder property with pixel size
827   Property::Map placeholderPixelSizeMapSet;
828   Property::Map placeholderPixelSizeMapGet;
829   Property::Map placeholderFontstyleMap;
830   placeholderPixelSizeMapSet["text"] = "Setting Placeholder Text";
831   placeholderPixelSizeMapSet["textFocused"] = "Setting Placeholder Text Focused";
832   placeholderPixelSizeMapSet["color"] = Color::BLUE;
833   placeholderPixelSizeMapSet["fontFamily"] = "Arial";
834   placeholderPixelSizeMapSet["pixelSize"] = 15.0f;
835   placeholderPixelSizeMapSet["ellipsis"] = true;
836
837   placeholderFontstyleMap.Insert( "weight", "bold" );
838   placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap;
839   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
840
841   placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
842   DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
843
844   tet_infoline("Test Placeholder settings set as strings is converted correctly to Property Index key and holds set value");
845   Property::Map placeholderConversionMap;
846   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
847   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
848   placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
849   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
850   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
851   placeholderConversionMap[ Text::PlaceHolder::Property::PIXEL_SIZE ] = placeholderPixelSizeMapSet["pixelSize"];
852
853   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderConversionMap ), true, TEST_LOCATION );
854
855   // Check the placeholder property with point size
856   Property::Map placeholderMapSet;
857   Property::Map placeholderMapGet;
858   placeholderMapSet["text"] = "Setting Placeholder Text";
859   placeholderMapSet["textFocused"] = "Setting Placeholder Text Focused";
860   placeholderMapSet["color"] = Color::RED;
861   placeholderMapSet["fontFamily"] = "Arial";
862   placeholderMapSet["pointSize"] = 12.0f;
863   placeholderMapSet["ellipsis"] = false;
864
865   // Check the placeholder font style property
866   placeholderFontstyleMap.Clear();
867
868   placeholderFontstyleMap.Insert( "weight", "bold" );
869   placeholderFontstyleMap.Insert( "width", "condensed" );
870   placeholderFontstyleMap.Insert( "slant", "italic" );
871   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
872   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
873
874   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
875   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
876
877   placeholderConversionMap.Clear();
878   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
879   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
880   placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
881   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
882   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
883   placeholderConversionMap[ Text::PlaceHolder::Property::POINT_SIZE ] = placeholderPixelSizeMapSet["pointSize"];
884
885   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
886
887   // Reset font style.
888   placeholderFontstyleMap.Clear();
889   placeholderFontstyleMap.Insert( "weight", "normal" );
890   placeholderFontstyleMap.Insert( "slant", "oblique" );
891   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
892   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
893
894   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
895   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
896
897   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
898   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
899
900   placeholderFontstyleMap.Clear();
901   placeholderFontstyleMap.Insert( "slant", "roman" );
902   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
903   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
904
905   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
906
907   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
908
909   placeholderFontstyleMap.Clear();
910   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
911   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
912
913   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
914   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
915   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
916
917   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
918
919   // Check the ellipsis property
920   DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
921   field.SetProperty( TextField::Property::ELLIPSIS, true );
922   DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
923
924   field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
925   DALI_TEST_EQUALS( field.GetProperty<int>( Actor::Property::LAYOUT_DIRECTION ), static_cast<int>( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
926
927   // Test the ENABLE_GRAB_HANDLE_POPUP property
928   DALI_TEST_CHECK( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP ) );
929   field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP, false );
930   DALI_TEST_CHECK( !field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP ) );
931
932   application.SendNotification();
933   application.Render();
934
935   END_TEST;
936 }
937
938 // Positive Atlas Text Renderer test
939 int utcDaliTextFieldAtlasRenderP(void)
940 {
941   ToolkitTestApplication application;
942   tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
943   StyleManager styleManager = StyleManager::Get();
944   styleManager.ApplyDefaultTheme();
945   TextField field = TextField::New();
946   DALI_TEST_CHECK( field );
947
948   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
949
950   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
951
952   Stage::GetCurrent().Add( field );
953
954   try
955   {
956     // Render some text with the shared atlas backend
957     field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
958     application.SendNotification();
959     application.Render();
960   }
961   catch( ... )
962   {
963     tet_result(TET_FAIL);
964   }
965   END_TEST;
966 }
967
968 // Positive test for the textChanged signal.
969 int utcDaliTextFieldTextChangedP(void)
970 {
971   ToolkitTestApplication application;
972   tet_infoline(" utcDaliTextFieldTextChangedP");
973   TextField field = TextField::New();
974   DALI_TEST_CHECK( field );
975
976   Stage::GetCurrent().Add( field );
977
978   // connect to the text changed signal.
979   ConnectionTracker* testTracker = new ConnectionTracker();
980   field.TextChangedSignal().Connect(&TestTextChangedCallback);
981   bool textChangedSignal = false;
982   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
983
984   gTextChangedCallBackCalled = false;
985   field.SetProperty( TextField::Property::TEXT, "ABC" );
986   DALI_TEST_CHECK( gTextChangedCallBackCalled );
987   DALI_TEST_CHECK( textChangedSignal );
988
989   application.SendNotification();
990
991   field.SetKeyInputFocus();
992
993   gTextChangedCallBackCalled = false;
994   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
995   DALI_TEST_CHECK( gTextChangedCallBackCalled );
996
997   END_TEST;
998 }
999
1000 // Negative test for the textChanged signal.
1001 int utcDaliTextFieldTextChangedN(void)
1002 {
1003   ToolkitTestApplication application;
1004   tet_infoline(" utcDaliTextFieldTextChangedN");
1005   TextField field = TextField::New();
1006   DALI_TEST_CHECK( field );
1007
1008   Stage::GetCurrent().Add( field );
1009
1010   // connect to the text changed signal.
1011   ConnectionTracker* testTracker = new ConnectionTracker();
1012   field.TextChangedSignal().Connect(&TestTextChangedCallback);
1013   bool textChangedSignal = false;
1014   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
1015
1016   gTextChangedCallBackCalled = false;
1017   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
1018   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1019   DALI_TEST_CHECK( !textChangedSignal );
1020
1021   END_TEST;
1022 }
1023
1024 // Positive test for Max Characters reached signal.
1025 int utcDaliTextFieldMaxCharactersReachedP(void)
1026 {
1027   ToolkitTestApplication application;
1028   tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
1029   TextField field = TextField::New();
1030   DALI_TEST_CHECK( field );
1031
1032   Stage::GetCurrent().Add( field );
1033
1034   const int maxNumberOfCharacters = 1;
1035   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1036
1037   field.SetKeyInputFocus();
1038
1039   // connect to the text changed signal.
1040   ConnectionTracker* testTracker = new ConnectionTracker();
1041   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1042   bool maxLengthReachedSignal = false;
1043   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
1044
1045   gMaxCharactersCallBackCalled = false;
1046
1047   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1048   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1049
1050   DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
1051   DALI_TEST_CHECK( maxLengthReachedSignal );
1052
1053   END_TEST;
1054 }
1055
1056 // Negative test for Max Characters reached signal.
1057 int utcDaliTextFieldMaxCharactersReachedN(void)
1058 {
1059   ToolkitTestApplication application;
1060   tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
1061   TextField field = TextField::New();
1062   DALI_TEST_CHECK( field );
1063
1064   Stage::GetCurrent().Add( field );
1065
1066   const int maxNumberOfCharacters = 3;
1067   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1068
1069   field.SetKeyInputFocus();
1070
1071   // connect to the text changed signal.
1072   ConnectionTracker* testTracker = new ConnectionTracker();
1073   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1074   bool maxLengthReachedSignal = false;
1075   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
1076
1077   gMaxCharactersCallBackCalled = false;
1078
1079   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1080   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1081
1082   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1083   DALI_TEST_CHECK( !maxLengthReachedSignal );
1084
1085   application.ProcessEvent( GenerateKey( "Return", "", "\r", KEY_RETURN_CODE, 0, 0, Integration::KeyEvent::Down, "\r", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1086
1087   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1088   DALI_TEST_CHECK( !maxLengthReachedSignal );
1089
1090   END_TEST;
1091 }
1092
1093 int utcDaliTextFieldInputStyleChanged01(void)
1094 {
1095   // The text-field emits signals when the input style changes. These changes of style are
1096   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1097   // can't be emitted during the size negotiation as the callbacks may update the UI.
1098   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1099   // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks.
1100   ToolkitTestApplication application;
1101   tet_infoline(" utcDaliTextFieldInputStyleChanged01");
1102
1103   // Load some fonts.
1104
1105   char* pathNamePtr = get_current_dir_name();
1106   const std::string pathName( pathNamePtr );
1107   free( pathNamePtr );
1108
1109   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1110   fontClient.SetDpi( 93u, 93u );
1111
1112   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1113   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1114
1115   TextField field = TextField::New();
1116   DALI_TEST_CHECK( field );
1117
1118
1119   field.SetSize( 300.f, 50.f );
1120   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1121   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1122
1123   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1124   field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
1125
1126   // connect to the text changed signal.
1127   ConnectionTracker* testTracker = new ConnectionTracker();
1128   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1129   bool inputStyleChangedSignal = false;
1130   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1131
1132   Stage::GetCurrent().Add( field );
1133
1134   // Render and notify
1135   application.SendNotification();
1136   application.Render();
1137
1138   // Executes the idle callbacks added by the text control on the change of input style.
1139   application.RunIdles();
1140
1141   gInputStyleChangedCallbackCalled = false;
1142   gInputStyleMask = TextField::InputStyle::NONE;
1143   inputStyleChangedSignal = false;
1144
1145   // Create a tap event to touch the text field.
1146   TestGenerateTap( application, 18.0f, 25.0f );
1147
1148   // Render and notify
1149   application.SendNotification();
1150   application.Render();
1151
1152   // Executes the idle callbacks added by the text control on the change of input style.
1153   application.RunIdles();
1154
1155   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1156   if( gInputStyleChangedCallbackCalled )
1157   {
1158     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
1159
1160     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1161     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1162
1163     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1164     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1165   }
1166   DALI_TEST_CHECK( inputStyleChangedSignal );
1167
1168   gInputStyleChangedCallbackCalled = false;
1169   gInputStyleMask = TextField::InputStyle::NONE;
1170   inputStyleChangedSignal = false;
1171
1172   // Create a tap event to touch the text field.
1173   TestGenerateTap( application, 30.0f, 25.0f );
1174
1175   // Render and notify
1176   application.SendNotification();
1177   application.Render();
1178
1179   // Executes the idle callbacks added by the text control on the change of input style.
1180   application.RunIdles();
1181
1182   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1183   DALI_TEST_CHECK( !inputStyleChangedSignal );
1184
1185   gInputStyleChangedCallbackCalled = false;
1186   gInputStyleMask = TextField::InputStyle::NONE;
1187   inputStyleChangedSignal = false;
1188
1189   // Create a tap event to touch the text field.
1190   TestGenerateTap( application, 43.0f, 25.0f );
1191
1192   // Render and notify
1193   application.SendNotification();
1194   application.Render();
1195
1196   // Executes the idle callbacks added by the text control on the change of input style.
1197   application.RunIdles();
1198
1199   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1200   if( gInputStyleChangedCallbackCalled )
1201   {
1202     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1203
1204     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1205     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1206   }
1207   DALI_TEST_CHECK( inputStyleChangedSignal );
1208
1209   gInputStyleChangedCallbackCalled = false;
1210   gInputStyleMask = TextField::InputStyle::NONE;
1211   inputStyleChangedSignal = false;
1212
1213   // Create a tap event to touch the text field.
1214   TestGenerateTap( application, 88.0f, 25.0f );
1215
1216   // Render and notify
1217   application.SendNotification();
1218   application.Render();
1219
1220   // Executes the idle callbacks added by the text control on the change of input style.
1221   application.RunIdles();
1222
1223   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1224   if( gInputStyleChangedCallbackCalled )
1225   {
1226     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1227
1228     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1229     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1230
1231     const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1232
1233     Property::Map fontStyleMapSet;
1234     fontStyleMapSet.Insert( "weight", "bold" );
1235
1236     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1237     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1238   }
1239   DALI_TEST_CHECK( inputStyleChangedSignal );
1240
1241   gInputStyleChangedCallbackCalled = false;
1242   gInputStyleMask = TextField::InputStyle::NONE;
1243   inputStyleChangedSignal = false;
1244
1245   // Create a tap event to touch the text field.
1246   TestGenerateTap( application, 115.0f, 25.0f );
1247
1248   // Render and notify
1249   application.SendNotification();
1250   application.Render();
1251
1252   // Executes the idle callbacks added by the text control on the change of input style.
1253   application.RunIdles();
1254
1255   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1256   DALI_TEST_CHECK( !inputStyleChangedSignal );
1257
1258   gInputStyleChangedCallbackCalled = false;
1259   gInputStyleMask = TextField::InputStyle::NONE;
1260   inputStyleChangedSignal = false;
1261
1262   // Create a tap event to touch the text field.
1263   TestGenerateTap( application, 164.0f, 25.0f );
1264
1265   // Render and notify
1266   application.SendNotification();
1267   application.Render();
1268
1269   // Executes the idle callbacks added by the text control on the change of input style.
1270   application.RunIdles();
1271
1272   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1273   if( gInputStyleChangedCallbackCalled )
1274   {
1275     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1276
1277     const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1278     DALI_TEST_CHECK( style.empty() );
1279   }
1280   DALI_TEST_CHECK( inputStyleChangedSignal );
1281
1282   gInputStyleChangedCallbackCalled = false;
1283   gInputStyleMask = TextField::InputStyle::NONE;
1284   inputStyleChangedSignal = false;
1285
1286   // Create a tap event to touch the text field.
1287   TestGenerateTap( application, 191.0f, 25.0f );
1288
1289   // Render and notify
1290   application.SendNotification();
1291   application.Render();
1292
1293   // Executes the idle callbacks added by the text control on the change of input style.
1294   application.RunIdles();
1295
1296   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1297   DALI_TEST_CHECK( !inputStyleChangedSignal );
1298
1299   END_TEST;
1300 }
1301
1302 int utcDaliTextFieldInputStyleChanged02(void)
1303 {
1304   // The text-field emits signals when the input style changes. These changes of style are
1305   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1306   // can't be emitted during the size negotiation as the callbacks may update the UI.
1307   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1308   // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks.
1309   ToolkitTestApplication application;
1310   tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1311
1312   // Load some fonts.
1313
1314   char* pathNamePtr = get_current_dir_name();
1315   const std::string pathName( pathNamePtr );
1316   free( pathNamePtr );
1317
1318   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1319   fontClient.SetDpi( 93u, 93u );
1320
1321   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1322   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1323
1324   TextField field = TextField::New();
1325   DALI_TEST_CHECK( field );
1326
1327   field.SetSize( 300.f, 50.f );
1328   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1329   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1330
1331   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1332   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>" );
1333
1334   // connect to the text changed signal.
1335   ConnectionTracker* testTracker = new ConnectionTracker();
1336   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1337   bool inputStyleChangedSignal = false;
1338   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1339
1340   Stage::GetCurrent().Add( field );
1341
1342   // Render and notify
1343   application.SendNotification();
1344   application.Render();
1345
1346   // Executes the idle callbacks added by the text control on the change of input style.
1347   application.RunIdles();
1348
1349   gInputStyleChangedCallbackCalled = false;
1350   gInputStyleMask = TextField::InputStyle::NONE;
1351   inputStyleChangedSignal = false;
1352
1353   // Create a tap event to touch the text field.
1354   TestGenerateTap( application, 53.0f, 25.0f, 100 );
1355   TestGenerateTap( application, 53.0f, 25.0f, 200 );
1356
1357   // Render and notify
1358   application.SendNotification();
1359   application.Render();
1360
1361   // Executes the idle callbacks added by the text control on the change of input style.
1362   application.RunIdles();
1363
1364   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1365   if( gInputStyleChangedCallbackCalled )
1366   {
1367     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1368                       static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1369                                                  TextField::InputStyle::POINT_SIZE  |
1370                                                  TextField::InputStyle::COLOR ),
1371                       TEST_LOCATION );
1372
1373     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1374     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1375
1376     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1377     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1378
1379     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1380     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1381   }
1382   DALI_TEST_CHECK( inputStyleChangedSignal );
1383
1384   gInputStyleChangedCallbackCalled = false;
1385   gInputStyleMask = TextField::InputStyle::NONE;
1386   inputStyleChangedSignal = false;
1387
1388   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1389
1390   // Render and notify
1391   application.SendNotification();
1392   application.Render();
1393
1394   // Executes the idle callbacks added by the text control on the change of input style.
1395   application.RunIdles();
1396
1397   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1398   if( gInputStyleChangedCallbackCalled )
1399   {
1400     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1401                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1402                       TEST_LOCATION );
1403
1404     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1405     DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1406   }
1407   DALI_TEST_CHECK( inputStyleChangedSignal );
1408
1409   gInputStyleChangedCallbackCalled = false;
1410   gInputStyleMask = TextField::InputStyle::NONE;
1411   inputStyleChangedSignal = false;
1412
1413   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1414
1415   // Render and notify
1416   application.SendNotification();
1417   application.Render();
1418
1419   // Executes the idle callbacks added by the text control on the change of input style.
1420   application.RunIdles();
1421
1422   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1423   DALI_TEST_CHECK( !inputStyleChangedSignal );
1424
1425   gInputStyleChangedCallbackCalled = false;
1426   gInputStyleMask = TextField::InputStyle::NONE;
1427   inputStyleChangedSignal = false;
1428
1429   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1430
1431   // Render and notify
1432   application.SendNotification();
1433   application.Render();
1434
1435   // Executes the idle callbacks added by the text control on the change of input style.
1436   application.RunIdles();
1437
1438   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1439   if( gInputStyleChangedCallbackCalled )
1440   {
1441     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1442                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1443                       TEST_LOCATION );
1444
1445     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1446     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1447   }
1448   DALI_TEST_CHECK( inputStyleChangedSignal );
1449
1450   gInputStyleChangedCallbackCalled = false;
1451   gInputStyleMask = TextField::InputStyle::NONE;
1452   inputStyleChangedSignal = false;
1453
1454   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1455
1456   Property::Map fontStyleMapSet;
1457   fontStyleMapSet.Insert( "weight", "thin" );
1458   fontStyleMapSet.Insert( "width", "condensed" );
1459   fontStyleMapSet.Insert( "slant", "italic" );
1460
1461   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1462   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1463
1464   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1465   field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1466   field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1467   field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1468
1469   // Render and notify
1470   application.SendNotification();
1471   application.Render();
1472
1473   // Executes the idle callbacks added by the text control on the change of input style.
1474   application.RunIdles();
1475
1476   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1477   DALI_TEST_CHECK( !inputStyleChangedSignal );
1478
1479   // Create a tap event to touch the text field.
1480   TestGenerateTap( application, 63.0f, 25.0f, 300 );
1481
1482   // Render and notify
1483   application.SendNotification();
1484   application.Render();
1485
1486   // Executes the idle callbacks added by the text control on the change of input style.
1487   application.RunIdles();
1488
1489   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1490   if( gInputStyleChangedCallbackCalled )
1491   {
1492     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1493                       static_cast<unsigned int>( TextField::InputStyle::COLOR |
1494                                                  TextField::InputStyle::POINT_SIZE |
1495                                                  TextField::InputStyle::FONT_STYLE |
1496                                                  TextField::InputStyle::UNDERLINE |
1497                                                  TextField::InputStyle::SHADOW |
1498                                                  TextField::InputStyle::EMBOSS |
1499                                                  TextField::InputStyle::OUTLINE ),
1500                       TEST_LOCATION );
1501
1502     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1503     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1504   }
1505   DALI_TEST_CHECK( inputStyleChangedSignal );
1506
1507   END_TEST;
1508 }
1509
1510 int utcDaliTextFieldEvent01(void)
1511 {
1512   ToolkitTestApplication application;
1513   tet_infoline(" utcDaliTextFieldEvent01");
1514
1515   // Creates a tap event. After creating a tap event the text field should
1516   // have the focus and add text with key events should be possible.
1517
1518   TextField field = TextField::New();
1519   DALI_TEST_CHECK( field );
1520
1521   Stage::GetCurrent().Add( field );
1522
1523   field.SetSize( 300.f, 50.f );
1524   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1525   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1526
1527   // Render and notify
1528   application.SendNotification();
1529   application.Render();
1530
1531   // Avoid a crash when core load gl resources.
1532   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1533
1534   // Render and notify
1535   application.SendNotification();
1536   application.Render();
1537
1538   // Add a key event but as the text field has not the focus it should do nothing.
1539   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1540
1541   // Render and notify
1542   application.SendNotification();
1543   application.Render();
1544
1545   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1546
1547   // Create a tap event to touch the text field.
1548   TestGenerateTap( application, 150.0f, 25.0f );
1549
1550   // Render and notify
1551   application.SendNotification();
1552   application.Render();
1553
1554   // Pressing delete key should be fine even if there is no text in TextField.
1555   application.ProcessEvent( GenerateKey( "Delete", "", "Delete", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::Down, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1556   // Render and notify
1557   application.SendNotification();
1558   application.Render();
1559
1560   // Now the text field has the focus, so it can handle the key events.
1561   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1562   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1563
1564   // Render and notify
1565   application.SendNotification();
1566   application.Render();
1567
1568   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1569
1570   // Create a second text field and send key events to it.
1571   TextField field2 = TextField::New();
1572
1573   field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1574   field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1575   field2.SetSize( 100.f, 100.0f );
1576   field2.SetPosition( 100.0f, 100.0f );
1577
1578   Stage::GetCurrent().Add( field2 );
1579
1580   // Render and notify
1581   application.SendNotification();
1582   application.Render();
1583
1584   // Create a tap event on the second text field.
1585   TestGenerateTap( application, 150.0f, 125.0f );
1586
1587   // Render and notify
1588   application.SendNotification();
1589   application.Render();
1590
1591   // The second text field has the focus. It should handle the key events.
1592   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1593   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1594
1595   // Render and notify
1596   application.SendNotification();
1597   application.Render();
1598
1599   // Check the text has been added to the second text field.
1600   DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1601
1602   END_TEST;
1603 }
1604
1605 int utcDaliTextFieldEvent02(void)
1606 {
1607   ToolkitTestApplication application;
1608   tet_infoline(" utcDaliTextFieldEvent02");
1609
1610   // Checks if the right number of actors are created.
1611
1612   TextField field = TextField::New();
1613   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1614   DALI_TEST_CHECK( field );
1615   LoadMarkerImages(application, field);
1616
1617   Stage::GetCurrent().Add( field );
1618
1619   field.SetSize( 300.0f, 50.0f );
1620   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1621   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1622
1623   // Avoid a crash when core load gl resources.
1624   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1625
1626   // Render and notify
1627   application.SendNotification();
1628   application.Render();
1629
1630   // Check there are the expected number of children ( stencil ).
1631   DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1632
1633   Actor stencil = field.GetChildAt( 0u );
1634   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1635
1636   // Create a tap event to touch the text field.
1637   TestGenerateTap( application, 150.0f, 25.0f, 300 );
1638
1639   // Render and notify
1640   application.SendNotification();
1641   application.Render();
1642
1643   Actor layer = field.GetChildAt( 1u );
1644   DALI_TEST_CHECK( layer.IsLayer() );
1645
1646   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1647   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1648
1649   // Now the text field has the focus, so it can handle the key events.
1650   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1651   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1652
1653   // Render and notify
1654   application.SendNotification();
1655   application.Render();
1656
1657   // Checks the cursor and the renderer have been created.
1658   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1659   DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1660
1661   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1662   DALI_TEST_CHECK( cursor );
1663
1664   // The offscreen root actor has a container with all the actors which contain the text renderers.
1665   Actor container = stencil.GetChildAt( 0u );
1666   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1667   {
1668     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1669     DALI_TEST_CHECK( renderer );
1670   }
1671
1672   // Move the cursor and check the position changes.
1673   Vector3 position1 = cursor.GetCurrentPosition();
1674   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1675
1676   // Render and notify
1677   application.SendNotification();
1678   application.Render();
1679
1680   Vector3 position2 = cursor.GetCurrentPosition();
1681   DALI_TEST_CHECK( position2.x < position1.x );
1682
1683   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1684
1685   // Render and notify
1686   application.SendNotification();
1687   application.Render();
1688
1689   Vector3 position3 = cursor.GetCurrentPosition();
1690   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1691
1692
1693   // Move the cursor to the first position.
1694   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1695   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1696
1697   // Render and notify
1698   application.SendNotification();
1699   application.Render();
1700
1701   Vector3 position4 = cursor.GetCurrentPosition();
1702
1703   // Send some taps and check the cursor positions.
1704
1705   // Try to tap at the beginning.
1706   TestGenerateTap( application, 1.0f, 25.0f, 900 );
1707
1708   // Render and notify
1709   application.SendNotification();
1710   application.Render();
1711
1712   // Cursor position should be the same than position1.
1713   Vector3 position5 = cursor.GetCurrentPosition();
1714
1715   DALI_TEST_EQUALS( position4, position5, TEST_LOCATION ); // Should be in the same position2.
1716
1717   // Tap away from the start position.
1718   TestGenerateTap( application, 16.0f, 25.0f, 1500 );
1719
1720   // Render and notify
1721   application.SendNotification();
1722   application.Render();
1723
1724   Vector3 position6 = cursor.GetCurrentPosition();
1725
1726   DALI_TEST_CHECK( position6.x > position5.x );
1727
1728   // Remove all the text.
1729   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1730   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1731   field.SetProperty( TextField::Property::TEXT, "" );
1732
1733   // Render and notify
1734   application.SendNotification();
1735   application.Render();
1736
1737   // Cursor position should be the same than position2.
1738   Vector3 position7 = cursor.GetCurrentPosition();
1739
1740   DALI_TEST_EQUALS( position4, position7, TEST_LOCATION );// Should be in the same position2.
1741
1742   // Should not be a renderer.
1743   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1744
1745   // Chanege exceed policy (EXCEED_POLICY_ORIGINAL doesn't use stencil )
1746   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1747   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
1748
1749   application.SendNotification();
1750   application.Render();
1751
1752   // There are renderer and decorator layer
1753   DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
1754
1755   END_TEST;
1756 }
1757
1758 int utcDaliTextFieldEvent03(void)
1759 {
1760   ToolkitTestApplication application;
1761   tet_infoline(" utcDaliTextFieldEvent03");
1762
1763   // Checks if the highlight actor is created.
1764
1765   TextField field = TextField::New();
1766   DALI_TEST_CHECK( field );
1767
1768   Stage::GetCurrent().Add( field );
1769
1770   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1771   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1772   field.SetSize( 30.f, 50.f );
1773   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1774   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1775
1776   // Avoid a crash when core load gl resources.
1777   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1778   LoadMarkerImages(application, field);
1779
1780   // Render and notify
1781   application.SendNotification();
1782   application.Render();
1783
1784   // Tap first to get the focus.
1785   TestGenerateTap( application, 3.0f, 25.0f );
1786
1787   // Render and notify
1788   application.SendNotification();
1789   application.Render();
1790
1791   // Double tap to select a word.
1792   TestGenerateTap( application, 3.0f, 25.0f );
1793
1794   // Render and notify
1795   application.SendNotification();
1796   application.Render();
1797
1798   // The offscreen root actor should have two actors: the renderer and the highlight actor.
1799   Actor stencil = field.GetChildAt( 0u );
1800
1801   // The highlight actor is drawn first, so is the first actor in the list
1802   Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
1803   DALI_TEST_CHECK( highlight );
1804
1805   // The offscreen root actor has a container with all the actors which contain the text renderers.
1806   Actor container = stencil.GetChildAt( 1u );
1807   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1808   {
1809     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1810     DALI_TEST_CHECK( renderer );
1811   }
1812
1813   END_TEST;
1814 }
1815
1816 int utcDaliTextFieldEvent04(void)
1817 {
1818   ToolkitTestApplication application;
1819   tet_infoline(" utcDaliTextFieldEvent04");
1820
1821   // Checks if the highlight actor is created.
1822
1823   TextField field = TextField::New();
1824   DALI_TEST_CHECK( field );
1825   Stage::GetCurrent().Add( field );
1826   LoadMarkerImages(application, field);
1827   // Render and notify
1828   application.SendNotification();
1829   application.Render();
1830
1831   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1832   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1833   field.SetSize( 300.f, 50.f );
1834   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1835   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1836
1837   // Avoid a crash when core load gl resources.
1838   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1839   // Render and notify
1840   application.SendNotification();
1841   application.Render();
1842
1843   // Create a tap event to touch the text field.
1844   TestGenerateTap( application, 150.0f, 25.0f );
1845   // Render and notify
1846   application.SendNotification();
1847   application.Render();
1848
1849
1850   // Tap first to get the focus.
1851   TestGenerateTap( application, 1.0f, 25.0f );
1852
1853   // Render and notify
1854   application.SendNotification();
1855   application.Render();
1856
1857   // Double tap to select a word.
1858   TestGenerateTap( application, 1.0f, 25.0f );
1859
1860   // Render and notify
1861   application.SendNotification();
1862   application.Render();
1863
1864   // Tap grab handle
1865   TestGenerateTap( application, 0.0f, 40.0f );
1866   END_TEST;
1867 }
1868
1869 int utcDaliTextFieldEvent05(void)
1870 {
1871   ToolkitTestApplication application;
1872   tet_infoline(" utcDaliTextFieldEvent05");
1873
1874   // Checks dragging of cursor/grab handle
1875
1876   TextField field = TextField::New();
1877   DALI_TEST_CHECK( field );
1878   Stage::GetCurrent().Add( field );
1879   LoadMarkerImages(application, field);
1880   // Render and notify
1881   application.SendNotification();
1882   application.Render();
1883
1884   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1885   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1886   field.SetSize( 300.f, 50.f );
1887   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1888   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1889
1890   // Avoid a crash when core load gl resources.
1891   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1892   // Render and notify
1893   application.SendNotification();
1894   application.Render();
1895
1896   // Create a tap event to touch the text field.
1897   TestGenerateTap( application, 150.0f, 25.0f );
1898   // Render and notify
1899   application.SendNotification();
1900   application.Render();
1901
1902   // Tap first to get the focus.
1903   TestGenerateTap( application, 1.0f, 25.0f );
1904
1905   // Render and notify
1906   application.SendNotification();
1907   application.Render();
1908
1909   // Double tap to select a word.
1910   TestGenerateTap( application, 1.0f, 25.0f );
1911
1912   // Render and notify
1913   application.SendNotification();
1914   application.Render();
1915
1916   Actor stencil = field.GetChildAt( 1u );
1917   END_TEST;
1918 }
1919
1920 int utcDaliTextFieldEvent06(void)
1921 {
1922   ToolkitTestApplication application;
1923   tet_infoline(" utcDaliTextFieldEvent06");
1924
1925   // Checks Longpress when in edit mode
1926
1927   TextField field = TextField::New();
1928   DALI_TEST_CHECK( field );
1929   Stage::GetCurrent().Add( field );
1930   LoadMarkerImages(application, field);
1931   // Render and notify
1932   application.SendNotification();
1933   application.Render();
1934
1935   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1936   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1937   field.SetSize( 300.f, 50.f );
1938   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1939   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1940
1941   // Avoid a crash when core load gl resources.
1942   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1943   // Render and notify
1944   application.SendNotification();
1945   application.Render();
1946
1947   // Create a tap event to touch the text field.
1948   TestGenerateTap( application, 150.0f, 25.0f );
1949   // Render and notify
1950   application.SendNotification();
1951   application.Render();
1952
1953
1954   // Tap first to get the focus.
1955   TestGenerateTap( application, 1.0f, 25.0f );
1956
1957   // Render and notify
1958   application.SendNotification();
1959   application.Render();
1960
1961   // Long Press
1962   TestGenerateLongPress(application, 1.0f, 25.0f);
1963
1964   // Render and notify
1965   application.SendNotification();
1966   application.Render();
1967
1968   END_TEST;
1969 }
1970
1971 int utcDaliTextFieldEvent07(void)
1972 {
1973   ToolkitTestApplication application;
1974   tet_infoline(" utcDaliTextFieldEvent07");
1975
1976   // Checks Longpress to start edit mode
1977
1978   TextField field = TextField::New();
1979   DALI_TEST_CHECK( field );
1980   Stage::GetCurrent().Add( field );
1981   LoadMarkerImages(application, field);
1982   // Render and notify
1983   application.SendNotification();
1984   application.Render();
1985
1986   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1987   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1988   field.SetSize( 300.f, 50.f );
1989   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1990   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1991   Property::Map propertyMap;
1992   propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD;
1993   field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
1994
1995   // Avoid a crash when core load gl resources.
1996   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1997   // Render and notify
1998   application.SendNotification();
1999   application.Render();
2000
2001   // Long Press
2002   TestGenerateLongPress(application, 1.0f, 25.0f);
2003
2004   // Render and notify
2005   application.SendNotification();
2006   application.Render();
2007
2008   END_TEST;
2009 }
2010
2011 int utcDaliTextFieldEvent08(void)
2012 {
2013   ToolkitTestApplication application;
2014   tet_infoline(" utcDaliTextFieldEvent08");
2015
2016   Dali::Clipboard clipboard = Clipboard::Get();
2017   clipboard.SetItem("testTextFieldEvent");
2018
2019   // Checks Longpress when only place holder text
2020
2021   TextField field = TextField::New();
2022   DALI_TEST_CHECK( field );
2023   Stage::GetCurrent().Add( field );
2024   LoadMarkerImages(application, field);
2025   // Render and notify
2026   application.SendNotification();
2027   application.Render();
2028
2029   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
2030   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2031   field.SetSize( 300.f, 50.f );
2032   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2033   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2034
2035   // Avoid a crash when core load gl resources.
2036   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2037   // Render and notify
2038   application.SendNotification();
2039   application.Render();
2040
2041   // Long Press
2042   TestGenerateLongPress( application, 1.0f, 25.0f, 20 );
2043
2044   // Render and notify
2045   application.SendNotification();
2046   application.Render();
2047
2048   Wait(application, 500);
2049
2050   TestEndLongPress( application, 1.0f, 25.0f, 520 );
2051
2052   // Long Press
2053   TestGenerateLongPress( application, 1.0f, 25.0f, 600 );
2054
2055   // Render and notify
2056   application.Render();
2057
2058   Wait(application, 500);
2059
2060   Stage stage = Stage::GetCurrent();
2061   Layer layer = stage.GetRootLayer();
2062   Actor actor = layer.FindChildByName("optionPaste");
2063
2064   if (actor)
2065   {
2066     Vector3 worldPosition = actor.GetCurrentWorldPosition();
2067     Vector2 halfStageSize = stage.GetSize() / 2.0f;
2068     Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
2069
2070     Dali::Integration::TouchEvent event;
2071     event = Dali::Integration::TouchEvent();
2072     event.AddPoint( GetPointDownInside( position ) );
2073     application.ProcessEvent( event );
2074
2075     event = Dali::Integration::TouchEvent();
2076     event.AddPoint( GetPointUpInside( position ) );
2077     application.ProcessEvent( event );
2078   }
2079   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
2080
2081   END_TEST;
2082 }
2083
2084 int utcDaliTextFieldEvent09(void)
2085 {
2086   ToolkitTestApplication application;
2087   tet_infoline(" utcDaliTextFieldEvent09");
2088
2089   TextField field = TextField::New();
2090   DALI_TEST_CHECK( field );
2091   Stage::GetCurrent().Add( field );
2092   LoadMarkerImages(application, field);
2093   // Render and notify
2094   application.SendNotification();
2095   application.Render();
2096
2097   field.SetProperty( TextField::Property::TEXT, "Hello" );
2098   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2099   field.SetSize( 300.f, 50.f );
2100   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2101   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2102
2103   // Avoid a crash when core load gl resources.
2104   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2105
2106   // Create a tap event to touch the text field.
2107   TestGenerateTap( application, 150.0f, 25.0f );
2108   application.SendNotification();
2109   application.Render();
2110
2111   Property::Map map;
2112   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE;
2113   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2114   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2115   application.SendNotification();
2116   application.Render();
2117
2118   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
2119   map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
2120   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2121   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2122   application.SendNotification();
2123   application.Render();
2124
2125   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_COUNT;
2126   map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2127   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2128   for( unsigned int index = 0u; index < 5u; ++index )
2129   {
2130     application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2131     application.SendNotification();
2132     application.Render();
2133   }
2134
2135   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT;
2136   map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2137   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2138   for( unsigned int index = 0u; index < 5u; ++index )
2139   {
2140     application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2141     application.SendNotification();
2142     application.Render();
2143   }
2144
2145   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER;
2146   map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 0;
2147   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2148   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2149   application.SendNotification();
2150   application.Render();
2151   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2152   application.SendNotification();
2153   application.Render();
2154
2155   map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 100;
2156   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2157   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2158   application.SendNotification();
2159   application.Render();
2160
2161   Property::Map mapGet;
2162   mapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
2163   DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION );
2164   DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION );
2165   END_TEST;
2166 }
2167
2168
2169 int utcDaliTextFieldStyleWhilstSelected(void)
2170 {
2171   ToolkitTestApplication application;
2172   tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
2173
2174   // Change font and styles whilst text is selected whilst word selected
2175
2176   TextField field = TextField::New();
2177   DALI_TEST_CHECK( field );
2178   Stage::GetCurrent().Add( field );
2179   LoadMarkerImages(application, field);
2180   // Render and notify
2181   application.SendNotification();
2182   application.Render();
2183
2184   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2185   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2186   field.SetSize( 300.f, 50.f );
2187   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2188   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2189
2190   // Avoid a crash when core load gl resources.
2191   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2192   // Render and notify
2193   application.SendNotification();
2194   application.Render();
2195
2196   // Create a tap event to touch the text field.
2197   TestGenerateTap( application, 150.0f, 25.0f );
2198   // Render and notify
2199   application.SendNotification();
2200   application.Render();
2201
2202
2203   // Tap first to get the focus.
2204   TestGenerateTap( application, 1.0f, 25.0f );
2205
2206   // Render and notify
2207   application.SendNotification();
2208   application.Render();
2209
2210   // Double tap to select a word.
2211   TestGenerateTap( application, 1.0f, 25.0f );
2212
2213   // Render and notify
2214   application.SendNotification();
2215   application.Render();
2216
2217   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
2218   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
2219
2220   Property::Map fontStyleMapSet;
2221   Property::Map fontStyleMapGet;
2222
2223   fontStyleMapSet.Insert( "weight", "bold" );
2224   fontStyleMapSet.Insert( "slant", "italic" );
2225   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2226
2227   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2228   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2229   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2230
2231   fontStyleMapSet.Clear();
2232   fontStyleMapSet.Insert( "width", "expanded" );
2233   fontStyleMapSet.Insert( "slant", "italic" );
2234   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2235
2236   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2237   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2238   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2239
2240   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2241   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2242
2243   field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2244   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2245
2246   fontStyleMapSet.Clear();
2247   fontStyleMapSet.Insert( "weight", "bold" );
2248   fontStyleMapSet.Insert( "slant", "italic" );
2249
2250   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2251
2252   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2253   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2254   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2255
2256   fontStyleMapSet.Clear();
2257   fontStyleMapSet.Insert( "width", "expanded" );
2258
2259   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2260
2261   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2262   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2263   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2264
2265   // Press Escape to increase coverage
2266   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2267   application.SendNotification();
2268   application.Render();
2269
2270   DALI_TEST_CHECK( !field.HasKeyInputFocus() );
2271
2272   END_TEST;
2273 }
2274
2275 int utcDaliTextFieldEscKeyLoseFocus(void)
2276 {
2277   ToolkitTestApplication application;
2278   tet_infoline(" utcDaliTextFieldEscKeyLoseFocus");
2279
2280   // Creates a tap event. After creating a tap event the text field should
2281   // have the focus and add text with key events should be possible.
2282
2283   TextField field = TextField::New();
2284   DALI_TEST_CHECK( field );
2285
2286   Stage::GetCurrent().Add( field );
2287
2288   field.SetSize( 300.f, 50.f );
2289   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2290   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2291
2292   // Avoid a crash when core load gl resources.
2293   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2294
2295   // Render and notify
2296   application.SendNotification();
2297   application.Render();
2298
2299   // Add a key event but as the text field has not the focus it should do nothing.
2300   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2301   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2302
2303   // Render and notify
2304   application.SendNotification();
2305   application.Render();
2306
2307   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2308
2309   // Create a tap event to touch the text field.
2310   TestGenerateTap( application, 150.0f, 25.0f );
2311
2312   // Render and notify
2313   application.SendNotification();
2314   application.Render();
2315
2316   // Now the text field has the focus, so it can handle the key events.
2317   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2318   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2319   application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2320   application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Up, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2321
2322   // Render and notify
2323   application.SendNotification();
2324   application.Render();
2325
2326   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2327
2328   // Generate a Esc key event. The text field should lose the focus.
2329   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2330   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2331
2332   // Render and notify
2333   application.SendNotification();
2334   application.Render();
2335
2336   DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2337
2338   // No more text should be introduced
2339   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2340   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2341
2342   // Render and notify
2343   application.SendNotification();
2344   application.Render();
2345
2346   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2347
2348   END_TEST;
2349 }
2350
2351 int utcDaliTextFieldSomeSpecialKeys(void)
2352 {
2353   ToolkitTestApplication application;
2354   tet_infoline(" utcDaliTextFieldSomeSpecialKeys");
2355
2356   // Checks some special keys when the text is selected.
2357
2358   TextField field = TextField::New();
2359   DALI_TEST_CHECK( field );
2360   Stage::GetCurrent().Add( field );
2361   LoadMarkerImages(application, field);
2362   // Render and notify
2363   application.SendNotification();
2364   application.Render();
2365
2366   const std::string longText( "This is a long text for the size of the text-field." );
2367
2368   field.SetProperty( TextField::Property::TEXT, longText );
2369   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2370   field.SetSize( 300.f, 50.f );
2371   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2372   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2373
2374   // Avoid a crash when core load gl resources.
2375   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2376   // Render and notify
2377   application.SendNotification();
2378   application.Render();
2379
2380   // Create a tap event to touch the text field.
2381   TestGenerateTap( application, 150.0f, 25.0f );
2382
2383   // Render and notify
2384   application.SendNotification();
2385   application.Render();
2386
2387   // Tap first to get the focus.
2388   TestGenerateTap( application, 1.0f, 25.0f );
2389
2390   // Render and notify
2391   application.SendNotification();
2392   application.Render();
2393
2394   // Double tap to select a word.
2395   TestGenerateTap( application, 1.0f, 25.0f );
2396
2397   // Render and notify
2398   application.SendNotification();
2399   application.Render();
2400
2401   // Generate a Esc key event. The text field should lose the focus.
2402   application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Down, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2403   application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Up, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2404
2405   // Render and notify
2406   application.SendNotification();
2407   application.Render();
2408
2409   // Generate a Esc key event. The text field should lose the focus.
2410   application.ProcessEvent( GenerateKey( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Down, "XF86Menu", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2411   application.ProcessEvent( GenerateKey( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Up, "XF86Menu", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2412
2413   // Render and notify
2414   application.SendNotification();
2415   application.Render();
2416
2417   // Generate a Esc key event. The text field should lose the focus.
2418   application.ProcessEvent( GenerateKey( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Down, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2419   application.ProcessEvent( GenerateKey( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Up, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2420
2421   // Render and notify
2422   application.SendNotification();
2423   application.Render();
2424
2425   // The text shouldn't be deleted.
2426   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), longText, TEST_LOCATION );
2427
2428   END_TEST;
2429 }
2430
2431 int utcDaliTextFieldSizeUpdate(void)
2432 {
2433   ToolkitTestApplication application;
2434   tet_infoline("utcDaliTextFieldSizeUpdate");
2435
2436   // Checks some special keys when the text is selected.
2437   TextField field = TextField::New();
2438   DALI_TEST_CHECK( field );
2439   Stage::GetCurrent().Add( field );
2440
2441   float previousHeight = 0.0f;
2442   float currentHeight = 0.0f;
2443   const float fieldWidth = 1920.0f;
2444
2445
2446   // "ㅁ" is bigger then "ኢ"
2447   field.SetSize( Vector2( fieldWidth ,10.0f ) );
2448   field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH );
2449   field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT );
2450
2451   field.SetProperty( TextField::Property::TEXT, "ኢ");
2452   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2453   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2454
2455   field.SetKeyboardFocusable(true);
2456   KeyboardFocusManager::Get().SetCurrentFocusActor( field );
2457
2458   application.SendNotification();
2459   application.Render();
2460
2461   previousHeight = field.GetHeightForWidth( fieldWidth );
2462   DALI_TEST_EQUALS( previousHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION );
2463
2464   // Add  another script characters ( glyph height is defferent )
2465   application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2466   application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2467
2468   application.SendNotification();
2469   application.Render();
2470
2471   currentHeight = field.GetHeightForWidth( fieldWidth );
2472   DALI_TEST_EQUALS( currentHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ), TEST_LOCATION );
2473   DALI_TEST_EQUALS( (previousHeight < currentHeight), true , TEST_LOCATION );
2474
2475   END_TEST;
2476 }
2477
2478 int utcDaliTextFieldExtremlyLargePointSize(void)
2479 {
2480   ToolkitTestApplication application;
2481   tet_infoline(" utcDaliTextFieldExtremlyLargePointSize");
2482
2483   TextField field = TextField::New();
2484
2485   field.SetProperty( TextField::Property::TEXT, "Text" );
2486   field.SetSize( 300.f, 50.f );
2487   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2488   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2489   Stage::GetCurrent().Add( field );
2490
2491   try
2492   {
2493     field.SetProperty( TextField::Property::POINT_SIZE, 160.0f );
2494     application.SendNotification();
2495     DALI_TEST_CHECK( field );
2496   }
2497   catch (...)
2498   {
2499     tet_result(TET_FAIL);
2500   }
2501   END_TEST;
2502 }
2503
2504 int UtcDaliTextFieldDefaultFontStylePropertyCoverage(void)
2505 {
2506   ToolkitTestApplication application;
2507   tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage");
2508   TextField field = TextField::New();
2509   DALI_TEST_CHECK( field );
2510   Stage::GetCurrent().Add( field );
2511
2512   Property::Map fontStyleMapGet;
2513
2514   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2515
2516   Property::Value* weightValue = NULL;
2517   Property::Value* widthValue = NULL;
2518   Property::Value* slantValue = NULL;
2519   weightValue = fontStyleMapGet.Find( "weight" );
2520   widthValue = fontStyleMapGet.Find( "width" );
2521   slantValue = fontStyleMapGet.Find( "slant" );
2522   DALI_TEST_CHECK( !weightValue );
2523   DALI_TEST_CHECK( !widthValue );
2524   DALI_TEST_CHECK( !slantValue );
2525
2526   END_TEST;
2527 }
2528
2529 int UtcDaliTextFieldSettingPlaceholder(void)
2530 {
2531   ToolkitTestApplication application;
2532   tet_infoline("UtcDaliTextFieldSettingPlaceholder");
2533
2534   TextField field = TextField::New();
2535   DALI_TEST_CHECK( field );
2536   Stage::GetCurrent().Add( field );
2537
2538   // Check the placeholder property with pixel size
2539   Property::Map placeholderPixelSizeMapSet;
2540   Property::Map placeholderPixelSizeMapGet;
2541   Property::Map placeholderFontstyleMap;
2542   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2543   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2544   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::BLUE;
2545   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2546   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::PIXEL_SIZE ] = 15.0f;
2547   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
2548
2549   placeholderFontstyleMap.Insert( "weight", "bold" );
2550   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2551   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
2552
2553   placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2554   DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
2555   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION );
2556
2557   // Check the placeholder property with point size
2558   Property::Map placeholderMapSet;
2559   Property::Map placeholderMapGet;
2560   placeholderMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2561   placeholderMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2562   placeholderMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::RED;
2563   placeholderMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2564   placeholderMapSet[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
2565   placeholderMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = false;
2566
2567   // Check the placeholder font style property
2568   placeholderFontstyleMap.Clear();
2569
2570   placeholderFontstyleMap.Insert( "weight", "bold" );
2571   placeholderFontstyleMap.Insert( "width", "condensed" );
2572   placeholderFontstyleMap.Insert( "slant", "italic" );
2573   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2574   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2575
2576   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2577   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2578   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2579
2580   // Reset font style.
2581   placeholderFontstyleMap.Clear();
2582   placeholderFontstyleMap.Insert( "weight", "normal" );
2583   placeholderFontstyleMap.Insert( "slant", "oblique" );
2584   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2585   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2586
2587   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2588   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2589   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2590
2591   placeholderFontstyleMap.Clear();
2592   placeholderFontstyleMap.Insert( "slant", "roman" );
2593   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2594   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2595
2596   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2597
2598   placeholderFontstyleMap.Clear();
2599   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2600
2601   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2602   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2603   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2604   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2605
2606   END_TEST;
2607 }
2608
2609 int UtcDaliTextFieldSetPaddingProperty(void)
2610 {
2611   ToolkitTestApplication application;
2612   tet_infoline("UtcDaliTextFieldSetPaddingProperty\n");
2613
2614   TextField field = TextField::New();
2615   DALI_TEST_CHECK( field );
2616   field.SetSize( 300.f, 50.f );
2617   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2618   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2619   Stage::GetCurrent().Add( field );
2620
2621   application.SendNotification();
2622   application.Render();
2623
2624   Vector3 originalSize = field.GetNaturalSize();
2625
2626   field.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
2627
2628   application.SendNotification();
2629   application.Render();
2630
2631   DALI_TEST_EQUALS( field.GetProperty<Extents>( Toolkit::Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
2632
2633   Vector3 paddingAddedSize = field.GetNaturalSize();
2634
2635   DALI_TEST_EQUALS( originalSize.width + 10 + 10 , paddingAddedSize.width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2636
2637   DALI_TEST_EQUALS( originalSize.height + 10 + 10 , paddingAddedSize.height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2638
2639   END_TEST;
2640 }
2641
2642 int UtcDaliTextFieldEnableShiftSelectionProperty(void)
2643 {
2644   ToolkitTestApplication application;
2645   tet_infoline("UtcDaliTextFieldEnableShiftSelectionProperty");
2646
2647   TextField field = TextField::New();
2648   DALI_TEST_CHECK( field );
2649   field.SetSize( 300.0f, 50.0f );
2650   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2651   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2652   Stage::GetCurrent().Add( field );
2653
2654   application.SendNotification();
2655   application.Render();
2656
2657   // The default value of ENABLE_SHIFT_SELECTION is 'true'.
2658   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), true, TEST_LOCATION );
2659
2660   // Check the enable shift selection property
2661   field.SetProperty( DevelTextField::Property::ENABLE_SHIFT_SELECTION, false );
2662   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), false, TEST_LOCATION );
2663
2664   application.SendNotification();
2665   application.Render();
2666
2667   END_TEST;
2668 }
2669
2670 int UtcDaliTextFieldEnableGrabHandleProperty(void)
2671 {
2672   ToolkitTestApplication application;
2673   tet_infoline("UtcDaliTextFieldEnableGrabHandleProperty");
2674
2675   TextField field = TextField::New();
2676   DALI_TEST_CHECK( field );
2677   field.SetSize( 300.0f, 50.0f );
2678   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2679   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2680   Stage::GetCurrent().Add( field );
2681
2682   application.SendNotification();
2683   application.Render();
2684
2685   // The default value of ENABLE_GRAB_HANDLE is 'true'.
2686   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE ), true, TEST_LOCATION );
2687
2688   // Check the enable grab handle property
2689   field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE, false );
2690   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE ), false, TEST_LOCATION );
2691
2692   application.SendNotification();
2693   application.Render();
2694
2695   END_TEST;
2696 }
2697
2698 int UtcDaliTextFieldMatchSystemLanguageDirectionProperty(void)
2699 {
2700   ToolkitTestApplication application;
2701   tet_infoline("UtcDaliTextFieldMatchSystemLanguageDirectionProperty");
2702
2703   TextField field = TextField::New();
2704   DALI_TEST_CHECK( field );
2705   field.SetSize( 300.0f, 50.0f );
2706   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2707   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2708   Stage::GetCurrent().Add( field );
2709
2710   application.SendNotification();
2711   application.Render();
2712
2713   // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'false'.
2714   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION );
2715
2716   // Check the match system language direction property
2717   field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true );
2718   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), true, TEST_LOCATION );
2719
2720   application.SendNotification();
2721   application.Render();
2722
2723   END_TEST;
2724 }
2725
2726 int utcDaliTextFieldLayoutDirectionCoverage(void)
2727 {
2728   ToolkitTestApplication application;
2729   tet_infoline(" utcDaliTextFieldLayoutDirectionCoverage");
2730
2731   // Creates a tap event. After creating a tap event the text field should
2732   // have the focus and add text with key events should be possible.
2733   TextField field = TextField::New();
2734   DALI_TEST_CHECK( field );
2735
2736   Stage::GetCurrent().Add( field );
2737
2738   field.SetSize( 300.0f, 50.0f );
2739   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2740   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2741
2742   // Avoid a crash when core load gl resources.
2743   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2744
2745   // Render and notify
2746   application.SendNotification();
2747   application.Render();
2748
2749   // init direction for coverage
2750   // Set horizontal alignment END
2751   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END");
2752
2753   // Create a tap event to touch the text field.
2754   TestGenerateTap( application, 150.0f, 25.0f );
2755
2756   // Render and notify
2757   application.SendNotification();
2758   application.Render();
2759
2760   // Set MATCH_SYSTEM_LANGUAGE_DIRECTION to true to use the layout direction.
2761   field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true );
2762   field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
2763
2764   // Set horizontal alignment BEGIN
2765   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "BEGIN");
2766
2767   // Create a tap event to touch the text field.
2768   TestGenerateTap( application, 150.0f, 25.0f );
2769
2770   // Render and notify
2771   application.SendNotification();
2772   application.Render();
2773
2774   // Set horizontal alignment CENTER
2775   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER");
2776
2777   // Create a tap event to touch the text field.
2778   TestGenerateTap( application, 150.0f, 25.0f );
2779
2780   // Render and notify
2781   application.SendNotification();
2782   application.Render();
2783
2784   // Set horizontal alignment END
2785   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END");
2786
2787   // Create a tap event to touch the text field.
2788   TestGenerateTap( application, 150.0f, 25.0f );
2789
2790   // Render and notify
2791   application.SendNotification();
2792   application.Render();
2793
2794   // Generate a Esc key event. The text field should lose the focus.
2795   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2796   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2797
2798   // Render and notify
2799   application.SendNotification();
2800   application.Render();
2801
2802   DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2803
2804   END_TEST;
2805 }
2806
2807 int UtcDaliTextFieldGetInputMethodContext(void)
2808 {
2809   ToolkitTestApplication application;
2810   tet_infoline("UtcDaliTextFieldGetInputMethodContext");
2811
2812   TextField field = TextField::New();
2813   DALI_TEST_CHECK( DevelTextField::GetInputMethodContext( field ) );
2814
2815   END_TEST;
2816 }
2817
2818 int UtcDaliTextFieldSelectWholeText(void)
2819 {
2820   ToolkitTestApplication application;
2821   tet_infoline(" UtcDaliTextFieldSelectWholeText ");
2822
2823   TextField textField = TextField::New();
2824
2825   Stage::GetCurrent().Add( textField );
2826
2827   textField.SetSize( 300.f, 50.f );
2828   textField.SetParentOrigin( ParentOrigin::TOP_LEFT );
2829   textField.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2830
2831   // Avoid a crash when core load gl resources.
2832   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2833
2834   application.SendNotification();
2835   application.Render();
2836
2837   DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION );
2838
2839   DevelTextField::SelectWholeText( textField );
2840
2841   application.SendNotification();
2842   application.Render();
2843
2844   // Nothing should have been selected. The number of children is still 1
2845   DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION );
2846
2847   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
2848
2849   application.SendNotification();
2850   application.Render();
2851
2852   DevelTextField::SelectWholeText( textField );
2853
2854   application.SendNotification();
2855   application.Render();
2856
2857   // Should be 2 children, the stencil and the layer
2858   DALI_TEST_EQUALS( 2u, textField.GetChildCount(), TEST_LOCATION );
2859
2860   // The offscreen root actor should have two actors: the renderer and the highlight actor.
2861   Actor stencil = textField.GetChildAt( 0u );
2862
2863   // The highlight actor is drawn first, so is the first actor in the list
2864   Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
2865   DALI_TEST_CHECK( highlight );
2866
2867   END_TEST;
2868 }