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