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