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