Add support to unselect text And Get_SelectedText
[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   field.SetProperty( DevelTextField::Property::BACKGROUND, Color::RED );
936   DALI_TEST_EQUALS( field.GetProperty<Vector4>( DevelTextField::Property::BACKGROUND ), Color::RED, TEST_LOCATION );
937
938   application.SendNotification();
939   application.Render();
940
941   END_TEST;
942 }
943
944 // Positive Atlas Text Renderer test
945 int utcDaliTextFieldAtlasRenderP(void)
946 {
947   ToolkitTestApplication application;
948   tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
949   StyleManager styleManager = StyleManager::Get();
950   styleManager.ApplyDefaultTheme();
951   TextField field = TextField::New();
952   DALI_TEST_CHECK( field );
953
954   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
955
956   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
957
958   Stage::GetCurrent().Add( field );
959
960   try
961   {
962     // Render some text with the shared atlas backend
963     field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
964     application.SendNotification();
965     application.Render();
966   }
967   catch( ... )
968   {
969     tet_result(TET_FAIL);
970   }
971   END_TEST;
972 }
973
974 // Positive test for the textChanged signal.
975 int utcDaliTextFieldTextChangedP(void)
976 {
977   ToolkitTestApplication application;
978   tet_infoline(" utcDaliTextFieldTextChangedP");
979   TextField field = TextField::New();
980   DALI_TEST_CHECK( field );
981
982   Stage::GetCurrent().Add( field );
983
984   // connect to the text changed signal.
985   ConnectionTracker* testTracker = new ConnectionTracker();
986   field.TextChangedSignal().Connect(&TestTextChangedCallback);
987   bool textChangedSignal = false;
988   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
989
990   gTextChangedCallBackCalled = false;
991   field.SetProperty( TextField::Property::TEXT, "ABC" );
992   DALI_TEST_CHECK( gTextChangedCallBackCalled );
993   DALI_TEST_CHECK( textChangedSignal );
994
995   application.SendNotification();
996
997   field.SetKeyInputFocus();
998
999   gTextChangedCallBackCalled = false;
1000   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1001   DALI_TEST_CHECK( gTextChangedCallBackCalled );
1002
1003   END_TEST;
1004 }
1005
1006 // Negative test for the textChanged signal.
1007 int utcDaliTextFieldTextChangedN(void)
1008 {
1009   ToolkitTestApplication application;
1010   tet_infoline(" utcDaliTextFieldTextChangedN");
1011   TextField field = TextField::New();
1012   DALI_TEST_CHECK( field );
1013
1014   Stage::GetCurrent().Add( field );
1015
1016   // connect to the text changed signal.
1017   ConnectionTracker* testTracker = new ConnectionTracker();
1018   field.TextChangedSignal().Connect(&TestTextChangedCallback);
1019   bool textChangedSignal = false;
1020   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
1021
1022   gTextChangedCallBackCalled = false;
1023   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
1024   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1025   DALI_TEST_CHECK( !textChangedSignal );
1026
1027   END_TEST;
1028 }
1029
1030 // Positive test for Max Characters reached signal.
1031 int utcDaliTextFieldMaxCharactersReachedP(void)
1032 {
1033   ToolkitTestApplication application;
1034   tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
1035   TextField field = TextField::New();
1036   DALI_TEST_CHECK( field );
1037
1038   Stage::GetCurrent().Add( field );
1039
1040   const int maxNumberOfCharacters = 1;
1041   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1042
1043   field.SetKeyInputFocus();
1044
1045   // connect to the text changed signal.
1046   ConnectionTracker* testTracker = new ConnectionTracker();
1047   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1048   bool maxLengthReachedSignal = false;
1049   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
1050
1051   gMaxCharactersCallBackCalled = false;
1052
1053   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1054   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1055
1056   DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
1057   DALI_TEST_CHECK( maxLengthReachedSignal );
1058
1059   END_TEST;
1060 }
1061
1062 // Negative test for Max Characters reached signal.
1063 int utcDaliTextFieldMaxCharactersReachedN(void)
1064 {
1065   ToolkitTestApplication application;
1066   tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
1067   TextField field = TextField::New();
1068   DALI_TEST_CHECK( field );
1069
1070   Stage::GetCurrent().Add( field );
1071
1072   const int maxNumberOfCharacters = 3;
1073   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1074
1075   field.SetKeyInputFocus();
1076
1077   // connect to the text changed signal.
1078   ConnectionTracker* testTracker = new ConnectionTracker();
1079   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1080   bool maxLengthReachedSignal = false;
1081   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
1082
1083   gMaxCharactersCallBackCalled = false;
1084
1085   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1086   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1087
1088   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1089   DALI_TEST_CHECK( !maxLengthReachedSignal );
1090
1091   application.ProcessEvent( GenerateKey( "Return", "", "\r", KEY_RETURN_CODE, 0, 0, Integration::KeyEvent::Down, "\r", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1092
1093   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1094   DALI_TEST_CHECK( !maxLengthReachedSignal );
1095
1096   END_TEST;
1097 }
1098
1099 int utcDaliTextFieldInputStyleChanged01(void)
1100 {
1101   // The text-field emits signals when the input style changes. These changes of style are
1102   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1103   // can't be emitted during the size negotiation as the callbacks may update the UI.
1104   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1105   // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks.
1106   ToolkitTestApplication application;
1107   tet_infoline(" utcDaliTextFieldInputStyleChanged01");
1108
1109   // Load some fonts.
1110
1111   char* pathNamePtr = get_current_dir_name();
1112   const std::string pathName( pathNamePtr );
1113   free( pathNamePtr );
1114
1115   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1116   fontClient.SetDpi( 93u, 93u );
1117
1118   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1119   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1120
1121   TextField field = TextField::New();
1122   DALI_TEST_CHECK( field );
1123
1124
1125   field.SetSize( 300.f, 50.f );
1126   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1127   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1128
1129   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1130   field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
1131
1132   // connect to the text changed signal.
1133   ConnectionTracker* testTracker = new ConnectionTracker();
1134   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1135   bool inputStyleChangedSignal = false;
1136   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1137
1138   Stage::GetCurrent().Add( field );
1139
1140   // Render and notify
1141   application.SendNotification();
1142   application.Render();
1143
1144   // Executes the idle callbacks added by the text control on the change of input style.
1145   application.RunIdles();
1146
1147   gInputStyleChangedCallbackCalled = false;
1148   gInputStyleMask = TextField::InputStyle::NONE;
1149   inputStyleChangedSignal = false;
1150
1151   // Create a tap event to touch the text field.
1152   TestGenerateTap( application, 18.0f, 25.0f );
1153
1154   // Render and notify
1155   application.SendNotification();
1156   application.Render();
1157
1158   // Executes the idle callbacks added by the text control on the change of input style.
1159   application.RunIdles();
1160
1161   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1162   if( gInputStyleChangedCallbackCalled )
1163   {
1164     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
1165
1166     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1167     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1168
1169     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1170     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1171   }
1172   DALI_TEST_CHECK( inputStyleChangedSignal );
1173
1174   gInputStyleChangedCallbackCalled = false;
1175   gInputStyleMask = TextField::InputStyle::NONE;
1176   inputStyleChangedSignal = false;
1177
1178   // Create a tap event to touch the text field.
1179   TestGenerateTap( application, 30.0f, 25.0f );
1180
1181   // Render and notify
1182   application.SendNotification();
1183   application.Render();
1184
1185   // Executes the idle callbacks added by the text control on the change of input style.
1186   application.RunIdles();
1187
1188   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1189   DALI_TEST_CHECK( !inputStyleChangedSignal );
1190
1191   gInputStyleChangedCallbackCalled = false;
1192   gInputStyleMask = TextField::InputStyle::NONE;
1193   inputStyleChangedSignal = false;
1194
1195   // Create a tap event to touch the text field.
1196   TestGenerateTap( application, 43.0f, 25.0f );
1197
1198   // Render and notify
1199   application.SendNotification();
1200   application.Render();
1201
1202   // Executes the idle callbacks added by the text control on the change of input style.
1203   application.RunIdles();
1204
1205   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1206   if( gInputStyleChangedCallbackCalled )
1207   {
1208     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1209
1210     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1211     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1212   }
1213   DALI_TEST_CHECK( inputStyleChangedSignal );
1214
1215   gInputStyleChangedCallbackCalled = false;
1216   gInputStyleMask = TextField::InputStyle::NONE;
1217   inputStyleChangedSignal = false;
1218
1219   // Create a tap event to touch the text field.
1220   TestGenerateTap( application, 88.0f, 25.0f );
1221
1222   // Render and notify
1223   application.SendNotification();
1224   application.Render();
1225
1226   // Executes the idle callbacks added by the text control on the change of input style.
1227   application.RunIdles();
1228
1229   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1230   if( gInputStyleChangedCallbackCalled )
1231   {
1232     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1233
1234     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1235     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1236
1237     const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1238
1239     Property::Map fontStyleMapSet;
1240     fontStyleMapSet.Insert( "weight", "bold" );
1241
1242     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1243     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1244   }
1245   DALI_TEST_CHECK( inputStyleChangedSignal );
1246
1247   gInputStyleChangedCallbackCalled = false;
1248   gInputStyleMask = TextField::InputStyle::NONE;
1249   inputStyleChangedSignal = false;
1250
1251   // Create a tap event to touch the text field.
1252   TestGenerateTap( application, 115.0f, 25.0f );
1253
1254   // Render and notify
1255   application.SendNotification();
1256   application.Render();
1257
1258   // Executes the idle callbacks added by the text control on the change of input style.
1259   application.RunIdles();
1260
1261   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1262   DALI_TEST_CHECK( !inputStyleChangedSignal );
1263
1264   gInputStyleChangedCallbackCalled = false;
1265   gInputStyleMask = TextField::InputStyle::NONE;
1266   inputStyleChangedSignal = false;
1267
1268   // Create a tap event to touch the text field.
1269   TestGenerateTap( application, 164.0f, 25.0f );
1270
1271   // Render and notify
1272   application.SendNotification();
1273   application.Render();
1274
1275   // Executes the idle callbacks added by the text control on the change of input style.
1276   application.RunIdles();
1277
1278   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1279   if( gInputStyleChangedCallbackCalled )
1280   {
1281     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1282
1283     const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1284     DALI_TEST_CHECK( style.empty() );
1285   }
1286   DALI_TEST_CHECK( inputStyleChangedSignal );
1287
1288   gInputStyleChangedCallbackCalled = false;
1289   gInputStyleMask = TextField::InputStyle::NONE;
1290   inputStyleChangedSignal = false;
1291
1292   // Create a tap event to touch the text field.
1293   TestGenerateTap( application, 191.0f, 25.0f );
1294
1295   // Render and notify
1296   application.SendNotification();
1297   application.Render();
1298
1299   // Executes the idle callbacks added by the text control on the change of input style.
1300   application.RunIdles();
1301
1302   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1303   DALI_TEST_CHECK( !inputStyleChangedSignal );
1304
1305   END_TEST;
1306 }
1307
1308 int utcDaliTextFieldInputStyleChanged02(void)
1309 {
1310   // The text-field emits signals when the input style changes. These changes of style are
1311   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1312   // can't be emitted during the size negotiation as the callbacks may update the UI.
1313   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1314   // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks.
1315   ToolkitTestApplication application;
1316   tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1317
1318   // Load some fonts.
1319
1320   char* pathNamePtr = get_current_dir_name();
1321   const std::string pathName( pathNamePtr );
1322   free( pathNamePtr );
1323
1324   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1325   fontClient.SetDpi( 93u, 93u );
1326
1327   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1328   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1329
1330   TextField field = TextField::New();
1331   DALI_TEST_CHECK( field );
1332
1333   field.SetSize( 300.f, 50.f );
1334   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1335   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1336
1337   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1338   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>" );
1339
1340   // connect to the text changed signal.
1341   ConnectionTracker* testTracker = new ConnectionTracker();
1342   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1343   bool inputStyleChangedSignal = false;
1344   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1345
1346   Stage::GetCurrent().Add( field );
1347
1348   // Render and notify
1349   application.SendNotification();
1350   application.Render();
1351
1352   // Executes the idle callbacks added by the text control on the change of input style.
1353   application.RunIdles();
1354
1355   gInputStyleChangedCallbackCalled = false;
1356   gInputStyleMask = TextField::InputStyle::NONE;
1357   inputStyleChangedSignal = false;
1358
1359   // Create a tap event to touch the text field.
1360   TestGenerateTap( application, 53.0f, 25.0f, 100 );
1361   TestGenerateTap( application, 53.0f, 25.0f, 200 );
1362
1363   // Render and notify
1364   application.SendNotification();
1365   application.Render();
1366
1367   // Executes the idle callbacks added by the text control on the change of input style.
1368   application.RunIdles();
1369
1370   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1371   if( gInputStyleChangedCallbackCalled )
1372   {
1373     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1374                       static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1375                                                  TextField::InputStyle::POINT_SIZE  |
1376                                                  TextField::InputStyle::COLOR ),
1377                       TEST_LOCATION );
1378
1379     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1380     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1381
1382     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1383     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1384
1385     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1386     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1387   }
1388   DALI_TEST_CHECK( inputStyleChangedSignal );
1389
1390   gInputStyleChangedCallbackCalled = false;
1391   gInputStyleMask = TextField::InputStyle::NONE;
1392   inputStyleChangedSignal = false;
1393
1394   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1395
1396   // Render and notify
1397   application.SendNotification();
1398   application.Render();
1399
1400   // Executes the idle callbacks added by the text control on the change of input style.
1401   application.RunIdles();
1402
1403   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1404   if( gInputStyleChangedCallbackCalled )
1405   {
1406     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1407                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1408                       TEST_LOCATION );
1409
1410     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1411     DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1412   }
1413   DALI_TEST_CHECK( inputStyleChangedSignal );
1414
1415   gInputStyleChangedCallbackCalled = false;
1416   gInputStyleMask = TextField::InputStyle::NONE;
1417   inputStyleChangedSignal = false;
1418
1419   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1420
1421   // Render and notify
1422   application.SendNotification();
1423   application.Render();
1424
1425   // Executes the idle callbacks added by the text control on the change of input style.
1426   application.RunIdles();
1427
1428   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1429   DALI_TEST_CHECK( !inputStyleChangedSignal );
1430
1431   gInputStyleChangedCallbackCalled = false;
1432   gInputStyleMask = TextField::InputStyle::NONE;
1433   inputStyleChangedSignal = false;
1434
1435   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1436
1437   // Render and notify
1438   application.SendNotification();
1439   application.Render();
1440
1441   // Executes the idle callbacks added by the text control on the change of input style.
1442   application.RunIdles();
1443
1444   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1445   if( gInputStyleChangedCallbackCalled )
1446   {
1447     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1448                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1449                       TEST_LOCATION );
1450
1451     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1452     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1453   }
1454   DALI_TEST_CHECK( inputStyleChangedSignal );
1455
1456   gInputStyleChangedCallbackCalled = false;
1457   gInputStyleMask = TextField::InputStyle::NONE;
1458   inputStyleChangedSignal = false;
1459
1460   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1461
1462   Property::Map fontStyleMapSet;
1463   fontStyleMapSet.Insert( "weight", "thin" );
1464   fontStyleMapSet.Insert( "width", "condensed" );
1465   fontStyleMapSet.Insert( "slant", "italic" );
1466
1467   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1468   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1469
1470   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1471   field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1472   field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1473   field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1474
1475   // Render and notify
1476   application.SendNotification();
1477   application.Render();
1478
1479   // Executes the idle callbacks added by the text control on the change of input style.
1480   application.RunIdles();
1481
1482   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1483   DALI_TEST_CHECK( !inputStyleChangedSignal );
1484
1485   // Create a tap event to touch the text field.
1486   TestGenerateTap( application, 63.0f, 25.0f, 300 );
1487
1488   // Render and notify
1489   application.SendNotification();
1490   application.Render();
1491
1492   // Executes the idle callbacks added by the text control on the change of input style.
1493   application.RunIdles();
1494
1495   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1496   if( gInputStyleChangedCallbackCalled )
1497   {
1498     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1499                       static_cast<unsigned int>( TextField::InputStyle::COLOR |
1500                                                  TextField::InputStyle::POINT_SIZE |
1501                                                  TextField::InputStyle::FONT_STYLE |
1502                                                  TextField::InputStyle::UNDERLINE |
1503                                                  TextField::InputStyle::SHADOW |
1504                                                  TextField::InputStyle::EMBOSS |
1505                                                  TextField::InputStyle::OUTLINE ),
1506                       TEST_LOCATION );
1507
1508     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1509     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1510   }
1511   DALI_TEST_CHECK( inputStyleChangedSignal );
1512
1513   END_TEST;
1514 }
1515
1516 int utcDaliTextFieldEvent01(void)
1517 {
1518   ToolkitTestApplication application;
1519   tet_infoline(" utcDaliTextFieldEvent01");
1520
1521   // Creates a tap event. After creating a tap event the text field should
1522   // have the focus and add text with key events should be possible.
1523
1524   TextField field = TextField::New();
1525   DALI_TEST_CHECK( field );
1526
1527   Stage::GetCurrent().Add( field );
1528
1529   field.SetSize( 300.f, 50.f );
1530   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1531   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1532
1533   // Render and notify
1534   application.SendNotification();
1535   application.Render();
1536
1537   // Avoid a crash when core load gl resources.
1538   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1539
1540   // Render and notify
1541   application.SendNotification();
1542   application.Render();
1543
1544   // Add a key event but as the text field has not the focus it should do nothing.
1545   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1546
1547   // Render and notify
1548   application.SendNotification();
1549   application.Render();
1550
1551   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1552
1553   // Create a tap event to touch the text field.
1554   TestGenerateTap( application, 150.0f, 25.0f );
1555
1556   // Render and notify
1557   application.SendNotification();
1558   application.Render();
1559
1560   // Pressing delete key should be fine even if there is no text in TextField.
1561   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 ) );
1562   // Render and notify
1563   application.SendNotification();
1564   application.Render();
1565
1566   // Now the text field has the focus, so it can handle the key events.
1567   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1568   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1569
1570   // Render and notify
1571   application.SendNotification();
1572   application.Render();
1573
1574   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1575
1576   // Create a second text field and send key events to it.
1577   TextField field2 = TextField::New();
1578
1579   field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1580   field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1581   field2.SetSize( 100.f, 100.0f );
1582   field2.SetPosition( 100.0f, 100.0f );
1583
1584   Stage::GetCurrent().Add( field2 );
1585
1586   // Render and notify
1587   application.SendNotification();
1588   application.Render();
1589
1590   // Create a tap event on the second text field.
1591   TestGenerateTap( application, 150.0f, 125.0f );
1592
1593   // Render and notify
1594   application.SendNotification();
1595   application.Render();
1596
1597   // The second text field has the focus. It should handle the key events.
1598   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1599   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1600
1601   // Render and notify
1602   application.SendNotification();
1603   application.Render();
1604
1605   // Check the text has been added to the second text field.
1606   DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1607
1608   END_TEST;
1609 }
1610
1611 int utcDaliTextFieldEvent02(void)
1612 {
1613   ToolkitTestApplication application;
1614   tet_infoline(" utcDaliTextFieldEvent02");
1615
1616   // Checks if the right number of actors are created.
1617
1618   TextField field = TextField::New();
1619   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1620   DALI_TEST_CHECK( field );
1621   LoadMarkerImages(application, field);
1622
1623   Stage::GetCurrent().Add( field );
1624
1625   field.SetSize( 300.0f, 50.0f );
1626   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1627   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1628
1629   // Avoid a crash when core load gl resources.
1630   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1631
1632   // Render and notify
1633   application.SendNotification();
1634   application.Render();
1635
1636   // Check there are the expected number of children ( stencil ).
1637   DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1638
1639   Actor stencil = field.GetChildAt( 0u );
1640   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1641
1642   // Create a tap event to touch the text field.
1643   TestGenerateTap( application, 150.0f, 25.0f, 300 );
1644
1645   // Render and notify
1646   application.SendNotification();
1647   application.Render();
1648
1649   Actor layer = field.GetChildAt( 1u );
1650   DALI_TEST_CHECK( layer.IsLayer() );
1651
1652   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1653   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1654
1655   // Now the text field has the focus, so it can handle the key events.
1656   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1657   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1658
1659   // Render and notify
1660   application.SendNotification();
1661   application.Render();
1662
1663   // Checks the cursor and the renderer have been created.
1664   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1665   DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1666
1667   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1668   DALI_TEST_CHECK( cursor );
1669
1670   // The offscreen root actor has a container with all the actors which contain the text renderers.
1671   Actor container = stencil.GetChildAt( 0u );
1672   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1673   {
1674     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1675     DALI_TEST_CHECK( renderer );
1676   }
1677
1678   // Move the cursor and check the position changes.
1679   Vector3 position1 = cursor.GetCurrentPosition();
1680   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1681
1682   // Render and notify
1683   application.SendNotification();
1684   application.Render();
1685
1686   Vector3 position2 = cursor.GetCurrentPosition();
1687   DALI_TEST_CHECK( position2.x < position1.x );
1688
1689   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1690
1691   // Render and notify
1692   application.SendNotification();
1693   application.Render();
1694
1695   Vector3 position3 = cursor.GetCurrentPosition();
1696   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1697
1698
1699   // Move the cursor to the first position.
1700   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1701   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1702
1703   // Render and notify
1704   application.SendNotification();
1705   application.Render();
1706
1707   Vector3 position4 = cursor.GetCurrentPosition();
1708
1709   // Send some taps and check the cursor positions.
1710
1711   // Try to tap at the beginning.
1712   TestGenerateTap( application, 1.0f, 25.0f, 900 );
1713
1714   // Render and notify
1715   application.SendNotification();
1716   application.Render();
1717
1718   // Cursor position should be the same than position1.
1719   Vector3 position5 = cursor.GetCurrentPosition();
1720
1721   DALI_TEST_EQUALS( position4, position5, TEST_LOCATION ); // Should be in the same position2.
1722
1723   // Tap away from the start position.
1724   TestGenerateTap( application, 16.0f, 25.0f, 1500 );
1725
1726   // Render and notify
1727   application.SendNotification();
1728   application.Render();
1729
1730   Vector3 position6 = cursor.GetCurrentPosition();
1731
1732   DALI_TEST_CHECK( position6.x > position5.x );
1733
1734   // Remove all the text.
1735   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1736   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1737   field.SetProperty( TextField::Property::TEXT, "" );
1738
1739   // Render and notify
1740   application.SendNotification();
1741   application.Render();
1742
1743   // Cursor position should be the same than position2.
1744   Vector3 position7 = cursor.GetCurrentPosition();
1745
1746   DALI_TEST_EQUALS( position4, position7, TEST_LOCATION );// Should be in the same position2.
1747
1748   // Should not be a renderer.
1749   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1750
1751   // Chanege exceed policy (EXCEED_POLICY_ORIGINAL doesn't use stencil )
1752   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1753   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
1754
1755   application.SendNotification();
1756   application.Render();
1757
1758   // There are renderer and decorator layer
1759   DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
1760
1761   END_TEST;
1762 }
1763
1764 int utcDaliTextFieldEvent03(void)
1765 {
1766   ToolkitTestApplication application;
1767   tet_infoline(" utcDaliTextFieldEvent03");
1768
1769   // Checks if the highlight actor is created.
1770
1771   TextField field = TextField::New();
1772   DALI_TEST_CHECK( field );
1773
1774   Stage::GetCurrent().Add( field );
1775
1776   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1777   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1778   field.SetSize( 30.f, 50.f );
1779   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1780   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1781
1782   // Avoid a crash when core load gl resources.
1783   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1784   LoadMarkerImages(application, field);
1785
1786   // Render and notify
1787   application.SendNotification();
1788   application.Render();
1789
1790   // Tap first to get the focus.
1791   TestGenerateTap( application, 3.0f, 25.0f );
1792
1793   // Render and notify
1794   application.SendNotification();
1795   application.Render();
1796
1797   // Double tap to select a word.
1798   TestGenerateTap( application, 3.0f, 25.0f );
1799
1800   // Render and notify
1801   application.SendNotification();
1802   application.Render();
1803
1804   // The offscreen root actor should have two actors: the renderer and the highlight actor.
1805   Actor stencil = field.GetChildAt( 0u );
1806
1807   // The highlight actor is drawn first, so is the first actor in the list
1808   Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
1809   DALI_TEST_CHECK( highlight );
1810
1811   // The offscreen root actor has a container with all the actors which contain the text renderers.
1812   Actor container = stencil.GetChildAt( 1u );
1813   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1814   {
1815     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1816     DALI_TEST_CHECK( renderer );
1817   }
1818
1819   END_TEST;
1820 }
1821
1822 int utcDaliTextFieldEvent04(void)
1823 {
1824   ToolkitTestApplication application;
1825   tet_infoline(" utcDaliTextFieldEvent04");
1826
1827   // Checks if the highlight actor is created.
1828
1829   TextField field = TextField::New();
1830   DALI_TEST_CHECK( field );
1831   Stage::GetCurrent().Add( field );
1832   LoadMarkerImages(application, field);
1833   // Render and notify
1834   application.SendNotification();
1835   application.Render();
1836
1837   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1838   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1839   field.SetSize( 300.f, 50.f );
1840   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1841   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1842
1843   // Avoid a crash when core load gl resources.
1844   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1845   // Render and notify
1846   application.SendNotification();
1847   application.Render();
1848
1849   // Create a tap event to touch the text field.
1850   TestGenerateTap( application, 150.0f, 25.0f );
1851   // Render and notify
1852   application.SendNotification();
1853   application.Render();
1854
1855
1856   // Tap first to get the focus.
1857   TestGenerateTap( application, 1.0f, 25.0f );
1858
1859   // Render and notify
1860   application.SendNotification();
1861   application.Render();
1862
1863   // Double tap to select a word.
1864   TestGenerateTap( application, 1.0f, 25.0f );
1865
1866   // Render and notify
1867   application.SendNotification();
1868   application.Render();
1869
1870   // Tap grab handle
1871   TestGenerateTap( application, 0.0f, 40.0f );
1872   END_TEST;
1873 }
1874
1875 int utcDaliTextFieldEvent05(void)
1876 {
1877   ToolkitTestApplication application;
1878   tet_infoline(" utcDaliTextFieldEvent05");
1879
1880   // Checks dragging of cursor/grab handle
1881
1882   TextField field = TextField::New();
1883   DALI_TEST_CHECK( field );
1884   Stage::GetCurrent().Add( field );
1885   LoadMarkerImages(application, field);
1886   // Render and notify
1887   application.SendNotification();
1888   application.Render();
1889
1890   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1891   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1892   field.SetSize( 300.f, 50.f );
1893   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1894   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1895
1896   // Avoid a crash when core load gl resources.
1897   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1898   // Render and notify
1899   application.SendNotification();
1900   application.Render();
1901
1902   // Create a tap event to touch the text field.
1903   TestGenerateTap( application, 150.0f, 25.0f );
1904   // Render and notify
1905   application.SendNotification();
1906   application.Render();
1907
1908   // Tap first to get the focus.
1909   TestGenerateTap( application, 1.0f, 25.0f );
1910
1911   // Render and notify
1912   application.SendNotification();
1913   application.Render();
1914
1915   // Double tap to select a word.
1916   TestGenerateTap( application, 1.0f, 25.0f );
1917
1918   // Render and notify
1919   application.SendNotification();
1920   application.Render();
1921
1922   Actor stencil = field.GetChildAt( 1u );
1923   END_TEST;
1924 }
1925
1926 int utcDaliTextFieldEvent06(void)
1927 {
1928   ToolkitTestApplication application;
1929   tet_infoline(" utcDaliTextFieldEvent06");
1930
1931   // Checks Longpress when in edit mode
1932
1933   TextField field = TextField::New();
1934   DALI_TEST_CHECK( field );
1935   Stage::GetCurrent().Add( field );
1936   LoadMarkerImages(application, field);
1937   // Render and notify
1938   application.SendNotification();
1939   application.Render();
1940
1941   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1942   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1943   field.SetSize( 300.f, 50.f );
1944   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1945   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1946
1947   // Avoid a crash when core load gl resources.
1948   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1949   // Render and notify
1950   application.SendNotification();
1951   application.Render();
1952
1953   // Create a tap event to touch the text field.
1954   TestGenerateTap( application, 150.0f, 25.0f );
1955   // Render and notify
1956   application.SendNotification();
1957   application.Render();
1958
1959
1960   // Tap first to get the focus.
1961   TestGenerateTap( application, 1.0f, 25.0f );
1962
1963   // Render and notify
1964   application.SendNotification();
1965   application.Render();
1966
1967   // Long Press
1968   TestGenerateLongPress(application, 1.0f, 25.0f);
1969
1970   // Render and notify
1971   application.SendNotification();
1972   application.Render();
1973
1974   END_TEST;
1975 }
1976
1977 int utcDaliTextFieldEvent07(void)
1978 {
1979   ToolkitTestApplication application;
1980   tet_infoline(" utcDaliTextFieldEvent07");
1981
1982   // Checks Longpress to start edit mode
1983
1984   TextField field = TextField::New();
1985   DALI_TEST_CHECK( field );
1986   Stage::GetCurrent().Add( field );
1987   LoadMarkerImages(application, field);
1988   // Render and notify
1989   application.SendNotification();
1990   application.Render();
1991
1992   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1993   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1994   field.SetSize( 300.f, 50.f );
1995   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1996   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1997   Property::Map propertyMap;
1998   propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD;
1999   field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
2000
2001   // Avoid a crash when core load gl resources.
2002   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2003   // Render and notify
2004   application.SendNotification();
2005   application.Render();
2006
2007   // Long Press
2008   TestGenerateLongPress(application, 1.0f, 25.0f);
2009
2010   // Render and notify
2011   application.SendNotification();
2012   application.Render();
2013
2014   END_TEST;
2015 }
2016
2017 int utcDaliTextFieldEvent08(void)
2018 {
2019   ToolkitTestApplication application;
2020   tet_infoline(" utcDaliTextFieldEvent08");
2021
2022   Dali::Clipboard clipboard = Clipboard::Get();
2023   clipboard.SetItem("testTextFieldEvent");
2024
2025   // Checks Longpress when only place holder text
2026
2027   TextField field = TextField::New();
2028   DALI_TEST_CHECK( field );
2029   Stage::GetCurrent().Add( field );
2030   LoadMarkerImages(application, field);
2031   // Render and notify
2032   application.SendNotification();
2033   application.Render();
2034
2035   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
2036   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2037   field.SetSize( 300.f, 50.f );
2038   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2039   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2040
2041   // Avoid a crash when core load gl resources.
2042   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2043   // Render and notify
2044   application.SendNotification();
2045   application.Render();
2046
2047   // Long Press
2048   TestGenerateLongPress( application, 1.0f, 25.0f, 20 );
2049
2050   // Render and notify
2051   application.SendNotification();
2052   application.Render();
2053
2054   Wait(application, 500);
2055
2056   TestEndLongPress( application, 1.0f, 25.0f, 520 );
2057
2058   // Long Press
2059   TestGenerateLongPress( application, 1.0f, 25.0f, 600 );
2060
2061   // Render and notify
2062   application.Render();
2063
2064   Wait(application, 500);
2065
2066   Stage stage = Stage::GetCurrent();
2067   Layer layer = stage.GetRootLayer();
2068   Actor actor = layer.FindChildByName("optionPaste");
2069
2070   if (actor)
2071   {
2072     Vector3 worldPosition = actor.GetCurrentWorldPosition();
2073     Vector2 halfStageSize = stage.GetSize() / 2.0f;
2074     Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
2075
2076     Dali::Integration::TouchEvent event;
2077     event = Dali::Integration::TouchEvent();
2078     event.AddPoint( GetPointDownInside( position ) );
2079     application.ProcessEvent( event );
2080
2081     event = Dali::Integration::TouchEvent();
2082     event.AddPoint( GetPointUpInside( position ) );
2083     application.ProcessEvent( event );
2084   }
2085   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
2086
2087   END_TEST;
2088 }
2089
2090 int utcDaliTextFieldEvent09(void)
2091 {
2092   ToolkitTestApplication application;
2093   tet_infoline(" utcDaliTextFieldEvent09");
2094
2095   TextField field = TextField::New();
2096   DALI_TEST_CHECK( field );
2097   Stage::GetCurrent().Add( field );
2098   LoadMarkerImages(application, field);
2099   // Render and notify
2100   application.SendNotification();
2101   application.Render();
2102
2103   field.SetProperty( TextField::Property::TEXT, "Hello" );
2104   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2105   field.SetSize( 300.f, 50.f );
2106   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2107   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2108
2109   // Avoid a crash when core load gl resources.
2110   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2111
2112   // Create a tap event to touch the text field.
2113   TestGenerateTap( application, 150.0f, 25.0f );
2114   application.SendNotification();
2115   application.Render();
2116
2117   Property::Map map;
2118   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE;
2119   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2120   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2121   application.SendNotification();
2122   application.Render();
2123
2124   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
2125   map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
2126   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2127   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2128   application.SendNotification();
2129   application.Render();
2130
2131   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_COUNT;
2132   map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2133   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2134   for( unsigned int index = 0u; index < 5u; ++index )
2135   {
2136     application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2137     application.SendNotification();
2138     application.Render();
2139   }
2140
2141   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT;
2142   map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2143   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2144   for( unsigned int index = 0u; index < 5u; ++index )
2145   {
2146     application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2147     application.SendNotification();
2148     application.Render();
2149   }
2150
2151   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER;
2152   map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 0;
2153   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2154   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2155   application.SendNotification();
2156   application.Render();
2157   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2158   application.SendNotification();
2159   application.Render();
2160
2161   map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 100;
2162   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2163   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2164   application.SendNotification();
2165   application.Render();
2166
2167   Property::Map mapGet;
2168   mapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
2169   DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION );
2170   DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION );
2171   END_TEST;
2172 }
2173
2174
2175 int utcDaliTextFieldStyleWhilstSelected(void)
2176 {
2177   ToolkitTestApplication application;
2178   tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
2179
2180   // Change font and styles whilst text is selected whilst word selected
2181
2182   TextField field = TextField::New();
2183   DALI_TEST_CHECK( field );
2184   Stage::GetCurrent().Add( field );
2185   LoadMarkerImages(application, field);
2186   // Render and notify
2187   application.SendNotification();
2188   application.Render();
2189
2190   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2191   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2192   field.SetSize( 300.f, 50.f );
2193   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2194   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2195
2196   // Avoid a crash when core load gl resources.
2197   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2198   // Render and notify
2199   application.SendNotification();
2200   application.Render();
2201
2202   // Create a tap event to touch the text field.
2203   TestGenerateTap( application, 150.0f, 25.0f );
2204   // Render and notify
2205   application.SendNotification();
2206   application.Render();
2207
2208
2209   // Tap first to get the focus.
2210   TestGenerateTap( application, 1.0f, 25.0f );
2211
2212   // Render and notify
2213   application.SendNotification();
2214   application.Render();
2215
2216   // Double tap to select a word.
2217   TestGenerateTap( application, 1.0f, 25.0f );
2218
2219   // Render and notify
2220   application.SendNotification();
2221   application.Render();
2222
2223   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
2224   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
2225
2226   Property::Map fontStyleMapSet;
2227   Property::Map fontStyleMapGet;
2228
2229   fontStyleMapSet.Insert( "weight", "bold" );
2230   fontStyleMapSet.Insert( "slant", "italic" );
2231   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2232
2233   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2234   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2235   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2236
2237   fontStyleMapSet.Clear();
2238   fontStyleMapSet.Insert( "width", "expanded" );
2239   fontStyleMapSet.Insert( "slant", "italic" );
2240   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2241
2242   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2243   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2244   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2245
2246   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2247   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2248
2249   field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2250   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2251
2252   fontStyleMapSet.Clear();
2253   fontStyleMapSet.Insert( "weight", "bold" );
2254   fontStyleMapSet.Insert( "slant", "italic" );
2255
2256   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2257
2258   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2259   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2260   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2261
2262   fontStyleMapSet.Clear();
2263   fontStyleMapSet.Insert( "width", "expanded" );
2264
2265   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2266
2267   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2268   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2269   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2270
2271   // Press Escape to increase coverage
2272   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2273   application.SendNotification();
2274   application.Render();
2275
2276   DALI_TEST_CHECK( !field.HasKeyInputFocus() );
2277
2278   END_TEST;
2279 }
2280
2281 int utcDaliTextFieldEscKeyLoseFocus(void)
2282 {
2283   ToolkitTestApplication application;
2284   tet_infoline(" utcDaliTextFieldEscKeyLoseFocus");
2285
2286   // Creates a tap event. After creating a tap event the text field should
2287   // have the focus and add text with key events should be possible.
2288
2289   TextField field = TextField::New();
2290   DALI_TEST_CHECK( field );
2291
2292   Stage::GetCurrent().Add( field );
2293
2294   field.SetSize( 300.f, 50.f );
2295   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2296   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2297
2298   // Avoid a crash when core load gl resources.
2299   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2300
2301   // Render and notify
2302   application.SendNotification();
2303   application.Render();
2304
2305   // Add a key event but as the text field has not the focus it should do nothing.
2306   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2307   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2308
2309   // Render and notify
2310   application.SendNotification();
2311   application.Render();
2312
2313   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2314
2315   // Create a tap event to touch the text field.
2316   TestGenerateTap( application, 150.0f, 25.0f );
2317
2318   // Render and notify
2319   application.SendNotification();
2320   application.Render();
2321
2322   // Now the text field has the focus, so it can handle the key events.
2323   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2324   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2325   application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2326   application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::Up, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2327
2328   // Render and notify
2329   application.SendNotification();
2330   application.Render();
2331
2332   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2333
2334   // Generate a Esc key event. The text field should lose the focus.
2335   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2336   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2337
2338   // Render and notify
2339   application.SendNotification();
2340   application.Render();
2341
2342   DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2343
2344   // No more text should be introduced
2345   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2346   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2347
2348   // Render and notify
2349   application.SendNotification();
2350   application.Render();
2351
2352   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2353
2354   END_TEST;
2355 }
2356
2357 int utcDaliTextFieldSomeSpecialKeys(void)
2358 {
2359   ToolkitTestApplication application;
2360   tet_infoline(" utcDaliTextFieldSomeSpecialKeys");
2361
2362   // Checks some special keys when the text is selected.
2363
2364   TextField field = TextField::New();
2365   DALI_TEST_CHECK( field );
2366   Stage::GetCurrent().Add( field );
2367   LoadMarkerImages(application, field);
2368   // Render and notify
2369   application.SendNotification();
2370   application.Render();
2371
2372   const std::string longText( "This is a long text for the size of the text-field." );
2373
2374   field.SetProperty( TextField::Property::TEXT, longText );
2375   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2376   field.SetSize( 300.f, 50.f );
2377   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2378   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2379
2380   // Avoid a crash when core load gl resources.
2381   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2382   // Render and notify
2383   application.SendNotification();
2384   application.Render();
2385
2386   // Create a tap event to touch the text field.
2387   TestGenerateTap( application, 150.0f, 25.0f );
2388
2389   // Render and notify
2390   application.SendNotification();
2391   application.Render();
2392
2393   // Tap first to get the focus.
2394   TestGenerateTap( application, 1.0f, 25.0f );
2395
2396   // Render and notify
2397   application.SendNotification();
2398   application.Render();
2399
2400   // Double tap to select a word.
2401   TestGenerateTap( application, 1.0f, 25.0f );
2402
2403   // Render and notify
2404   application.SendNotification();
2405   application.Render();
2406
2407   // Generate a Esc key event. The text field should lose the focus.
2408   application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Down, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2409   application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::Up, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
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( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Down, "XF86Menu", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2417   application.ProcessEvent( GenerateKey( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::Up, "XF86Menu", 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( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Down, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2425   application.ProcessEvent( GenerateKey( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::Up, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2426
2427   // Render and notify
2428   application.SendNotification();
2429   application.Render();
2430
2431   // The text shouldn't be deleted.
2432   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), longText, TEST_LOCATION );
2433
2434   END_TEST;
2435 }
2436
2437 int utcDaliTextFieldSizeUpdate(void)
2438 {
2439   ToolkitTestApplication application;
2440   tet_infoline("utcDaliTextFieldSizeUpdate");
2441
2442   // Checks some special keys when the text is selected.
2443   TextField field = TextField::New();
2444   DALI_TEST_CHECK( field );
2445   Stage::GetCurrent().Add( field );
2446
2447   float previousHeight = 0.0f;
2448   float currentHeight = 0.0f;
2449   const float fieldWidth = 1920.0f;
2450
2451
2452   // "ㅁ" is bigger then "ኢ"
2453   field.SetSize( Vector2( fieldWidth ,10.0f ) );
2454   field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH );
2455   field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT );
2456
2457   field.SetProperty( TextField::Property::TEXT, "ኢ");
2458   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2459   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2460
2461   field.SetKeyboardFocusable(true);
2462   KeyboardFocusManager::Get().SetCurrentFocusActor( field );
2463
2464   application.SendNotification();
2465   application.Render();
2466
2467   previousHeight = field.GetHeightForWidth( fieldWidth );
2468   DALI_TEST_EQUALS( previousHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION );
2469
2470   // Add  another script characters ( glyph height is defferent )
2471   application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2472   application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::Up, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2473
2474   application.SendNotification();
2475   application.Render();
2476
2477   currentHeight = field.GetHeightForWidth( fieldWidth );
2478   DALI_TEST_EQUALS( currentHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ), TEST_LOCATION );
2479   DALI_TEST_EQUALS( (previousHeight < currentHeight), true , TEST_LOCATION );
2480
2481   END_TEST;
2482 }
2483
2484 int utcDaliTextFieldExtremlyLargePointSize(void)
2485 {
2486   ToolkitTestApplication application;
2487   tet_infoline(" utcDaliTextFieldExtremlyLargePointSize");
2488
2489   TextField field = TextField::New();
2490
2491   field.SetProperty( TextField::Property::TEXT, "Text" );
2492   field.SetSize( 300.f, 50.f );
2493   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2494   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2495   Stage::GetCurrent().Add( field );
2496
2497   try
2498   {
2499     field.SetProperty( TextField::Property::POINT_SIZE, 160.0f );
2500     application.SendNotification();
2501     DALI_TEST_CHECK( field );
2502   }
2503   catch (...)
2504   {
2505     tet_result(TET_FAIL);
2506   }
2507   END_TEST;
2508 }
2509
2510 int UtcDaliTextFieldDefaultFontStylePropertyCoverage(void)
2511 {
2512   ToolkitTestApplication application;
2513   tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage");
2514   TextField field = TextField::New();
2515   DALI_TEST_CHECK( field );
2516   Stage::GetCurrent().Add( field );
2517
2518   Property::Map fontStyleMapGet;
2519
2520   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2521
2522   Property::Value* weightValue = NULL;
2523   Property::Value* widthValue = NULL;
2524   Property::Value* slantValue = NULL;
2525   weightValue = fontStyleMapGet.Find( "weight" );
2526   widthValue = fontStyleMapGet.Find( "width" );
2527   slantValue = fontStyleMapGet.Find( "slant" );
2528   DALI_TEST_CHECK( !weightValue );
2529   DALI_TEST_CHECK( !widthValue );
2530   DALI_TEST_CHECK( !slantValue );
2531
2532   END_TEST;
2533 }
2534
2535 int UtcDaliTextFieldSettingPlaceholder(void)
2536 {
2537   ToolkitTestApplication application;
2538   tet_infoline("UtcDaliTextFieldSettingPlaceholder");
2539
2540   TextField field = TextField::New();
2541   DALI_TEST_CHECK( field );
2542   Stage::GetCurrent().Add( field );
2543
2544   // Check the placeholder property with pixel size
2545   Property::Map placeholderPixelSizeMapSet;
2546   Property::Map placeholderPixelSizeMapGet;
2547   Property::Map placeholderFontstyleMap;
2548   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2549   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2550   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::BLUE;
2551   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2552   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::PIXEL_SIZE ] = 15.0f;
2553   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
2554
2555   placeholderFontstyleMap.Insert( "weight", "bold" );
2556   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2557   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
2558
2559   placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2560   DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
2561   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION );
2562
2563   // Check the placeholder property with point size
2564   Property::Map placeholderMapSet;
2565   Property::Map placeholderMapGet;
2566   placeholderMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
2567   placeholderMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
2568   placeholderMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::RED;
2569   placeholderMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
2570   placeholderMapSet[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
2571   placeholderMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = false;
2572
2573   // Check the placeholder font style property
2574   placeholderFontstyleMap.Clear();
2575
2576   placeholderFontstyleMap.Insert( "weight", "bold" );
2577   placeholderFontstyleMap.Insert( "width", "condensed" );
2578   placeholderFontstyleMap.Insert( "slant", "italic" );
2579   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2580   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2581
2582   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2583   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2584   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2585
2586   // Reset font style.
2587   placeholderFontstyleMap.Clear();
2588   placeholderFontstyleMap.Insert( "weight", "normal" );
2589   placeholderFontstyleMap.Insert( "slant", "oblique" );
2590   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2591   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2592
2593   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2594   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2595   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2596
2597   placeholderFontstyleMap.Clear();
2598   placeholderFontstyleMap.Insert( "slant", "roman" );
2599   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2600   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2601
2602   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2603
2604   placeholderFontstyleMap.Clear();
2605   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
2606
2607   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
2608   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
2609   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
2610   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
2611
2612   END_TEST;
2613 }
2614
2615 int UtcDaliTextFieldSetPaddingProperty(void)
2616 {
2617   ToolkitTestApplication application;
2618   tet_infoline("UtcDaliTextFieldSetPaddingProperty\n");
2619
2620   TextField field = TextField::New();
2621   DALI_TEST_CHECK( field );
2622   field.SetSize( 300.f, 50.f );
2623   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2624   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2625   Stage::GetCurrent().Add( field );
2626
2627   application.SendNotification();
2628   application.Render();
2629
2630   Vector3 originalSize = field.GetNaturalSize();
2631
2632   field.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
2633
2634   application.SendNotification();
2635   application.Render();
2636
2637   DALI_TEST_EQUALS( field.GetProperty<Extents>( Toolkit::Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
2638
2639   Vector3 paddingAddedSize = field.GetNaturalSize();
2640
2641   DALI_TEST_EQUALS( originalSize.width + 10 + 10 , paddingAddedSize.width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2642
2643   DALI_TEST_EQUALS( originalSize.height + 10 + 10 , paddingAddedSize.height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2644
2645   END_TEST;
2646 }
2647
2648 int UtcDaliTextFieldEnableShiftSelectionProperty(void)
2649 {
2650   ToolkitTestApplication application;
2651   tet_infoline("UtcDaliTextFieldEnableShiftSelectionProperty");
2652
2653   TextField field = TextField::New();
2654   DALI_TEST_CHECK( field );
2655   field.SetSize( 300.0f, 50.0f );
2656   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2657   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2658   Stage::GetCurrent().Add( field );
2659
2660   application.SendNotification();
2661   application.Render();
2662
2663   // The default value of ENABLE_SHIFT_SELECTION is 'true'.
2664   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), true, TEST_LOCATION );
2665
2666   // Check the enable shift selection property
2667   field.SetProperty( DevelTextField::Property::ENABLE_SHIFT_SELECTION, false );
2668   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), false, TEST_LOCATION );
2669
2670   application.SendNotification();
2671   application.Render();
2672
2673   END_TEST;
2674 }
2675
2676 int UtcDaliTextFieldEnableGrabHandleProperty(void)
2677 {
2678   ToolkitTestApplication application;
2679   tet_infoline("UtcDaliTextFieldEnableGrabHandleProperty");
2680
2681   TextField field = TextField::New();
2682   DALI_TEST_CHECK( field );
2683   field.SetSize( 300.0f, 50.0f );
2684   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2685   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2686   Stage::GetCurrent().Add( field );
2687
2688   application.SendNotification();
2689   application.Render();
2690
2691   // The default value of ENABLE_GRAB_HANDLE is 'true'.
2692   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE ), true, TEST_LOCATION );
2693
2694   // Check the enable grab handle property
2695   field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE, false );
2696   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE ), false, TEST_LOCATION );
2697
2698   application.SendNotification();
2699   application.Render();
2700
2701   END_TEST;
2702 }
2703
2704 int UtcDaliTextFieldMatchSystemLanguageDirectionProperty(void)
2705 {
2706   ToolkitTestApplication application;
2707   tet_infoline("UtcDaliTextFieldMatchSystemLanguageDirectionProperty");
2708
2709   TextField field = TextField::New();
2710   DALI_TEST_CHECK( field );
2711   field.SetSize( 300.0f, 50.0f );
2712   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2713   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2714   Stage::GetCurrent().Add( field );
2715
2716   application.SendNotification();
2717   application.Render();
2718
2719   // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'false'.
2720   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION );
2721
2722   // Check the match system language direction property
2723   field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true );
2724   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), true, TEST_LOCATION );
2725
2726   application.SendNotification();
2727   application.Render();
2728
2729   END_TEST;
2730 }
2731
2732 int utcDaliTextFieldLayoutDirectionCoverage(void)
2733 {
2734   ToolkitTestApplication application;
2735   tet_infoline(" utcDaliTextFieldLayoutDirectionCoverage");
2736
2737   // Creates a tap event. After creating a tap event the text field should
2738   // have the focus and add text with key events should be possible.
2739   TextField field = TextField::New();
2740   DALI_TEST_CHECK( field );
2741
2742   Stage::GetCurrent().Add( field );
2743
2744   field.SetSize( 300.0f, 50.0f );
2745   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
2746   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2747
2748   // Avoid a crash when core load gl resources.
2749   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2750
2751   // Render and notify
2752   application.SendNotification();
2753   application.Render();
2754
2755   // init direction for coverage
2756   // Set horizontal alignment END
2757   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END");
2758
2759   // Create a tap event to touch the text field.
2760   TestGenerateTap( application, 150.0f, 25.0f );
2761
2762   // Render and notify
2763   application.SendNotification();
2764   application.Render();
2765
2766   // Set MATCH_SYSTEM_LANGUAGE_DIRECTION to true to use the layout direction.
2767   field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true );
2768   field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
2769
2770   // Set horizontal alignment BEGIN
2771   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "BEGIN");
2772
2773   // Create a tap event to touch the text field.
2774   TestGenerateTap( application, 150.0f, 25.0f );
2775
2776   // Render and notify
2777   application.SendNotification();
2778   application.Render();
2779
2780   // Set horizontal alignment CENTER
2781   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER");
2782
2783   // Create a tap event to touch the text field.
2784   TestGenerateTap( application, 150.0f, 25.0f );
2785
2786   // Render and notify
2787   application.SendNotification();
2788   application.Render();
2789
2790   // Set horizontal alignment END
2791   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END");
2792
2793   // Create a tap event to touch the text field.
2794   TestGenerateTap( application, 150.0f, 25.0f );
2795
2796   // Render and notify
2797   application.SendNotification();
2798   application.Render();
2799
2800   // Generate a Esc key event. The text field should lose the focus.
2801   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Down, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2802   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::Up, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2803
2804   // Render and notify
2805   application.SendNotification();
2806   application.Render();
2807
2808   DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2809
2810   END_TEST;
2811 }
2812
2813 int UtcDaliTextFieldGetInputMethodContext(void)
2814 {
2815   ToolkitTestApplication application;
2816   tet_infoline("UtcDaliTextFieldGetInputMethodContext");
2817
2818   TextField field = TextField::New();
2819   DALI_TEST_CHECK( DevelTextField::GetInputMethodContext( field ) );
2820
2821   END_TEST;
2822 }
2823
2824 int UtcDaliTextFieldSelectWholeText(void)
2825 {
2826   ToolkitTestApplication application;
2827   tet_infoline(" UtcDaliTextFieldSelectWholeText ");
2828
2829   TextField textField = TextField::New();
2830
2831   Stage::GetCurrent().Add( textField );
2832
2833   textField.SetSize( 300.f, 50.f );
2834   textField.SetParentOrigin( ParentOrigin::TOP_LEFT );
2835   textField.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2836
2837   // Avoid a crash when core load gl resources.
2838   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2839
2840   application.SendNotification();
2841   application.Render();
2842
2843   DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION );
2844
2845   DevelTextField::SelectWholeText( textField );
2846
2847   application.SendNotification();
2848   application.Render();
2849
2850   // Nothing should have been selected. The number of children is still 1
2851   DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION );
2852
2853   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
2854
2855   application.SendNotification();
2856   application.Render();
2857
2858   DevelTextField::SelectWholeText( textField );
2859
2860   application.SendNotification();
2861   application.Render();
2862
2863   // Should be 2 children, the stencil and the layer
2864   DALI_TEST_EQUALS( 2u, textField.GetChildCount(), TEST_LOCATION );
2865
2866   // The offscreen root actor should have two actors: the renderer and the highlight actor.
2867   Actor stencil = textField.GetChildAt( 0u );
2868
2869   // The highlight actor is drawn first, so is the first actor in the list
2870   Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
2871   DALI_TEST_CHECK( highlight );
2872
2873   END_TEST;
2874 }
2875
2876 int UtcDaliTextFieldSelectNone(void)
2877 {
2878   ToolkitTestApplication application;
2879   tet_infoline(" UtcDaliTextFieldSelectWholeText ");
2880
2881   TextField textField = TextField::New();
2882
2883   Stage::GetCurrent().Add( textField );
2884
2885   textField.SetSize( 300.f, 50.f );
2886   textField.SetParentOrigin( ParentOrigin::TOP_LEFT );
2887   textField.SetAnchorPoint( AnchorPoint::TOP_LEFT );
2888
2889   // Avoid a crash when core load gl resources.
2890   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2891
2892   application.SendNotification();
2893   application.Render();
2894
2895   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
2896
2897   application.SendNotification();
2898   application.Render();
2899
2900   // Nothing is selected
2901   std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
2902   DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
2903
2904   DevelTextField::SelectWholeText( textField );
2905
2906   application.SendNotification();
2907   application.Render();
2908
2909   // whole text is selected
2910   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
2911   DALI_TEST_EQUALS( "Hello world", selectedText, TEST_LOCATION );
2912
2913   DevelTextField::SelectNone( textField );
2914
2915   application.SendNotification();
2916   application.Render();
2917
2918   // Nothing is selected
2919   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
2920   DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
2921
2922   END_TEST;
2923 }