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