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