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