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