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