Merge "DALi Version 2.1.4" into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextField.cpp
1 /*
2  * Copyright (c) 2021 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 #include <dali-toolkit/devel-api/text/text-enumerations-devel.h>
34 #include "test-text-geometry-utils.h"
35
36 using namespace Dali;
37 using namespace Toolkit;
38
39 void dali_textfield_startup(void)
40 {
41   test_return_value = TET_UNDEF;
42 }
43
44 void dali_textfield_cleanup(void)
45 {
46   test_return_value = TET_PASS;
47 }
48
49 namespace
50 {
51
52 const char* const PROPERTY_NAME_RENDERING_BACKEND                    = "renderingBackend";
53 const char* const PROPERTY_NAME_TEXT                                 = "text";
54 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT                     = "placeholderText";
55 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED             = "placeholderTextFocused";
56 const char* const PROPERTY_NAME_FONT_FAMILY                          = "fontFamily";
57 const char* const PROPERTY_NAME_FONT_STYLE                           = "fontStyle";
58 const char* const PROPERTY_NAME_POINT_SIZE                           = "pointSize";
59 const char* const PROPERTY_NAME_MAX_LENGTH                           = "maxLength";
60 const char* const PROPERTY_NAME_EXCEED_POLICY                        = "exceedPolicy";
61 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT                 = "horizontalAlignment";
62 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT                   = "verticalAlignment";
63 const char* const PROPERTY_NAME_TEXT_COLOR                           = "textColor";
64 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR               = "placeholderTextColor";
65 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR                 = "primaryCursorColor";
66 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR               = "secondaryCursorColor";
67 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK                  = "enableCursorBlink";
68 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL                = "cursorBlinkInterval";
69 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION                = "cursorBlinkDuration";
70 const char* const PROPERTY_NAME_CURSOR_WIDTH                         = "cursorWidth";
71 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHandleImage";
72 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
73 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
74 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
78 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
79 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT   = "selectionHandleMarkerImageLeft";
80 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = "selectionHandleMarkerImageRight";
81 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR            = "selectionHighlightColor";
82 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX              = "decorationBoundingBox";
83 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS                = "inputMethodSettings";
84 const char* const PROPERTY_NAME_INPUT_COLOR                          = "inputColor";
85 const char* const PROPERTY_NAME_ENABLE_MARKUP                        = "enableMarkup";
86 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY                    = "inputFontFamily";
87 const char* const PROPERTY_NAME_INPUT_FONT_STYLE                     = "inputFontStyle";
88 const char* const PROPERTY_NAME_INPUT_POINT_SIZE                     = "inputPointSize";
89
90 const char* const PROPERTY_NAME_UNDERLINE                            = "underline";
91 const char* const PROPERTY_NAME_INPUT_UNDERLINE                      = "inputUnderline";
92 const char* const PROPERTY_NAME_SHADOW                               = "shadow";
93 const char* const PROPERTY_NAME_INPUT_SHADOW                         = "inputShadow";
94 const char* const PROPERTY_NAME_EMBOSS                               = "emboss";
95 const char* const PROPERTY_NAME_INPUT_EMBOSS                         = "inputEmboss";
96 const char* const PROPERTY_NAME_OUTLINE                              = "outline";
97 const char* const PROPERTY_NAME_INPUT_OUTLINE                        = "inputOutline";
98
99 const char* const PROPERTY_NAME_HIDDEN_INPUT_SETTINGS                = "hiddenInputSettings";
100 const char* const PROPERTY_NAME_PIXEL_SIZE                           = "pixelSize";
101 const char* const PROPERTY_NAME_ENABLE_SELECTION                     = "enableSelection";
102 const char* const PROPERTY_NAME_PLACEHOLDER                          = "placeholder";
103 const char* const PROPERTY_NAME_ELLIPSIS                             = "ellipsis";
104 const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION               = "enableShiftSelection";
105 const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE                   = "enableGrabHandle";
106 const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION      = "matchSystemLanguageDirection";
107 const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP             = "enableGrabHandlePopup";
108 const char* const PROPERTY_NAME_BACKGROUND                           = "textBackground";
109 const char* const PROPERTY_NAME_FONT_SIZE_SCALE                      = "fontSizeScale";
110 const char* const PROPERTY_NAME_ENABLE_FONT_SIZE_SCALE               = "enableFontSizeScale";
111 const char* const PROPERTY_NAME_GRAB_HANDLE_COLOR                    = "grabHandleColor";
112 const char* const PROPERTY_NAME_INPUT_FILTER                         = "inputFilter";
113
114 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
115 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
116
117 const float RENDER_FRAME_INTERVAL = 16.66f;
118
119 const unsigned int DEFAULT_FONT_SIZE = 1152u;
120 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
121
122 const int KEY_RETURN_CODE = 36;
123 const int KEY_A_CODE = 38;
124 const int KEY_D_CODE = 40;
125 const int KEY_SHIFT_MODIFIER = 257;
126
127 const std::string DEFAULT_DEVICE_NAME("hwKeyboard");
128
129 static bool gSelectionChangedCallbackCalled;
130 static uint32_t oldSelectionStart;
131 static uint32_t oldSelectionEnd;
132 static bool gSelectionClearedCallbackCalled;
133 static bool gAnchorClickedCallBackCalled;
134 static bool gAnchorClickedCallBackNotCalled;
135 static bool gTextChangedCallBackCalled;
136 static bool gMaxCharactersCallBackCalled;
137 static bool gInputFilteredAcceptedCallbackCalled;
138 static bool gInputFilteredRejectedCallbackCalled;
139 static bool gInputStyleChangedCallbackCalled;
140 static bool gCursorPositionChangedCallbackCalled;
141 static uint32_t oldCursorPos;
142 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
143
144 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
145 {
146   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
147   Integration::ResourcePointer resource(bitmap);
148   bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
149 }
150
151 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
152 {
153   int width(40);
154   int height(40);
155   LoadBitmapResource( app.GetPlatform(), width, height );
156
157   Property::Map propertyMap;
158   propertyMap["filename"] = "image.png";
159   propertyMap["width"] = width;
160   propertyMap["height"] = height;
161   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
162   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
163   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
164   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
165   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
166   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
167   textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
168   textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
169 }
170
171 /*
172  * Simulate time passed by.
173  *
174  * @note this will always process at least 1 frame (1/60 sec)
175  *
176  * @param application Test application instance
177  * @param duration Time to pass in milliseconds.
178  * @return The actual time passed in milliseconds
179  */
180 static int Wait(ToolkitTestApplication& application, int duration = 0)
181 {
182   int time = 0;
183
184   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
185   {
186     application.SendNotification();
187     application.Render(RENDER_FRAME_INTERVAL);
188     time += RENDER_FRAME_INTERVAL;
189   }
190
191   return time;
192 }
193
194 Dali::Integration::Point GetPointDownInside( Vector2& pos )
195 {
196   Dali::Integration::Point point;
197   point.SetState( PointState::DOWN );
198   point.SetScreenPosition( pos );
199   return point;
200 }
201
202 Dali::Integration::Point GetPointUpInside( Vector2& pos )
203 {
204   Dali::Integration::Point point;
205   point.SetState( PointState::UP );
206   point.SetScreenPosition( pos );
207   return point;
208 }
209
210 struct CallbackFunctor
211 {
212   CallbackFunctor(bool* callbackFlag)
213   : mCallbackFlag( callbackFlag )
214   {
215   }
216
217   void operator()()
218   {
219     *mCallbackFlag = true;
220   }
221   bool* mCallbackFlag;
222 };
223
224 static void TestSelectionClearedCallback(TextField control)
225 {
226   tet_infoline(" TestSelectionClearedCallback");
227
228   gSelectionClearedCallbackCalled = true;
229 }
230
231 static void TestSelectionChangedCallback(TextField control, uint32_t oldStart, uint32_t oldEnd)
232 {
233   tet_infoline(" TestSelectionChangedCallback");
234
235   gSelectionChangedCallbackCalled = true;
236   oldSelectionStart = oldStart;
237   oldSelectionEnd   = oldEnd;
238 }
239
240 static void TestAnchorClickedCallback(TextField control, const char* href, unsigned int hrefLength)
241 {
242   tet_infoline(" TestAnchorClickedCallback");
243
244   gAnchorClickedCallBackNotCalled = false;
245
246   if (!strcmp(href, "https://www.tizen.org") && hrefLength == strlen(href))
247   {
248     gAnchorClickedCallBackCalled = true;
249   }
250 }
251
252 static void TestCursorPositionChangedCallback( TextField control, unsigned int oldPos )
253 {
254   tet_infoline(" TestCursorPositionChangedCallback");
255
256   gCursorPositionChangedCallbackCalled = true;
257   oldCursorPos = oldPos;
258 }
259
260 static void TestTextChangedCallback( TextField control )
261 {
262   tet_infoline(" TestTextChangedCallback");
263
264   gTextChangedCallBackCalled = true;
265 }
266
267 static void TestMaxLengthReachedCallback( TextField control )
268 {
269   tet_infoline(" TestMaxLengthReachedCallback");
270
271   gMaxCharactersCallBackCalled = true;
272 }
273
274 static void TestInputFilteredCallback(TextField control, Toolkit::InputFilter::Property::Type type)
275 {
276   tet_infoline(" TestInputFilteredCallback");
277
278   if(type == Toolkit::InputFilter::Property::ACCEPTED)
279   {
280     gInputFilteredAcceptedCallbackCalled = true;
281   }
282   else if(type == Toolkit::InputFilter::Property::REJECTED)
283   {
284     gInputFilteredRejectedCallbackCalled = true;
285   }
286 }
287
288 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
289 {
290   tet_infoline(" TestInputStyleChangedCallback");
291
292   gInputStyleChangedCallbackCalled = true;
293   gInputStyleMask = mask;
294 }
295
296 // Generate a KeyEvent to send to Core.
297 Integration::KeyEvent GenerateKey( const std::string& keyName,
298                                    const std::string& logicalKey,
299                                    const std::string& keyString,
300                                    int keyCode,
301                                    int keyModifier,
302                                    unsigned long timeStamp,
303                                    const Integration::KeyEvent::State& keyState,
304                                    const std::string& compose = "",
305                                    const std::string& deviceName = DEFAULT_DEVICE_NAME,
306                                    const Device::Class::Type& deviceClass = Device::Class::NONE,
307                                    const Device::Subclass::Type& deviceSubclass = Device::Subclass::NONE )
308 {
309   return Integration::KeyEvent( keyName,
310                                 logicalKey,
311                                 keyString,
312                                 keyCode,
313                                 keyModifier,
314                                 timeStamp,
315                                 keyState,
316                                 compose,
317                                 deviceName,
318                                 deviceClass,
319                                 deviceSubclass );
320 }
321
322 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
323 {
324   if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
325   {
326     for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
327     {
328       const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
329
330       Property::Value* valueSet = NULL;
331       if ( valueGet.first.type == Property::Key::INDEX )
332       {
333         valueSet = fontStyleMapSet.Find( valueGet.first.indexKey );
334       }
335       else
336       {
337         // Get Key is a string so searching Set Map for a string key
338         valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
339       }
340
341       if( NULL != valueSet )
342       {
343         if( valueSet->GetType() == Dali::Property::STRING && ( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() ) )
344         {
345           tet_printf( "Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
346           return false;
347         }
348         else if( valueSet->GetType() == Dali::Property::BOOLEAN && ( valueGet.second.Get<bool>() != valueSet->Get<bool>() ) )
349         {
350           tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get<bool>(), valueSet->Get<bool>() );
351           return false;
352         }
353         else if( valueSet->GetType() == Dali::Property::INTEGER && ( valueGet.second.Get<int>() != valueSet->Get<int>() ) )
354         {
355           tet_printf( "Value got : [%d], expected : [%d]", valueGet.second.Get<int>(), valueSet->Get<int>() );
356           return false;
357         }
358         else if( valueSet->GetType() == Dali::Property::FLOAT && ( valueGet.second.Get<float>() != valueSet->Get<float>() ) )
359         {
360           tet_printf( "Value got : [%f], expected : [%f]", valueGet.second.Get<float>(), valueSet->Get<float>() );
361           return false;
362         }
363         else if( valueSet->GetType() == Dali::Property::VECTOR2 && ( valueGet.second.Get<Vector2>() != valueSet->Get<Vector2>() ) )
364         {
365           Vector2 vector2Get = valueGet.second.Get<Vector2>();
366           Vector2 vector2Set = valueSet->Get<Vector2>();
367           tet_printf( "Value got : [%f, %f], expected : [%f, %f]", vector2Get.x, vector2Get.y, vector2Set.x, vector2Set.y );
368           return false;
369         }
370         else if( valueSet->GetType() == Dali::Property::VECTOR4 && ( valueGet.second.Get<Vector4>() != valueSet->Get<Vector4>() ) )
371         {
372           Vector4 vector4Get = valueGet.second.Get<Vector4>();
373           Vector4 vector4Set = valueSet->Get<Vector4>();
374           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 );
375           return false;
376         }
377       }
378       else
379       {
380         if ( valueGet.first.type == Property::Key::INDEX )
381         {
382           tet_printf( "  The key %d doesn't exist.", valueGet.first.indexKey );
383         }
384         else
385         {
386           tet_printf( "  The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
387         }
388         return false;
389       }
390     }
391   }
392
393   return true;
394 }
395
396 } // namespace
397
398 int UtcDaliToolkitTextFieldConstructorP(void)
399 {
400   ToolkitTestApplication application;
401   tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
402   TextField textField;
403   DALI_TEST_CHECK( !textField );
404   END_TEST;
405 }
406
407 int UtcDaliToolkitTextFieldNewP(void)
408 {
409   ToolkitTestApplication application;
410   tet_infoline(" UtcDaliToolkitTextFieldNewP");
411   TextField textField = TextField::New();
412   DALI_TEST_CHECK( textField );
413   END_TEST;
414 }
415
416 int UtcDaliToolkitTextFieldDownCastP(void)
417 {
418   ToolkitTestApplication application;
419   tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
420   TextField textField1 = TextField::New();
421   BaseHandle object( textField1 );
422
423   TextField textField2 = TextField::DownCast( object );
424   DALI_TEST_CHECK( textField2 );
425
426   TextField textField3 = DownCast< TextField >( object );
427   DALI_TEST_CHECK( textField3 );
428   END_TEST;
429 }
430
431 int UtcDaliToolkitTextFieldDownCastN(void)
432 {
433   ToolkitTestApplication application;
434   tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
435   BaseHandle uninitializedObject;
436   TextField textField1 = TextField::DownCast( uninitializedObject );
437   DALI_TEST_CHECK( !textField1 );
438
439   TextField textField2 = DownCast< TextField >( uninitializedObject );
440   DALI_TEST_CHECK( !textField2 );
441   END_TEST;
442 }
443
444 int UtcDaliToolkitTextFieldCopyConstructorP(void)
445 {
446   ToolkitTestApplication application;
447   tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
448   TextField textField = TextField::New();
449   textField.SetProperty( TextField::Property::TEXT, "Test" );
450
451   TextField copy( textField );
452   DALI_TEST_CHECK( copy );
453   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
454   END_TEST;
455 }
456
457 int UtcDaliTextFieldMoveConstructor(void)
458 {
459   ToolkitTestApplication application;
460
461   TextField textField = TextField::New();
462   textField.SetProperty( TextEditor::Property::TEXT, "Test" );
463   DALI_TEST_CHECK( textField.GetProperty<std::string>( TextField::Property::TEXT ) == "Test" );
464
465   TextField moved = std::move( textField );
466   DALI_TEST_CHECK( moved );
467   DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
468   DALI_TEST_CHECK( moved.GetProperty<std::string>( TextField::Property::TEXT ) == "Test" );
469   DALI_TEST_CHECK( !textField );
470
471   END_TEST;
472 }
473
474 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
475 {
476   ToolkitTestApplication application;
477   tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
478   TextField textField = TextField::New();
479   textField.SetProperty( TextField::Property::TEXT, "Test" );
480
481   TextField copy = textField;
482   DALI_TEST_CHECK( copy );
483   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
484   END_TEST;
485 }
486
487 int UtcDaliTextFieldMoveAssignment(void)
488 {
489   ToolkitTestApplication application;
490
491   TextField textField = TextField::New();
492   textField.SetProperty( TextEditor::Property::TEXT, "Test" );
493   DALI_TEST_CHECK( textField.GetProperty<std::string>( TextField::Property::TEXT ) == "Test" );
494
495   TextField moved;
496   moved = std::move( textField );
497   DALI_TEST_CHECK( moved );
498   DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
499   DALI_TEST_CHECK( moved.GetProperty<std::string>( TextField::Property::TEXT ) == "Test" );
500   DALI_TEST_CHECK( !textField );
501
502   END_TEST;
503 }
504
505 int UtcDaliTextFieldNewP(void)
506 {
507   ToolkitTestApplication application;
508   tet_infoline(" UtcDaliToolkitTextFieldNewP");
509   TextField textField = TextField::New();
510   DALI_TEST_CHECK( textField );
511   END_TEST;
512 }
513
514 // Positive test case for a method
515 int UtcDaliTextFieldGetPropertyP(void)
516 {
517   ToolkitTestApplication application;
518   tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
519   TextField field = TextField::New();
520   DALI_TEST_CHECK( field );
521
522   // Check Property Indices are correct
523   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == DevelTextField::Property::RENDERING_BACKEND );
524   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
525   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
526   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
527   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
528   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
529   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
530   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
531   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
532   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
533   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
534   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
535   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
536   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
537   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
538   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
539   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
540   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
541   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
542   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
543   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
544   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
545   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
546   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
547   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
548   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
549   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
550   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
551   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
552   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
553   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
554   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
555   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
556   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
557   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
558   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
559   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
560   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
561   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
562   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
563   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
564   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
565   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
566   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
567   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
568   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HIDDEN_INPUT_SETTINGS ) == TextField::Property::HIDDEN_INPUT_SETTINGS );
569   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PIXEL_SIZE ) == TextField::Property::PIXEL_SIZE );
570   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SELECTION ) == TextField::Property::ENABLE_SELECTION );
571   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER ) == TextField::Property::PLACEHOLDER );
572   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ELLIPSIS ) == TextField::Property::ELLIPSIS );
573   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_SIZE_SCALE ) == DevelTextField::Property::FONT_SIZE_SCALE );
574   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_FONT_SIZE_SCALE ) == DevelTextField::Property::ENABLE_FONT_SIZE_SCALE );
575   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextField::Property::ENABLE_SHIFT_SELECTION );
576   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextField::Property::ENABLE_GRAB_HANDLE );
577   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION );
578   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE_POPUP ) == DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP );
579   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_BACKGROUND ) == DevelTextField::Property::BACKGROUND );
580   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_COLOR ) == DevelTextField::Property::GRAB_HANDLE_COLOR );
581   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FILTER ) == DevelTextField::Property::INPUT_FILTER );
582
583   END_TEST;
584 }
585
586 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
587 {
588   bool result = false;
589   Property::Map imageMap;
590   imageMap[mapKey] =mapValue;
591
592   field.SetProperty( property , imageMap );
593   Property::Value propValue = field.GetProperty( property );
594   Property::Map* resultMap = propValue.GetMap();
595
596   if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
597   {
598     result = true;
599   }
600
601   return result;
602 }
603
604 // Positive test case for a method
605 int UtcDaliTextFieldSetPropertyP(void)
606 {
607   ToolkitTestApplication application;
608   tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
609   TextField field = TextField::New();
610   DALI_TEST_CHECK( field );
611   application.GetScene().Add( field );
612
613   // Note - we can't check the defaults since the stylesheets are platform-specific
614
615   // Check the render backend property.
616   field.SetProperty( DevelTextField::Property::RENDERING_BACKEND, DevelText::RENDERING_SHARED_ATLAS );
617   DALI_TEST_EQUALS( (DevelText::RenderingType)field.GetProperty<int>( DevelTextField::Property::RENDERING_BACKEND ), DevelText::RENDERING_SHARED_ATLAS, TEST_LOCATION );
618
619   field.SetProperty( DevelTextField::Property::RENDERING_BACKEND, DevelText::RENDERING_VECTOR_BASED );
620   DALI_TEST_EQUALS( (DevelText::RenderingType)field.GetProperty<int>( DevelTextField::Property::RENDERING_BACKEND ), DevelText::RENDERING_VECTOR_BASED, TEST_LOCATION );
621
622   // Check text property.
623   field.SetProperty( TextField::Property::TEXT, "Setting Text" );
624   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
625
626   // Check placeholder text properties.
627   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
628   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
629
630   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
631   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
632
633   // Check font properties.
634   field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
635   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
636
637   Property::Map fontStyleMapSet;
638   Property::Map fontStyleMapGet;
639   Property::Value* slantValue = NULL;
640
641   fontStyleMapSet.Insert( "weight", "bold" );
642   fontStyleMapSet.Insert( "width", "condensed" );
643   fontStyleMapSet.Insert( "slant", "italic" );
644   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
645
646   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
647   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
648   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
649
650   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
651   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
652
653   field.SetProperty( DevelTextField::Property::FONT_SIZE_SCALE, 2.5f );
654   DALI_TEST_EQUALS( field.GetProperty<float>( DevelTextField::Property::FONT_SIZE_SCALE ), 2.5f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
655   field.SetProperty( DevelTextField::Property::FONT_SIZE_SCALE, 1.0f );
656
657   field.SetProperty( DevelTextField::Property::ENABLE_FONT_SIZE_SCALE, false );
658   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_FONT_SIZE_SCALE ), false, TEST_LOCATION );
659   field.SetProperty( DevelTextField::Property::ENABLE_FONT_SIZE_SCALE, true );
660
661   // Reset font style.
662   fontStyleMapSet.Clear();
663   fontStyleMapSet.Insert( "weight", "normal" );
664   fontStyleMapSet.Insert( "slant", "oblique" );
665   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
666
667   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
668   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
669   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
670
671   fontStyleMapSet.Clear();
672   fontStyleMapSet.Insert( "slant", "roman" );
673   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
674   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
675
676   // Replace 'roman' for 'normal'.
677   slantValue = fontStyleMapGet.Find( "slant" );
678   if( NULL != slantValue )
679   {
680     if( "normal" == slantValue->Get<std::string>() )
681     {
682       fontStyleMapGet["slant"] = "roman";
683     }
684   }
685   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
686   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
687
688   fontStyleMapSet.Clear();
689
690   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
691   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
692   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
693   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
694
695   // Check that the MAX_LENGTH property can be correctly set
696   const int maxNumberOfCharacters = 20;
697   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
698   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
699
700   // Check exceed policy
701   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP );
702   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION );
703   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
704   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
705
706   // Check that the Alignment properties can be correctly set
707   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
708   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
709   field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
710   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
711
712   // Check text's color property
713   field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
714   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
715
716   // Check placeholder text's color property.
717   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
718   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
719
720   // Check cursor properties
721   field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
722   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
723   field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
724   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
725
726   field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
727   DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
728   field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
729   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
730   field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
731   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
732   field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
733   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
734
735   // Check scroll properties.
736   field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
737   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
738   field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
739   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
740
741   // Check handle images
742   field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
743   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
744   field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
745   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
746   field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
747
748   // Check handle images
749   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" )  );
750   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" )  );
751   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" )  );
752   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" )  );
753   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" )  );
754   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" )  );
755
756   // Check the highlight color
757   field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
758   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
759
760   // Decoration bounding box
761   field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
762   DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
763
764   // Check the input method setting
765   Property::Map propertyMap;
766   InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
767   InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
768   InputMethod::ButtonAction::Type buttonAction = InputMethod::ButtonAction::GO;
769   int inputVariation = 1;
770   propertyMap["PANEL_LAYOUT"] = panelLayout;
771   propertyMap["AUTO_CAPITALIZE"] = autoCapital;
772   propertyMap["BUTTON_ACTION"] = buttonAction;
773   propertyMap["VARIATION"] = inputVariation;
774   field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
775
776   Property::Value value = field.GetProperty( TextField::Property::INPUT_METHOD_SETTINGS );
777   Property::Map map;
778   DALI_TEST_CHECK( value.Get( map ) );
779
780   int layout = 0;
781   DALI_TEST_CHECK( map[ "PANEL_LAYOUT" ].Get( layout ) );
782   DALI_TEST_EQUALS( static_cast<int>(panelLayout), layout, TEST_LOCATION );
783
784   int capital = 0;
785   DALI_TEST_CHECK( map[ "AUTO_CAPITALIZE" ].Get( capital ) );
786   DALI_TEST_EQUALS( static_cast<int>(autoCapital), capital, TEST_LOCATION );
787
788   int action = 0;
789   DALI_TEST_CHECK( map[ "BUTTON_ACTION" ].Get( action ) );
790   DALI_TEST_EQUALS( static_cast<int>(buttonAction), action, TEST_LOCATION );
791
792   int variation = 0;
793   DALI_TEST_CHECK( map[ "VARIATION" ].Get( variation ) );
794   DALI_TEST_EQUALS( inputVariation, variation, TEST_LOCATION );
795
796   // Check input color property.
797   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
798   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
799
800   // Check the enable markup property.
801   DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
802   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
803   DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
804
805   // Check input font properties.
806   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
807   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
808
809   fontStyleMapSet.Clear();
810   fontStyleMapSet.Insert( "weight", "bold" );
811   fontStyleMapSet.Insert( "width", "condensed" );
812   fontStyleMapSet.Insert( "slant", "italic" );
813
814   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
815   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
816   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
817   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
818
819   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
820   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
821
822   // Reset input font style.
823   fontStyleMapSet.Clear();
824   fontStyleMapSet.Insert( "weight", "normal" );
825   fontStyleMapSet.Insert( "slant", "oblique" );
826
827   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
828   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
829   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
830   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
831
832   fontStyleMapSet.Clear();
833   fontStyleMapSet.Insert( "slant", "roman" );
834
835   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
836   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
837
838   // Replace 'roman' for 'normal'.
839   slantValue = fontStyleMapGet.Find( "slant" );
840   if( NULL != slantValue )
841   {
842     if( "normal" == slantValue->Get<std::string>() )
843     {
844       fontStyleMapGet["slant"] = "roman";
845     }
846   }
847   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
848   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
849
850   fontStyleMapSet.Clear();
851
852   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
853   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
854   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
855   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
856
857   Property::Map underlineMapSet;
858   Property::Map underlineMapGet;
859
860   underlineMapSet.Insert( "enable", true );
861   underlineMapSet.Insert( "color", Color::RED );
862   underlineMapSet.Insert( "height", 1 );
863
864   // Check the underline property
865   field.SetProperty( TextField::Property::UNDERLINE, underlineMapSet );
866
867   underlineMapGet = field.GetProperty<Property::Map>( TextField::Property::UNDERLINE );
868   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
869   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
870
871   // Check the input underline property
872   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
873   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
874
875   // Check the shadow property
876   Property::Map shadowMapSet;
877   Property::Map shadowMapGet;
878
879   shadowMapSet.Insert( "color", Color::GREEN );
880   shadowMapSet.Insert( "offset", Vector2(2.0f, 2.0f) );
881   shadowMapSet.Insert( "blurRadius", 3.0f );
882
883   field.SetProperty( TextField::Property::SHADOW, shadowMapSet );
884
885   shadowMapGet = field.GetProperty<Property::Map>( TextField::Property::SHADOW );
886   DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
887   DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
888
889   // Check the input shadow property
890   field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
891   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
892
893   // Check the emboss property
894   field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
895   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
896
897   // Check the input emboss property
898   field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
899   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
900
901   // Check the outline property
902
903   // Test string type first
904   // This is purely to maintain backward compatibility, but we don't support string as the outline property type.
905   field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
906   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
907
908   // Then test the property map type
909   Property::Map outlineMapSet;
910   Property::Map outlineMapGet;
911
912   outlineMapSet["color"] = Color::RED;
913   outlineMapSet["width"] = 2.0f;
914
915   field.SetProperty( TextField::Property::OUTLINE, outlineMapSet );
916
917   outlineMapGet = field.GetProperty<Property::Map>( TextField::Property::OUTLINE );
918   DALI_TEST_EQUALS( outlineMapGet.Count(), outlineMapSet.Count(), TEST_LOCATION );
919   DALI_TEST_EQUALS( DaliTestCheckMaps( outlineMapGet, outlineMapSet ), true, TEST_LOCATION );
920
921   // Check the input outline property
922   field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
923   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
924
925   // Check the hidden input settings property
926   Property::Map hiddenMapSet;
927   Property::Map hiddenMapGet;
928   hiddenMapSet[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
929   hiddenMapSet[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 2;
930   hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 4;
931   hiddenMapSet[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
932   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, hiddenMapSet );
933
934   hiddenMapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
935   DALI_TEST_EQUALS( hiddenMapSet.Count(), hiddenMapGet.Count(), TEST_LOCATION );
936   DALI_TEST_EQUALS( DaliTestCheckMaps( hiddenMapSet, hiddenMapGet ), true, TEST_LOCATION );
937
938   // Check the pixel size of font
939   field.SetProperty( TextField::Property::PIXEL_SIZE, 20.f );
940   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::PIXEL_SIZE ), 20.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
941
942   // Check the enable selection property
943   field.SetProperty( TextField::Property::ENABLE_SELECTION, false );
944   DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_SELECTION ), false, TEST_LOCATION );
945
946   // Check the placeholder property with pixel size
947   Property::Map placeholderPixelSizeMapSet;
948   Property::Map placeholderPixelSizeMapGet;
949   Property::Map placeholderFontstyleMap;
950   placeholderPixelSizeMapSet["text"] = "Setting Placeholder Text";
951   placeholderPixelSizeMapSet["textFocused"] = "Setting Placeholder Text Focused";
952   placeholderPixelSizeMapSet["color"] = Color::BLUE;
953   placeholderPixelSizeMapSet["fontFamily"] = "Arial";
954   placeholderPixelSizeMapSet["pixelSize"] = 15.0f;
955   placeholderPixelSizeMapSet["ellipsis"] = true;
956
957   placeholderFontstyleMap.Insert( "weight", "bold" );
958   placeholderPixelSizeMapSet["placeholderFontStyle"] = placeholderFontstyleMap;
959   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
960
961   placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
962   DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
963
964   tet_infoline("Test Placeholder settings set as strings is converted correctly to Property Index key and holds set value");
965   Property::Map placeholderConversionMap;
966   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
967   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
968   placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
969   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
970   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
971   placeholderConversionMap[ Text::PlaceHolder::Property::PIXEL_SIZE ] = placeholderPixelSizeMapSet["pixelSize"];
972
973   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderConversionMap ), true, TEST_LOCATION );
974
975   // Check the placeholder property with point size
976   Property::Map placeholderMapSet;
977   Property::Map placeholderMapGet;
978   placeholderMapSet["text"] = "Setting Placeholder Text";
979   placeholderMapSet["textFocused"] = "Setting Placeholder Text Focused";
980   placeholderMapSet["color"] = Color::RED;
981   placeholderMapSet["fontFamily"] = "Arial";
982   placeholderMapSet["pointSize"] = 12.0f;
983   placeholderMapSet["ellipsis"] = false;
984
985   // Check the placeholder font style property
986   placeholderFontstyleMap.Clear();
987
988   placeholderFontstyleMap.Insert( "weight", "bold" );
989   placeholderFontstyleMap.Insert( "width", "condensed" );
990   placeholderFontstyleMap.Insert( "slant", "italic" );
991   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
992   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
993
994   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
995   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
996
997   placeholderConversionMap.Clear();
998   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT ] = placeholderPixelSizeMapSet["text"];
999   placeholderConversionMap[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = placeholderPixelSizeMapSet["textFocused"] ;
1000   placeholderConversionMap[ Text::PlaceHolder::Property::COLOR ] = placeholderPixelSizeMapSet["color"];
1001   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
1002   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = placeholderPixelSizeMapSet["fontFamily"];
1003   placeholderConversionMap[ Text::PlaceHolder::Property::POINT_SIZE ] = placeholderPixelSizeMapSet["pointSize"];
1004
1005   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
1006
1007   // Reset font style.
1008   placeholderFontstyleMap.Clear();
1009   placeholderFontstyleMap.Insert( "weight", "normal" );
1010   placeholderFontstyleMap.Insert( "slant", "oblique" );
1011   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
1012   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
1013
1014   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
1015   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
1016
1017   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
1018   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
1019
1020   placeholderFontstyleMap.Clear();
1021   placeholderFontstyleMap.Insert( "slant", "roman" );
1022   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
1023   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
1024
1025   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
1026
1027   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
1028
1029   placeholderFontstyleMap.Clear();
1030   placeholderMapSet["fontStyle"] = placeholderFontstyleMap;
1031   placeholderConversionMap[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderPixelSizeMapSet["fontStyle"];
1032
1033   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
1034   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
1035   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
1036
1037   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderConversionMap ), true, TEST_LOCATION );
1038
1039   // Check the ellipsis property
1040   DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
1041   field.SetProperty( TextField::Property::ELLIPSIS, true );
1042   DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ELLIPSIS ) );
1043
1044   field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
1045   DALI_TEST_EQUALS( field.GetProperty<int>( Actor::Property::LAYOUT_DIRECTION ), static_cast<int>( LayoutDirection::RIGHT_TO_LEFT ), TEST_LOCATION );
1046
1047   // Test the ENABLE_GRAB_HANDLE_POPUP property
1048   DALI_TEST_CHECK( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP ) );
1049   field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP, false );
1050   DALI_TEST_CHECK( !field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE_POPUP ) );
1051
1052   // Check the background property
1053   field.SetProperty( DevelTextField::Property::BACKGROUND, Color::RED );
1054   DALI_TEST_EQUALS( field.GetProperty<Vector4>( DevelTextField::Property::BACKGROUND ), Color::RED, TEST_LOCATION );
1055
1056   //Check handle color
1057   field.SetProperty( DevelTextField::Property::GRAB_HANDLE_COLOR, Color::GREEN );
1058   DALI_TEST_EQUALS( field.GetProperty<Vector4>( DevelTextField::Property::GRAB_HANDLE_COLOR ), Color::GREEN, TEST_LOCATION );
1059
1060   // Check the input filter property
1061   Property::Map inputFilterMapSet;
1062   Property::Map inputFilterMapGet;
1063   inputFilterMapSet[InputFilter::Property::ACCEPTED] = "[\\w]";
1064   inputFilterMapSet[InputFilter::Property::REJECTED] = "[\\d]";
1065
1066   field.SetProperty(DevelTextField::Property::INPUT_FILTER, inputFilterMapSet);
1067
1068   inputFilterMapGet = field.GetProperty<Property::Map>(DevelTextField::Property::INPUT_FILTER);
1069   DALI_TEST_EQUALS(inputFilterMapGet.Count(), inputFilterMapSet.Count(), TEST_LOCATION);
1070
1071   // Clear
1072   inputFilterMapSet.Clear();
1073   field.SetProperty(DevelTextField::Property::INPUT_FILTER, inputFilterMapSet);
1074
1075   application.SendNotification();
1076   application.Render();
1077
1078   END_TEST;
1079 }
1080
1081 // Positive Atlas Text Renderer test
1082 int utcDaliTextFieldAtlasRenderP(void)
1083 {
1084   ToolkitTestApplication application;
1085   tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
1086   StyleManager styleManager = StyleManager::Get();
1087   styleManager.ApplyDefaultTheme();
1088   TextField field = TextField::New();
1089   DALI_TEST_CHECK( field );
1090
1091   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
1092
1093   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1094
1095   application.GetScene().Add( field );
1096
1097   try
1098   {
1099     // Render some text with the shared atlas backend
1100     field.SetProperty( DevelTextField::Property::RENDERING_BACKEND, DevelText::RENDERING_SHARED_ATLAS );
1101     application.SendNotification();
1102     application.Render();
1103   }
1104   catch( ... )
1105   {
1106     tet_result(TET_FAIL);
1107   }
1108   END_TEST;
1109 }
1110
1111 // Positive test for the anchorClicked signal.
1112 int utcDaliTextFieldAnchorClicked01(void)
1113 {
1114   ToolkitTestApplication application;
1115   tet_infoline(" utcDaliTextFieldAnchorClicked01");
1116   TextField field = TextField::New();
1117   DALI_TEST_CHECK(field);
1118
1119   application.GetScene().Add(field);
1120
1121   // connect to the anchor clicked signal.
1122   ConnectionTracker* testTracker = new ConnectionTracker();
1123   DevelTextField::AnchorClickedSignal(field).Connect(&TestAnchorClickedCallback);
1124   bool anchorClickedSignal = false;
1125   field.ConnectSignal(testTracker, "anchorClicked", CallbackFunctor(&anchorClickedSignal));
1126
1127   gAnchorClickedCallBackCalled = false;
1128   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1129   field.SetProperty(TextField::Property::ENABLE_MARKUP, true);
1130   field.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
1131   field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1132   field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1133
1134   application.SendNotification();
1135   application.Render();
1136   field.SetKeyInputFocus();
1137
1138   // Create a tap event to touch the text field.
1139   TestGenerateTap(application, 5.0f, 25.0f);
1140   application.SendNotification();
1141   application.Render();
1142
1143   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1144   DALI_TEST_CHECK(anchorClickedSignal);
1145
1146   gAnchorClickedCallBackNotCalled = true;
1147   // Tap the outside of anchor, callback should not be called.
1148   TestGenerateTap(application, 150.f, 100.f);
1149   application.SendNotification();
1150   application.Render();
1151
1152   DALI_TEST_CHECK(gAnchorClickedCallBackNotCalled);
1153
1154   END_TEST;
1155 }
1156
1157 // Positive test for the anchorClicked signal.
1158 int utcDaliTextFieldAnchorClicked02(void)
1159 {
1160   ToolkitTestApplication application;
1161   tet_infoline(" utcDaliTextFieldAnchorClicked02");
1162   TextField field = TextField::New();
1163   DALI_TEST_CHECK(field);
1164
1165   application.GetScene().Add(field);
1166
1167   // connect to the anchor clicked signal.
1168   ConnectionTracker* testTracker = new ConnectionTracker();
1169   DevelTextField::AnchorClickedSignal(field).Connect(&TestAnchorClickedCallback);
1170   bool anchorClickedSignal = false;
1171   field.ConnectSignal(testTracker, "anchorClicked", CallbackFunctor(&anchorClickedSignal));
1172
1173   gAnchorClickedCallBackCalled = false;
1174   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1175   field.SetProperty(TextField::Property::ENABLE_MARKUP, true);
1176   field.SetProperty(Actor::Property::SIZE, Vector2(100.f, 50.f));
1177   field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
1178   field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
1179
1180   application.SendNotification();
1181   application.Render();
1182   field.SetKeyInputFocus();
1183
1184   // Avoid a crash when core load gl resources.
1185   application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE);
1186
1187   // Create a tap event to touch the text field.
1188   TestGenerateTap(application, 30.0f, 25.0f, 100);
1189   application.SendNotification();
1190   application.Render();
1191
1192   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1193   DALI_TEST_CHECK(anchorClickedSignal);
1194
1195
1196   // For coverage InsertTextAnchor, RemoveTextAnchor
1197   // first index insert
1198   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1199   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 0);
1200   application.SendNotification();
1201   application.Render();
1202
1203   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1204   application.SendNotification();
1205   application.Render();
1206
1207   gAnchorClickedCallBackCalled = false;
1208   // Create a tap event to touch the text field.
1209   TestGenerateTap(application, 30.0f, 25.0f, 700);
1210   application.SendNotification();
1211   field.SetKeyInputFocus();
1212
1213   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1214
1215   // last index insert
1216   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1217   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 5);
1218   application.SendNotification();
1219   application.Render();
1220
1221   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1222   application.SendNotification();
1223   application.Render();
1224
1225   gAnchorClickedCallBackCalled = false;
1226   // Create a tap event to touch the text field.
1227   TestGenerateTap(application, 30.0f, 25.0f, 1300);
1228   application.SendNotification();
1229   field.SetKeyInputFocus();
1230
1231   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1232
1233   // mid index insert
1234   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1235   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 2);
1236   application.SendNotification();
1237   application.Render();
1238
1239   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1240   application.SendNotification();
1241   application.Render();
1242
1243   gAnchorClickedCallBackCalled = false;
1244   // Create a tap event to touch the text field.
1245   TestGenerateTap(application, 30.0f, 25.0f, 1900);
1246   application.SendNotification();
1247   field.SetKeyInputFocus();
1248
1249   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1250
1251   // first index remove
1252   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1253   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 0);
1254   application.SendNotification();
1255   application.Render();
1256
1257   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1258   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));
1259   application.SendNotification();
1260   application.Render();
1261
1262   gAnchorClickedCallBackCalled = false;
1263   // Create a tap event to touch the text field.
1264   TestGenerateTap(application, 30.0f, 25.0f, 2500);
1265   application.SendNotification();
1266   field.SetKeyInputFocus();
1267
1268   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1269
1270   // last index remove
1271   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1272   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 5);
1273   application.SendNotification();
1274   application.Render();
1275
1276   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1277   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));
1278   application.SendNotification();
1279   application.Render();
1280
1281   gAnchorClickedCallBackCalled = false;
1282   // Create a tap event to touch the text field.
1283   TestGenerateTap(application, 30.0f, 25.0f, 3100);
1284   application.SendNotification();
1285   application.Render();
1286
1287   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1288
1289   // middle index
1290   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1291   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 2);
1292   application.SendNotification();
1293   application.Render();
1294
1295   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1296   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));
1297   application.SendNotification();
1298   application.Render();
1299
1300   gAnchorClickedCallBackCalled = false;
1301   // Create a tap event to touch the text field.
1302   TestGenerateTap(application, 30.0f, 25.0f, 3700);
1303   application.SendNotification();
1304   application.Render();
1305
1306   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1307
1308   // 0 ~ 1 index remove
1309   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1310   field.SetProperty( DevelTextField::Property::SELECTED_TEXT_START, 0);
1311   field.SetProperty( DevelTextField::Property::SELECTED_TEXT_END, 1);
1312   application.SendNotification();
1313   application.Render();
1314
1315   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1316   application.SendNotification();
1317   application.Render();
1318
1319   gAnchorClickedCallBackCalled = false;
1320   // Create a tap event to touch the text field.
1321   TestGenerateTap(application, 30.0f, 25.0f, 4300);
1322   application.SendNotification();
1323   application.Render();
1324
1325   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1326
1327   // 1 ~ 3 index remove
1328   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1329   field.SetProperty( DevelTextField::Property::SELECTED_TEXT_START, 1);
1330   field.SetProperty( DevelTextField::Property::SELECTED_TEXT_END, 3);
1331   application.SendNotification();
1332   application.Render();
1333
1334   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1335   application.SendNotification();
1336   application.Render();
1337
1338   gAnchorClickedCallBackCalled = false;
1339   // Create a tap event to touch the text field.
1340   TestGenerateTap(application, 30.0f, 25.0f, 4900);
1341   application.SendNotification();
1342   application.Render();
1343
1344   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1345
1346   // 3 ~ 4 index remove
1347   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1348   field.SetProperty( DevelTextField::Property::SELECTED_TEXT_START, 3);
1349   field.SetProperty( DevelTextField::Property::SELECTED_TEXT_END, 4);
1350   application.SendNotification();
1351   application.Render();
1352
1353   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1354   application.SendNotification();
1355   application.Render();
1356
1357   gAnchorClickedCallBackCalled = false;
1358   // Create a tap event to touch the text field.
1359   TestGenerateTap(application, 30.0f, 25.0f, 5500);
1360   application.SendNotification();
1361   application.Render();
1362
1363   DALI_TEST_CHECK(gAnchorClickedCallBackCalled);
1364
1365   // Remove front of anchor
1366   field.SetProperty(TextField::Property::TEXT, "TIZEN<a href='https://www.tizen.org'>TIZEN</a>");
1367   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
1368   application.SendNotification();
1369   application.Render();
1370
1371   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1372   application.SendNotification();
1373   application.Render();
1374
1375   // Remove whole text
1376   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>TIZEN</a>");
1377   DevelTextField::SelectWholeText(field);
1378   application.SendNotification();
1379   application.Render();
1380
1381   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1382   application.SendNotification();
1383   application.Render();
1384
1385   // Remove all with backspace
1386   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>T</a>");
1387   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 1);
1388   application.SendNotification();
1389   application.Render();
1390
1391   application.ProcessEvent(GenerateKey("", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1392   application.SendNotification();
1393   application.Render();
1394
1395   // Remove all with delete
1396   field.SetProperty(TextField::Property::TEXT, "<a href='https://www.tizen.org'>T</a>");
1397   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 0);
1398   application.SendNotification();
1399   application.Render();
1400
1401   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));
1402   application.SendNotification();
1403   application.Render();
1404
1405   END_TEST;
1406 }
1407
1408 // Positive test for the textChanged signal.
1409 int utcDaliTextFieldTextChangedP(void)
1410 {
1411   ToolkitTestApplication application;
1412   tet_infoline(" utcDaliTextFieldTextChangedP");
1413   TextField field = TextField::New();
1414   DALI_TEST_CHECK( field );
1415
1416   application.GetScene().Add( field );
1417
1418   // connect to the text changed signal.
1419   ConnectionTracker* testTracker = new ConnectionTracker();
1420   field.TextChangedSignal().Connect(&TestTextChangedCallback);
1421   bool textChangedSignal = false;
1422   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
1423
1424   gTextChangedCallBackCalled = false;
1425   field.SetProperty( TextField::Property::TEXT, "ABC" );
1426   DALI_TEST_CHECK( gTextChangedCallBackCalled );
1427   DALI_TEST_CHECK( textChangedSignal );
1428
1429   application.SendNotification();
1430   field.SetKeyInputFocus();
1431
1432   gTextChangedCallBackCalled = false;
1433   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1434   DALI_TEST_CHECK( gTextChangedCallBackCalled );
1435
1436   // Remove all text
1437   field.SetProperty( TextField::Property::TEXT, "" );
1438
1439   // Pressing backspace key: TextChangedCallback should not be called when there is no text in textfield.
1440   gTextChangedCallBackCalled = false;
1441   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1442   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1443
1444   // Pressing delete key: TextChangedCallback should not be called when there is no text in textfield.
1445   gTextChangedCallBackCalled = false;
1446   application.ProcessEvent( GenerateKey( "", "", "", Dali::DevelKey::DALI_KEY_DELETE, 0, 0, Integration::KeyEvent::DOWN, "Delete", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1447   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1448
1449   END_TEST;
1450 }
1451
1452 int utcDaliTextFieldTextChangedWithInputMethodContext(void)
1453 {
1454   ToolkitTestApplication application;
1455   tet_infoline(" utcDaliTextFieldTextChangedWithInputMethodContext");
1456   TextField field = TextField::New();
1457   DALI_TEST_CHECK( field );
1458
1459
1460   application.GetScene().Add( field );
1461
1462   // connect to the text changed signal.
1463   ConnectionTracker* testTracker = new ConnectionTracker();
1464   field.TextChangedSignal().Connect(&TestTextChangedCallback);
1465   bool textChangedSignal = false;
1466   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
1467
1468
1469   // get InputMethodContext
1470   std::string text;
1471   InputMethodContext::EventData imfEvent;
1472   InputMethodContext inputMethodContext = DevelTextField::GetInputMethodContext( field );
1473
1474   field.SetKeyInputFocus();
1475   field.SetProperty( DevelTextField::Property::ENABLE_EDITING, true );
1476
1477   // input text
1478   gTextChangedCallBackCalled = false;
1479   imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "ㅎ", 0, 1 );
1480   inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
1481   application.SendNotification();
1482   application.Render();
1483   DALI_TEST_CHECK( gTextChangedCallBackCalled );
1484   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ㅎ"), TEST_LOCATION );
1485
1486   gTextChangedCallBackCalled = false;
1487   imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "호", 0, 1 );
1488   inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
1489   application.SendNotification();
1490   application.Render();
1491   DALI_TEST_CHECK( gTextChangedCallBackCalled );
1492   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("호"), TEST_LOCATION );
1493
1494   gTextChangedCallBackCalled = false;
1495   imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "혿", 0, 1 );
1496   inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
1497   application.SendNotification();
1498   application.Render();
1499   DALI_TEST_CHECK( gTextChangedCallBackCalled );
1500   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("혿"), TEST_LOCATION );
1501
1502   gTextChangedCallBackCalled = false;
1503   imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "", 0, 1 );
1504   inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
1505   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1506
1507   imfEvent = InputMethodContext::EventData( InputMethodContext::COMMIT, "호", 0, 1 );
1508   inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
1509   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1510
1511   imfEvent = InputMethodContext::EventData( InputMethodContext::PRE_EDIT, "두", 1, 2 );
1512   inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent);
1513   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1514
1515   application.SendNotification();
1516   application.Render();
1517   DALI_TEST_CHECK( gTextChangedCallBackCalled );
1518   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("호두"), TEST_LOCATION );
1519
1520   END_TEST;
1521 }
1522
1523
1524 // Negative test for the textChanged signal.
1525 int utcDaliTextFieldTextChangedN(void)
1526 {
1527   ToolkitTestApplication application;
1528   tet_infoline(" utcDaliTextFieldTextChangedN");
1529   TextField field = TextField::New();
1530   DALI_TEST_CHECK( field );
1531
1532   application.GetScene().Add( field );
1533
1534   // connect to the text changed signal.
1535   ConnectionTracker* testTracker = new ConnectionTracker();
1536   field.TextChangedSignal().Connect(&TestTextChangedCallback);
1537   bool textChangedSignal = false;
1538   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
1539
1540   gTextChangedCallBackCalled = false;
1541   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
1542   application.SendNotification();
1543   application.Render();
1544   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
1545   DALI_TEST_CHECK( !textChangedSignal );
1546
1547   END_TEST;
1548 }
1549
1550 // Positive test for Max Characters reached signal.
1551 int utcDaliTextFieldMaxCharactersReachedP(void)
1552 {
1553   ToolkitTestApplication application;
1554   tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
1555   TextField field = TextField::New();
1556   DALI_TEST_CHECK( field );
1557
1558   application.GetScene().Add( field );
1559
1560   const int maxNumberOfCharacters = 1;
1561   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1562
1563   field.SetKeyInputFocus();
1564
1565   // connect to the text changed signal.
1566   ConnectionTracker* testTracker = new ConnectionTracker();
1567   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1568   bool maxLengthReachedSignal = false;
1569   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
1570
1571   gMaxCharactersCallBackCalled = false;
1572
1573   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1574   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1575
1576   DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
1577   DALI_TEST_CHECK( maxLengthReachedSignal );
1578
1579   END_TEST;
1580 }
1581
1582 // Negative test for Max Characters reached signal.
1583 int utcDaliTextFieldMaxCharactersReachedN(void)
1584 {
1585   ToolkitTestApplication application;
1586   tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
1587   TextField field = TextField::New();
1588   DALI_TEST_CHECK( field );
1589
1590   application.GetScene().Add( field );
1591
1592   const int maxNumberOfCharacters = 3;
1593   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
1594
1595   field.SetKeyInputFocus();
1596
1597   // connect to the text changed signal.
1598   ConnectionTracker* testTracker = new ConnectionTracker();
1599   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
1600   bool maxLengthReachedSignal = false;
1601   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
1602
1603   gMaxCharactersCallBackCalled = false;
1604
1605   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1606   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1607
1608   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1609   DALI_TEST_CHECK( !maxLengthReachedSignal );
1610
1611   application.ProcessEvent( GenerateKey( "Return", "", "\r", KEY_RETURN_CODE, 0, 0, Integration::KeyEvent::DOWN, "\r", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
1612
1613   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
1614   DALI_TEST_CHECK( !maxLengthReachedSignal );
1615
1616   END_TEST;
1617 }
1618
1619 // Positive test for Input Filtered signal.
1620 int utcDaliTextFieldInputFilteredP(void)
1621 {
1622   ToolkitTestApplication application;
1623   tet_infoline(" utcDaliTextFieldInputFilteredP");
1624   TextField field = TextField::New();
1625   DALI_TEST_CHECK(field);
1626
1627   application.GetScene().Add(field);
1628
1629   Property::Map inputFilter;
1630
1631   // Only digit is accepted.
1632   inputFilter[InputFilter::Property::ACCEPTED] = "[\\d]";
1633
1634   // Set input filter to TextField.
1635   field.SetProperty(DevelTextField::Property::INPUT_FILTER, inputFilter);
1636
1637   field.SetKeyInputFocus();
1638
1639   // connect to the input filtered signal.
1640   ConnectionTracker* testTracker = new ConnectionTracker();
1641   DevelTextField::InputFilteredSignal(field).Connect(&TestInputFilteredCallback);
1642   bool inputFilteredSignal = false;
1643   field.ConnectSignal(testTracker, "inputFiltered", CallbackFunctor(&inputFilteredSignal));
1644
1645   gInputFilteredAcceptedCallbackCalled = false;
1646
1647   application.ProcessEvent(GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ));
1648
1649   DALI_TEST_CHECK(gInputFilteredAcceptedCallbackCalled);
1650   DALI_TEST_CHECK(inputFilteredSignal);
1651
1652   // Word is rejected.
1653   inputFilter[InputFilter::Property::ACCEPTED] = "";
1654   inputFilter[InputFilter::Property::REJECTED] = "[\\w]";
1655
1656   // Set input filter to TextField.
1657   field.SetProperty(DevelTextField::Property::INPUT_FILTER, inputFilter);
1658
1659   field.SetKeyInputFocus();
1660
1661   inputFilteredSignal = false;
1662   gInputFilteredRejectedCallbackCalled = false;
1663
1664   application.ProcessEvent(GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1665
1666   DALI_TEST_CHECK(gInputFilteredAcceptedCallbackCalled);
1667   DALI_TEST_CHECK(inputFilteredSignal);
1668
1669   END_TEST;
1670 }
1671
1672 // Negative test for Input Filtered signal.
1673 int utcDaliTextFieldInputFilteredN(void)
1674 {
1675   ToolkitTestApplication application;
1676   tet_infoline(" utcDaliTextFieldInputFilteredP");
1677   TextField field = TextField::New();
1678   DALI_TEST_CHECK(field);
1679
1680   application.GetScene().Add(field);
1681
1682   Property::Map inputFilter;
1683
1684   // Only word is accepted.
1685   inputFilter[InputFilter::Property::ACCEPTED] = "[\\w]";
1686
1687   // Set input filter to TextField.
1688   field.SetProperty(DevelTextField::Property::INPUT_FILTER, inputFilter);
1689
1690   field.SetKeyInputFocus();
1691
1692   // connect to the input filtered signal.
1693   ConnectionTracker* testTracker = new ConnectionTracker();
1694   DevelTextField::InputFilteredSignal(field).Connect(&TestInputFilteredCallback);
1695   bool inputFilteredSignal = false;
1696   field.ConnectSignal(testTracker, "inputFiltered", CallbackFunctor(&inputFilteredSignal));
1697
1698   gInputFilteredAcceptedCallbackCalled = false;
1699
1700   // Key a, d should not be filtered.
1701   application.ProcessEvent(GenerateKey("a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1702   application.ProcessEvent(GenerateKey("a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1703   application.ProcessEvent(GenerateKey("d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1704   application.ProcessEvent(GenerateKey("d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::UP, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1705
1706   // Backspace, Delete should not be filtered.
1707   application.ProcessEvent(GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1708   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));
1709
1710   // Render and notify
1711   application.SendNotification();
1712   application.Render();
1713
1714   DALI_TEST_CHECK(!gInputFilteredAcceptedCallbackCalled);
1715   DALI_TEST_CHECK(!inputFilteredSignal);
1716
1717   // Digit is rejected.
1718   inputFilter[InputFilter::Property::ACCEPTED] = "";
1719   inputFilter[InputFilter::Property::REJECTED] = "[\\d]";
1720
1721   field.SetProperty(DevelTextField::Property::INPUT_FILTER, inputFilter);
1722
1723   field.SetKeyInputFocus();
1724
1725   inputFilteredSignal = false;
1726   gInputFilteredRejectedCallbackCalled = false;
1727
1728   // Key a, d should not be filtered.
1729   application.ProcessEvent(GenerateKey("a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1730   application.ProcessEvent(GenerateKey("a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1731   application.ProcessEvent(GenerateKey("d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1732   application.ProcessEvent(GenerateKey("d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::UP, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1733
1734   // Backspace, Delete should not be filtered.
1735   application.ProcessEvent(GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE));
1736   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));
1737
1738   // Render and notify
1739   application.SendNotification();
1740   application.Render();
1741
1742   DALI_TEST_CHECK(!gInputFilteredAcceptedCallbackCalled);
1743   DALI_TEST_CHECK(!inputFilteredSignal);
1744
1745   END_TEST;
1746 }
1747
1748 int utcDaliTextFieldInputStyleChanged01(void)
1749 {
1750   // The text-field emits signals when the input style changes. These changes of style are
1751   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1752   // can't be emitted during the size negotiation as the callbacks may update the UI.
1753   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1754   // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks.
1755   ToolkitTestApplication application;
1756   tet_infoline(" utcDaliTextFieldInputStyleChanged01");
1757
1758   // Load some fonts.
1759
1760   char* pathNamePtr = get_current_dir_name();
1761   const std::string pathName( pathNamePtr );
1762   free( pathNamePtr );
1763
1764   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1765   fontClient.SetDpi( 93u, 93u );
1766
1767   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1768   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1769
1770   TextField field = TextField::New();
1771   DALI_TEST_CHECK( field );
1772
1773
1774   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
1775   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1776   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1777
1778   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1779   field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
1780
1781   // connect to the text changed signal.
1782   ConnectionTracker* testTracker = new ConnectionTracker();
1783   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1784   bool inputStyleChangedSignal = false;
1785   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1786
1787   application.GetScene().Add( field );
1788
1789   // Render and notify
1790   application.SendNotification();
1791   application.Render();
1792
1793   // Executes the idle callbacks added by the text control on the change of input style.
1794   application.RunIdles();
1795
1796   gInputStyleChangedCallbackCalled = false;
1797   gInputStyleMask = TextField::InputStyle::NONE;
1798   inputStyleChangedSignal = false;
1799
1800   // Create a tap event to touch the text field.
1801   TestGenerateTap( application, 18.0f, 25.0f );
1802
1803   // Render and notify
1804   application.SendNotification();
1805   application.Render();
1806
1807   // Executes the idle callbacks added by the text control on the change of input style.
1808   application.RunIdles();
1809
1810   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1811   if( gInputStyleChangedCallbackCalled )
1812   {
1813     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
1814
1815     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1816     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1817
1818     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1819     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1820   }
1821   DALI_TEST_CHECK( inputStyleChangedSignal );
1822
1823   gInputStyleChangedCallbackCalled = false;
1824   gInputStyleMask = TextField::InputStyle::NONE;
1825   inputStyleChangedSignal = false;
1826
1827   // Create a tap event to touch the text field.
1828   TestGenerateTap( application, 30.0f, 25.0f );
1829
1830   // Render and notify
1831   application.SendNotification();
1832   application.Render();
1833
1834   // Executes the idle callbacks added by the text control on the change of input style.
1835   application.RunIdles();
1836
1837   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1838   DALI_TEST_CHECK( !inputStyleChangedSignal );
1839
1840   gInputStyleChangedCallbackCalled = false;
1841   gInputStyleMask = TextField::InputStyle::NONE;
1842   inputStyleChangedSignal = false;
1843
1844   // Create a tap event to touch the text field.
1845   TestGenerateTap( application, 43.0f, 25.0f );
1846
1847   // Render and notify
1848   application.SendNotification();
1849   application.Render();
1850
1851   // Executes the idle callbacks added by the text control on the change of input style.
1852   application.RunIdles();
1853
1854   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1855   if( gInputStyleChangedCallbackCalled )
1856   {
1857     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1858
1859     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1860     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1861   }
1862   DALI_TEST_CHECK( inputStyleChangedSignal );
1863
1864   gInputStyleChangedCallbackCalled = false;
1865   gInputStyleMask = TextField::InputStyle::NONE;
1866   inputStyleChangedSignal = false;
1867
1868   // Create a tap event to touch the text field.
1869   TestGenerateTap( application, 88.0f, 25.0f );
1870
1871   // Render and notify
1872   application.SendNotification();
1873   application.Render();
1874
1875   // Executes the idle callbacks added by the text control on the change of input style.
1876   application.RunIdles();
1877
1878   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1879   if( gInputStyleChangedCallbackCalled )
1880   {
1881     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1882
1883     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1884     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1885
1886     const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1887
1888     Property::Map fontStyleMapSet;
1889     fontStyleMapSet.Insert( "weight", "bold" );
1890
1891     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1892     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1893   }
1894   DALI_TEST_CHECK( inputStyleChangedSignal );
1895
1896   gInputStyleChangedCallbackCalled = false;
1897   gInputStyleMask = TextField::InputStyle::NONE;
1898   inputStyleChangedSignal = false;
1899
1900   // Create a tap event to touch the text field.
1901   TestGenerateTap( application, 115.0f, 25.0f );
1902
1903   // Render and notify
1904   application.SendNotification();
1905   application.Render();
1906
1907   // Executes the idle callbacks added by the text control on the change of input style.
1908   application.RunIdles();
1909
1910   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1911   DALI_TEST_CHECK( !inputStyleChangedSignal );
1912
1913   gInputStyleChangedCallbackCalled = false;
1914   gInputStyleMask = TextField::InputStyle::NONE;
1915   inputStyleChangedSignal = false;
1916
1917   // Create a tap event to touch the text field.
1918   TestGenerateTap( application, 164.0f, 25.0f );
1919
1920   // Render and notify
1921   application.SendNotification();
1922   application.Render();
1923
1924   // Executes the idle callbacks added by the text control on the change of input style.
1925   application.RunIdles();
1926
1927   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1928   if( gInputStyleChangedCallbackCalled )
1929   {
1930     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1931
1932     const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1933     DALI_TEST_CHECK( style.empty() );
1934   }
1935   DALI_TEST_CHECK( inputStyleChangedSignal );
1936
1937   gInputStyleChangedCallbackCalled = false;
1938   gInputStyleMask = TextField::InputStyle::NONE;
1939   inputStyleChangedSignal = false;
1940
1941   // Create a tap event to touch the text field.
1942   TestGenerateTap( application, 191.0f, 25.0f );
1943
1944   // Render and notify
1945   application.SendNotification();
1946   application.Render();
1947
1948   // Executes the idle callbacks added by the text control on the change of input style.
1949   application.RunIdles();
1950
1951   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1952   DALI_TEST_CHECK( !inputStyleChangedSignal );
1953
1954   END_TEST;
1955 }
1956
1957 int utcDaliTextFieldInputStyleChanged02(void)
1958 {
1959   // The text-field emits signals when the input style changes. These changes of style are
1960   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1961   // can't be emitted during the size negotiation as the callbacks may update the UI.
1962   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1963   // The ToolkitTestApplication creates an implementation of the adaptor stub and a queue of idle callbacks.
1964   ToolkitTestApplication application;
1965   tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1966
1967   // Load some fonts.
1968
1969   char* pathNamePtr = get_current_dir_name();
1970   const std::string pathName( pathNamePtr );
1971   free( pathNamePtr );
1972
1973   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1974   fontClient.SetDpi( 93u, 93u );
1975
1976   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1977   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1978
1979   TextField field = TextField::New();
1980   DALI_TEST_CHECK( field );
1981
1982   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
1983   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
1984   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
1985
1986   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1987   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>" );
1988
1989   // connect to the text changed signal.
1990   ConnectionTracker* testTracker = new ConnectionTracker();
1991   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1992   bool inputStyleChangedSignal = false;
1993   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1994
1995   application.GetScene().Add( field );
1996
1997   // Render and notify
1998   application.SendNotification();
1999   application.Render();
2000
2001   // Executes the idle callbacks added by the text control on the change of input style.
2002   application.RunIdles();
2003
2004   gInputStyleChangedCallbackCalled = false;
2005   gInputStyleMask = TextField::InputStyle::NONE;
2006   inputStyleChangedSignal = false;
2007
2008   // Create a tap event to touch the text field.
2009   TestGenerateTap( application, 53.0f, 25.0f, 100 );
2010   TestGenerateTap( application, 53.0f, 25.0f, 200 );
2011
2012   // Render and notify
2013   application.SendNotification();
2014   application.Render();
2015
2016   // Executes the idle callbacks added by the text control on the change of input style.
2017   application.RunIdles();
2018
2019   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
2020   if( gInputStyleChangedCallbackCalled )
2021   {
2022     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
2023                       static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
2024                                                  TextField::InputStyle::POINT_SIZE  |
2025                                                  TextField::InputStyle::COLOR ),
2026                       TEST_LOCATION );
2027
2028     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
2029     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
2030
2031     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
2032     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
2033
2034     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
2035     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2036   }
2037   DALI_TEST_CHECK( inputStyleChangedSignal );
2038
2039   gInputStyleChangedCallbackCalled = false;
2040   gInputStyleMask = TextField::InputStyle::NONE;
2041   inputStyleChangedSignal = false;
2042
2043   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2044
2045   // Render and notify
2046   application.SendNotification();
2047   application.Render();
2048
2049   // Executes the idle callbacks added by the text control on the change of input style.
2050   application.RunIdles();
2051
2052   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
2053   if( gInputStyleChangedCallbackCalled )
2054   {
2055     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
2056                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
2057                       TEST_LOCATION );
2058
2059     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
2060     DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
2061   }
2062   DALI_TEST_CHECK( inputStyleChangedSignal );
2063
2064   gInputStyleChangedCallbackCalled = false;
2065   gInputStyleMask = TextField::InputStyle::NONE;
2066   inputStyleChangedSignal = false;
2067
2068   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2069
2070   // Render and notify
2071   application.SendNotification();
2072   application.Render();
2073
2074   // Executes the idle callbacks added by the text control on the change of input style.
2075   application.RunIdles();
2076
2077   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
2078   DALI_TEST_CHECK( !inputStyleChangedSignal );
2079
2080   gInputStyleChangedCallbackCalled = false;
2081   gInputStyleMask = TextField::InputStyle::NONE;
2082   inputStyleChangedSignal = false;
2083
2084   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2085
2086   // Render and notify
2087   application.SendNotification();
2088   application.Render();
2089
2090   // Executes the idle callbacks added by the text control on the change of input style.
2091   application.RunIdles();
2092
2093   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
2094   if( gInputStyleChangedCallbackCalled )
2095   {
2096     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
2097                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
2098                       TEST_LOCATION );
2099
2100     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
2101     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
2102   }
2103   DALI_TEST_CHECK( inputStyleChangedSignal );
2104
2105   gInputStyleChangedCallbackCalled = false;
2106   gInputStyleMask = TextField::InputStyle::NONE;
2107   inputStyleChangedSignal = false;
2108
2109   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
2110
2111   Property::Map fontStyleMapSet;
2112   fontStyleMapSet.Insert( "weight", "thin" );
2113   fontStyleMapSet.Insert( "width", "condensed" );
2114   fontStyleMapSet.Insert( "slant", "italic" );
2115
2116   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2117   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
2118
2119   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
2120   field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
2121   field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
2122   field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
2123
2124   // Render and notify
2125   application.SendNotification();
2126   application.Render();
2127
2128   // Executes the idle callbacks added by the text control on the change of input style.
2129   application.RunIdles();
2130
2131   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
2132   DALI_TEST_CHECK( !inputStyleChangedSignal );
2133
2134   // Create a tap event to touch the text field.
2135   TestGenerateTap( application, 63.0f, 25.0f, 700 );
2136
2137   // Render and notify
2138   application.SendNotification();
2139   application.Render();
2140
2141   // Executes the idle callbacks added by the text control on the change of input style.
2142   application.RunIdles();
2143
2144   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
2145   if( gInputStyleChangedCallbackCalled )
2146   {
2147     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
2148                       static_cast<unsigned int>( TextField::InputStyle::COLOR |
2149                                                  TextField::InputStyle::POINT_SIZE |
2150                                                  TextField::InputStyle::FONT_STYLE |
2151                                                  TextField::InputStyle::UNDERLINE |
2152                                                  TextField::InputStyle::SHADOW |
2153                                                  TextField::InputStyle::EMBOSS |
2154                                                  TextField::InputStyle::OUTLINE ),
2155                       TEST_LOCATION );
2156
2157     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
2158     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
2159   }
2160   DALI_TEST_CHECK( inputStyleChangedSignal );
2161
2162   END_TEST;
2163 }
2164
2165 int utcDaliTextFieldEvent01(void)
2166 {
2167   ToolkitTestApplication application;
2168   tet_infoline(" utcDaliTextFieldEvent01");
2169
2170   // Creates a tap event. After creating a tap event the text field should
2171   // have the focus and add text with key events should be possible.
2172
2173   TextField field = TextField::New();
2174   DALI_TEST_CHECK( field );
2175
2176   application.GetScene().Add( field );
2177
2178   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2179   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2180   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2181
2182   // Render and notify
2183   application.SendNotification();
2184   application.Render();
2185
2186   // Avoid a crash when core load gl resources.
2187   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2188
2189   // Render and notify
2190   application.SendNotification();
2191   application.Render();
2192
2193   // Add a key event but as the text field has not the focus it should do nothing.
2194   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2195
2196   // Render and notify
2197   application.SendNotification();
2198   application.Render();
2199
2200   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2201
2202   // Create a tap event to touch the text field.
2203   TestGenerateTap( application, 150.0f, 25.0f );
2204
2205   // Render and notify
2206   application.SendNotification();
2207   application.Render();
2208
2209   // Pressing delete key should be fine even if there is no text in TextField.
2210   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 ) );
2211   // Render and notify
2212   application.SendNotification();
2213   application.Render();
2214
2215   // Now the text field has the focus, so it can handle the key events.
2216   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2217   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2218
2219   // Render and notify
2220   application.SendNotification();
2221   application.Render();
2222
2223   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
2224
2225   // Create a second text field and send key events to it.
2226   TextField field2 = TextField::New();
2227
2228   field2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2229   field2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2230   field2.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 100.f ) );
2231   field2.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
2232
2233   application.GetScene().Add( field2 );
2234
2235   // Render and notify
2236   application.SendNotification();
2237   application.Render();
2238
2239   // Create a tap event on the second text field.
2240   TestGenerateTap( application, 150.0f, 125.0f );
2241
2242   // Render and notify
2243   application.SendNotification();
2244   application.Render();
2245
2246   // The second text field has the focus. It should handle the key events.
2247   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2248   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2249
2250   // Render and notify
2251   application.SendNotification();
2252   application.Render();
2253
2254   // Check the text has been added to the second text field.
2255   DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
2256
2257   END_TEST;
2258 }
2259
2260 int utcDaliTextFieldEvent02(void)
2261 {
2262   ToolkitTestApplication application;
2263   tet_infoline(" utcDaliTextFieldEvent02");
2264
2265   // Checks if the right number of actors are created.
2266
2267   TextField field = TextField::New();
2268   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2269   DALI_TEST_CHECK( field );
2270   LoadMarkerImages(application, field);
2271
2272   application.GetScene().Add( field );
2273
2274   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2275   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2276   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2277
2278   // Avoid a crash when core load gl resources.
2279   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2280
2281   // Render and notify
2282   application.SendNotification();
2283   application.Render();
2284
2285   // Check there are the expected number of children ( stencil ).
2286   DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
2287
2288   Actor stencil = field.GetChildAt( 0u );
2289   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
2290
2291   // Create a tap event to touch the text field.
2292   TestGenerateTap( application, 150.0f, 25.0f, 300 );
2293
2294   // Render and notify
2295   application.SendNotification();
2296   application.Render();
2297
2298   Actor layer = field.GetChildAt( 1u );
2299   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
2300   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
2301
2302   // Now the text field has the focus, so it can handle the key events.
2303   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2304   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2305
2306   // Render and notify
2307   application.SendNotification();
2308   application.Render();
2309
2310   // Checks the cursor and the renderer have been created.
2311   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
2312   DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
2313
2314   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
2315   DALI_TEST_CHECK( cursor );
2316
2317   // The offscreen root actor has a container with all the actors which contain the text renderers.
2318   Actor container = stencil.GetChildAt( 0u );
2319   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
2320   {
2321     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
2322     DALI_TEST_CHECK( renderer );
2323   }
2324
2325   // Move the cursor and check the position changes.
2326   Vector3 position1 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
2327   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2328
2329   // Render and notify
2330   application.SendNotification();
2331   application.Render();
2332
2333   Vector3 position2 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
2334   DALI_TEST_CHECK( position2.x < position1.x );
2335
2336   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2337
2338   // Render and notify
2339   application.SendNotification();
2340   application.Render();
2341
2342   Vector3 position3 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
2343   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
2344
2345
2346   // Move the cursor to the first position.
2347   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2348   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2349
2350   // Render and notify
2351   application.SendNotification();
2352   application.Render();
2353
2354   Vector3 position4 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
2355
2356   // Send some taps and check the cursor positions.
2357
2358   // Try to tap at the beginning.
2359   TestGenerateTap( application, 1.0f, 25.0f, 900 );
2360
2361   // Render and notify
2362   application.SendNotification();
2363   application.Render();
2364
2365   // Cursor position should be the same than position1.
2366   Vector3 position5 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
2367
2368   DALI_TEST_EQUALS( position4, position5, TEST_LOCATION ); // Should be in the same position2.
2369
2370   // Tap away from the start position.
2371   TestGenerateTap( application, 16.0f, 25.0f, 1500 );
2372
2373   // Render and notify
2374   application.SendNotification();
2375   application.Render();
2376
2377   Vector3 position6 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
2378
2379   DALI_TEST_CHECK( position6.x > position5.x );
2380
2381   // Remove all the text.
2382   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2383   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2384   field.SetProperty( TextField::Property::TEXT, "" );
2385
2386   // Render and notify
2387   application.SendNotification();
2388   application.Render();
2389
2390   // Cursor position should be the same than position2.
2391   Vector3 position7 = cursor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
2392
2393   DALI_TEST_EQUALS( position4, position7, TEST_LOCATION );// Should be in the same position2.
2394
2395   // Should not be a renderer.
2396   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
2397
2398   // Chanege exceed policy (EXCEED_POLICY_ORIGINAL doesn't use stencil )
2399   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2400   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
2401
2402   application.SendNotification();
2403   application.Render();
2404
2405   // There are renderer and decorator layer
2406   DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
2407
2408   END_TEST;
2409 }
2410
2411 int utcDaliTextFieldEvent03(void)
2412 {
2413   ToolkitTestApplication application;
2414   tet_infoline(" utcDaliTextFieldEvent03");
2415
2416   // Checks if the highlight actor is created.
2417
2418   TextField field = TextField::New();
2419   DALI_TEST_CHECK( field );
2420
2421   application.GetScene().Add( field );
2422
2423   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2424   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2425   field.SetProperty( Actor::Property::SIZE, Vector2( 30.f, 50.f ) );
2426   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2427   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2428
2429   // Avoid a crash when core load gl resources.
2430   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2431   LoadMarkerImages(application, field);
2432
2433   // Render and notify
2434   application.SendNotification();
2435   application.Render();
2436
2437   // Tap first to get the focus.
2438   TestGenerateTap( application, 3.0f, 25.0f );
2439
2440   // Render and notify
2441   application.SendNotification();
2442   application.Render();
2443
2444   // Double tap to select a word.
2445   TestGenerateTap( application, 3.0f, 25.0f );
2446
2447   // Render and notify
2448   application.SendNotification();
2449   application.Render();
2450
2451   // The offscreen root actor should have two actors: the renderer and the highlight actor.
2452   Actor stencil = field.GetChildAt( 0u );
2453
2454   // The highlight actor is drawn first, so is the first actor in the list
2455   Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
2456   DALI_TEST_CHECK( highlight );
2457
2458   // The offscreen root actor has a container with all the actors which contain the text renderers.
2459   Actor container = stencil.GetChildAt( 1u );
2460   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
2461   {
2462     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
2463     DALI_TEST_CHECK( renderer );
2464   }
2465
2466   END_TEST;
2467 }
2468
2469 int utcDaliTextFieldEvent04(void)
2470 {
2471   ToolkitTestApplication application;
2472   tet_infoline(" utcDaliTextFieldEvent04");
2473
2474   // Checks if the highlight actor is created.
2475
2476   TextField field = TextField::New();
2477   DALI_TEST_CHECK( field );
2478   application.GetScene().Add( field );
2479   LoadMarkerImages(application, field);
2480   // Render and notify
2481   application.SendNotification();
2482   application.Render();
2483
2484   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2485   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2486   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2487   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2488   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2489
2490   // Avoid a crash when core load gl resources.
2491   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2492   // Render and notify
2493   application.SendNotification();
2494   application.Render();
2495
2496   // Create a tap event to touch the text field.
2497   TestGenerateTap( application, 150.0f, 25.0f );
2498   // Render and notify
2499   application.SendNotification();
2500   application.Render();
2501
2502
2503   // Tap first to get the focus.
2504   TestGenerateTap( application, 1.0f, 25.0f );
2505
2506   // Render and notify
2507   application.SendNotification();
2508   application.Render();
2509
2510   // Double tap to select a word.
2511   TestGenerateTap( application, 1.0f, 25.0f );
2512
2513   // Render and notify
2514   application.SendNotification();
2515   application.Render();
2516
2517   // Tap grab handle
2518   TestGenerateTap( application, 0.0f, 40.0f );
2519   END_TEST;
2520 }
2521
2522 int utcDaliTextFieldEvent05(void)
2523 {
2524   ToolkitTestApplication application;
2525   tet_infoline(" utcDaliTextFieldEvent05");
2526
2527   // Checks dragging of cursor/grab handle
2528
2529   TextField field = TextField::New();
2530   DALI_TEST_CHECK( field );
2531   application.GetScene().Add( field );
2532   LoadMarkerImages(application, field);
2533   // Render and notify
2534   application.SendNotification();
2535   application.Render();
2536
2537   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2538   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2539   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2540   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2541   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2542
2543   // Avoid a crash when core load gl resources.
2544   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2545   // Render and notify
2546   application.SendNotification();
2547   application.Render();
2548
2549   // Create a tap event to touch the text field.
2550   TestGenerateTap( application, 150.0f, 25.0f );
2551   // Render and notify
2552   application.SendNotification();
2553   application.Render();
2554
2555   // Tap first to get the focus.
2556   TestGenerateTap( application, 1.0f, 25.0f );
2557
2558   // Render and notify
2559   application.SendNotification();
2560   application.Render();
2561
2562   // Double tap to select a word.
2563   TestGenerateTap( application, 1.0f, 25.0f );
2564
2565   // Render and notify
2566   application.SendNotification();
2567   application.Render();
2568
2569   Actor stencil = field.GetChildAt( 1u );
2570   END_TEST;
2571 }
2572
2573 int utcDaliTextFieldEvent06(void)
2574 {
2575   ToolkitTestApplication application;
2576   tet_infoline(" utcDaliTextFieldEvent06");
2577
2578   // Checks Longpress when in edit mode
2579
2580   TextField field = TextField::New();
2581   DALI_TEST_CHECK( field );
2582   application.GetScene().Add( field );
2583   LoadMarkerImages(application, field);
2584   // Render and notify
2585   application.SendNotification();
2586   application.Render();
2587
2588   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
2589   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2590   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2591   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2592   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2593
2594   // Avoid a crash when core load gl resources.
2595   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2596   // Render and notify
2597   application.SendNotification();
2598   application.Render();
2599
2600   // Create a tap event to touch the text field.
2601   TestGenerateTap( application, 150.0f, 25.0f );
2602   // Render and notify
2603   application.SendNotification();
2604   application.Render();
2605
2606
2607   // Tap first to get the focus.
2608   TestGenerateTap( application, 1.0f, 25.0f );
2609
2610   // Render and notify
2611   application.SendNotification();
2612   application.Render();
2613
2614   // Long Press
2615   TestGenerateLongPress(application, 1.0f, 25.0f);
2616
2617   // Render and notify
2618   application.SendNotification();
2619   application.Render();
2620
2621   END_TEST;
2622 }
2623
2624 int utcDaliTextFieldEvent07(void)
2625 {
2626   ToolkitTestApplication application;
2627   tet_infoline(" utcDaliTextFieldEvent07");
2628
2629   // Checks Longpress to start edit mode
2630
2631   TextField field = TextField::New();
2632   DALI_TEST_CHECK( field );
2633   application.GetScene().Add( field );
2634   LoadMarkerImages(application, field);
2635   // Render and notify
2636   application.SendNotification();
2637   application.Render();
2638
2639   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
2640   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2641   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2642   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2643   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2644   Property::Map propertyMap;
2645   propertyMap["PANEL_LAYOUT"] = InputMethod::PanelLayout::PASSWORD;
2646   field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
2647
2648   // Avoid a crash when core load gl resources.
2649   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2650   // Render and notify
2651   application.SendNotification();
2652   application.Render();
2653
2654   // Long Press
2655   TestGenerateLongPress(application, 1.0f, 25.0f);
2656
2657   // Render and notify
2658   application.SendNotification();
2659   application.Render();
2660
2661   END_TEST;
2662 }
2663
2664 int utcDaliTextFieldEvent08(void)
2665 {
2666   ToolkitTestApplication application;
2667   tet_infoline(" utcDaliTextFieldEvent08");
2668
2669   Dali::Clipboard clipboard = Clipboard::Get();
2670   clipboard.SetItem("testTextFieldEvent");
2671
2672   // Checks Longpress when only place holder text
2673
2674   TextField field = TextField::New();
2675   DALI_TEST_CHECK( field );
2676   application.GetScene().Add( field );
2677   LoadMarkerImages(application, field);
2678   // Render and notify
2679   application.SendNotification();
2680   application.Render();
2681
2682   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
2683   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2684   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2685   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2686   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2687
2688   // Avoid a crash when core load gl resources.
2689   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2690   // Render and notify
2691   application.SendNotification();
2692   application.Render();
2693
2694   // Long Press
2695   TestGenerateLongPress( application, 1.0f, 25.0f, 20 );
2696
2697   // Render and notify
2698   application.SendNotification();
2699   application.Render();
2700
2701   Wait(application, 500);
2702
2703   TestEndLongPress( application, 1.0f, 25.0f, 520 );
2704
2705   // Long Press
2706   TestGenerateLongPress( application, 1.0f, 25.0f, 600 );
2707
2708   // Render and notify
2709   application.Render();
2710
2711   Wait(application, 500);
2712
2713   Integration::Scene stage = application.GetScene();
2714   Layer layer = stage.GetRootLayer();
2715   Actor actor = layer.FindChildByName("optionPaste");
2716
2717   if (actor)
2718   {
2719     Vector3 worldPosition = actor.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_POSITION );
2720     Vector2 halfStageSize = stage.GetSize() / 2.0f;
2721     Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
2722
2723     Dali::Integration::TouchEvent event;
2724     event = Dali::Integration::TouchEvent();
2725     event.AddPoint( GetPointDownInside( position ) );
2726     application.ProcessEvent( event );
2727
2728     event = Dali::Integration::TouchEvent();
2729     event.AddPoint( GetPointUpInside( position ) );
2730     application.ProcessEvent( event );
2731   }
2732   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
2733
2734   END_TEST;
2735 }
2736
2737 int utcDaliTextFieldEvent09(void)
2738 {
2739   ToolkitTestApplication application;
2740   tet_infoline(" utcDaliTextFieldEvent09");
2741
2742   TextField field = TextField::New();
2743   DALI_TEST_CHECK( field );
2744   application.GetScene().Add( field );
2745   LoadMarkerImages(application, field);
2746   // Render and notify
2747   application.SendNotification();
2748   application.Render();
2749
2750   field.SetProperty( TextField::Property::TEXT, "Hello" );
2751   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2752   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2753   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2754   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2755
2756   // Avoid a crash when core load gl resources.
2757   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2758
2759   // Create a tap event to touch the text field.
2760   TestGenerateTap( application, 150.0f, 25.0f );
2761   application.SendNotification();
2762   application.Render();
2763
2764   Property::Map map;
2765   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_NONE;
2766   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2767   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2768   application.SendNotification();
2769   application.Render();
2770
2771   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_ALL;
2772   map[ HiddenInput::Property::SUBSTITUTE_CHARACTER ] = 0x23;
2773   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2774   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2775   application.SendNotification();
2776   application.Render();
2777
2778   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::HIDE_COUNT;
2779   map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2780   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2781   for( unsigned int index = 0u; index < 5u; ++index )
2782   {
2783     application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2784     application.SendNotification();
2785     application.Render();
2786   }
2787
2788   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_COUNT;
2789   map[ HiddenInput::Property::SUBSTITUTE_COUNT ] = 2;
2790   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2791   for( unsigned int index = 0u; index < 5u; ++index )
2792   {
2793     application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2794     application.SendNotification();
2795     application.Render();
2796   }
2797
2798   map[ HiddenInput::Property::MODE ] = HiddenInput::Mode::SHOW_LAST_CHARACTER;
2799   map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 0;
2800   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2801   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2802   application.SendNotification();
2803   application.Render();
2804   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2805   application.SendNotification();
2806   application.Render();
2807
2808   map[ HiddenInput::Property::SHOW_LAST_CHARACTER_DURATION ] = 100;
2809   field.SetProperty( TextField::Property::HIDDEN_INPUT_SETTINGS, map );
2810   application.ProcessEvent( GenerateKey( "d", "", "d", 0, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2811   application.SendNotification();
2812   application.Render();
2813
2814   Property::Map mapGet;
2815   mapGet = field.GetProperty<Property::Map>( TextField::Property::HIDDEN_INPUT_SETTINGS );
2816   DALI_TEST_EQUALS( map.Count(), mapGet.Count(), TEST_LOCATION );
2817   DALI_TEST_EQUALS( DaliTestCheckMaps( map, mapGet ), true, TEST_LOCATION );
2818   END_TEST;
2819 }
2820
2821
2822 int utcDaliTextFieldStyleWhilstSelected(void)
2823 {
2824   ToolkitTestApplication application;
2825   tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
2826
2827   // Change font and styles whilst text is selected whilst word selected
2828
2829   TextField field = TextField::New();
2830   DALI_TEST_CHECK( field );
2831   application.GetScene().Add( field );
2832   LoadMarkerImages(application, field);
2833   // Render and notify
2834   application.SendNotification();
2835   application.Render();
2836
2837   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
2838   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
2839   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2840   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2841   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2842
2843   // Avoid a crash when core load gl resources.
2844   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2845   // Render and notify
2846   application.SendNotification();
2847   application.Render();
2848
2849   // Create a tap event to touch the text field.
2850   TestGenerateTap( application, 150.0f, 25.0f );
2851   // Render and notify
2852   application.SendNotification();
2853   application.Render();
2854
2855
2856   // Tap first to get the focus.
2857   TestGenerateTap( application, 1.0f, 25.0f );
2858
2859   // Render and notify
2860   application.SendNotification();
2861   application.Render();
2862
2863   // Double tap to select a word.
2864   TestGenerateTap( application, 1.0f, 25.0f );
2865
2866   // Render and notify
2867   application.SendNotification();
2868   application.Render();
2869
2870   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
2871   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
2872
2873   Property::Map fontStyleMapSet;
2874   Property::Map fontStyleMapGet;
2875
2876   fontStyleMapSet.Insert( "weight", "bold" );
2877   fontStyleMapSet.Insert( "slant", "italic" );
2878   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2879
2880   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2881   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2882   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2883
2884   fontStyleMapSet.Clear();
2885   fontStyleMapSet.Insert( "width", "expanded" );
2886   fontStyleMapSet.Insert( "slant", "italic" );
2887   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2888
2889   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2890   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2891   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2892
2893   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2894   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2895
2896   field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2897   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2898
2899   fontStyleMapSet.Clear();
2900   fontStyleMapSet.Insert( "weight", "bold" );
2901   fontStyleMapSet.Insert( "slant", "italic" );
2902
2903   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2904
2905   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2906   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2907   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2908
2909   fontStyleMapSet.Clear();
2910   fontStyleMapSet.Insert( "width", "expanded" );
2911
2912   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2913
2914   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2915   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2916   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2917
2918   // Press Escape to increase coverage
2919   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2920   application.SendNotification();
2921   application.Render();
2922
2923   DALI_TEST_CHECK( !field.HasKeyInputFocus() );
2924
2925   END_TEST;
2926 }
2927
2928 int utcDaliTextFieldEscKeyLoseFocus(void)
2929 {
2930   ToolkitTestApplication application;
2931   tet_infoline(" utcDaliTextFieldEscKeyLoseFocus");
2932
2933   // Creates a tap event. After creating a tap event the text field should
2934   // have the focus and add text with key events should be possible.
2935
2936   TextField field = TextField::New();
2937   DALI_TEST_CHECK( field );
2938
2939   application.GetScene().Add( field );
2940
2941   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
2942   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
2943   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
2944
2945   // Avoid a crash when core load gl resources.
2946   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
2947
2948   // Render and notify
2949   application.SendNotification();
2950   application.Render();
2951
2952   // Add a key event but as the text field has not the focus it should do nothing.
2953   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2954   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2955
2956   // Render and notify
2957   application.SendNotification();
2958   application.Render();
2959
2960   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
2961
2962   // Create a tap event to touch the text field.
2963   TestGenerateTap( application, 150.0f, 25.0f );
2964
2965   // Render and notify
2966   application.SendNotification();
2967   application.Render();
2968
2969   // Now the text field has the focus, so it can handle the key events.
2970   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2971   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2972   application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2973   application.ProcessEvent( GenerateKey( "d", "", "d", KEY_D_CODE, 0, 0, Integration::KeyEvent::UP, "d", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2974
2975   // Render and notify
2976   application.SendNotification();
2977   application.Render();
2978
2979   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
2980
2981   // Generate a Esc key event. The text field should lose the focus.
2982   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2983   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2984
2985   // Render and notify
2986   application.SendNotification();
2987   application.Render();
2988
2989   DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
2990
2991   // No more text should be introduced
2992   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2993   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::UP, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
2994
2995   // Render and notify
2996   application.SendNotification();
2997   application.Render();
2998
2999   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("ad"), TEST_LOCATION );
3000
3001   END_TEST;
3002 }
3003
3004 int utcDaliTextFieldSomeSpecialKeys(void)
3005 {
3006   ToolkitTestApplication application;
3007   tet_infoline(" utcDaliTextFieldSomeSpecialKeys");
3008
3009   // Checks some special keys when the text is selected.
3010
3011   TextField field = TextField::New();
3012   DALI_TEST_CHECK( field );
3013   application.GetScene().Add( field );
3014   LoadMarkerImages(application, field);
3015   // Render and notify
3016   application.SendNotification();
3017   application.Render();
3018
3019   const std::string longText( "This is a long text for the size of the text-field." );
3020
3021   field.SetProperty( TextField::Property::TEXT, longText );
3022   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
3023   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3024   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3025   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3026
3027   // Avoid a crash when core load gl resources.
3028   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3029   // Render and notify
3030   application.SendNotification();
3031   application.Render();
3032
3033   // Create a tap event to touch the text field.
3034   TestGenerateTap( application, 150.0f, 25.0f );
3035
3036   // Render and notify
3037   application.SendNotification();
3038   application.Render();
3039
3040   // Tap first to get the focus.
3041   TestGenerateTap( application, 1.0f, 25.0f );
3042
3043   // Render and notify
3044   application.SendNotification();
3045   application.Render();
3046
3047   // Double tap to select a word.
3048   TestGenerateTap( application, 1.0f, 25.0f );
3049
3050   // Render and notify
3051   application.SendNotification();
3052   application.Render();
3053
3054   // Generate a Esc key event. The text field should lose the focus.
3055   application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::DOWN, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3056   application.ProcessEvent( GenerateKey( "XF86PowerOff", "", "XF86PowerOff", DALI_KEY_POWER, 0, 0, Integration::KeyEvent::UP, "XF86PowerOff", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3057
3058   // Render and notify
3059   application.SendNotification();
3060   application.Render();
3061
3062   // Generate a Esc key event. The text field should lose the focus.
3063   application.ProcessEvent( GenerateKey( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::DOWN, "XF86Menu", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3064   application.ProcessEvent( GenerateKey( "XF86Menu", "", "XF86Menu", DALI_KEY_MENU, 0, 0, Integration::KeyEvent::UP, "XF86Menu", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3065
3066   // Render and notify
3067   application.SendNotification();
3068   application.Render();
3069
3070   // Generate a Esc key event. The text field should lose the focus.
3071   application.ProcessEvent( GenerateKey( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::DOWN, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3072   application.ProcessEvent( GenerateKey( "XF86Home", "", "XF86Home", DALI_KEY_HOME, 0, 0, Integration::KeyEvent::UP, "XF86Home", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3073
3074   // Render and notify
3075   application.SendNotification();
3076   application.Render();
3077
3078   // The text shouldn't be deleted.
3079   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), longText, TEST_LOCATION );
3080
3081   END_TEST;
3082 }
3083
3084 int utcDaliTextFieldSizeUpdate(void)
3085 {
3086   ToolkitTestApplication application;
3087   tet_infoline("utcDaliTextFieldSizeUpdate");
3088
3089   // Checks some special keys when the text is selected.
3090   TextField field = TextField::New();
3091   DALI_TEST_CHECK( field );
3092   application.GetScene().Add( field );
3093
3094   float previousHeight = 0.0f;
3095   float currentHeight = 0.0f;
3096   const float fieldWidth = 1920.0f;
3097
3098
3099   // "ㅁ" is bigger then "ኢ"
3100   field.SetProperty( Actor::Property::SIZE, Vector2( fieldWidth ,10.0f ) );
3101   field.SetResizePolicy( ResizePolicy::FIXED , Dimension::WIDTH );
3102   field.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY , Dimension::HEIGHT );
3103
3104   field.SetProperty( TextField::Property::TEXT, "ኢ");
3105   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3106   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3107
3108   field.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
3109   KeyboardFocusManager::Get().SetCurrentFocusActor( field );
3110
3111   application.SendNotification();
3112   application.Render();
3113
3114   previousHeight = field.GetHeightForWidth( fieldWidth );
3115   DALI_TEST_EQUALS( previousHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ) , TEST_LOCATION );
3116
3117   // Add  another script characters ( glyph height is defferent )
3118   application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3119   application.ProcessEvent( GenerateKey( "ㅁ", "", "ㅁ", KEY_A_CODE, 0, 0, Integration::KeyEvent::UP, "ㅁ", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3120
3121   application.SendNotification();
3122   application.Render();
3123
3124   currentHeight = field.GetHeightForWidth( fieldWidth );
3125   DALI_TEST_EQUALS( currentHeight, field.GetProperty<float>( Actor::Property::SIZE_HEIGHT ), TEST_LOCATION );
3126   DALI_TEST_EQUALS( (previousHeight < currentHeight), true , TEST_LOCATION );
3127
3128   END_TEST;
3129 }
3130
3131 int utcDaliTextFieldExtremlyLargePointSize(void)
3132 {
3133   ToolkitTestApplication application;
3134   tet_infoline(" utcDaliTextFieldExtremlyLargePointSize");
3135
3136   TextField field = TextField::New();
3137
3138   field.SetProperty( TextField::Property::TEXT, "Text" );
3139   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3140   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3141   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3142   application.GetScene().Add( field );
3143
3144   try
3145   {
3146     field.SetProperty( TextField::Property::POINT_SIZE, 160.0f );
3147     application.SendNotification();
3148     DALI_TEST_CHECK( field );
3149   }
3150   catch (...)
3151   {
3152     tet_result(TET_FAIL);
3153   }
3154   END_TEST;
3155 }
3156
3157 int UtcDaliTextFieldDefaultFontStylePropertyCoverage(void)
3158 {
3159   ToolkitTestApplication application;
3160   tet_infoline("UtcDaliTextFieldFontStylePorpertyCoverage");
3161   TextField field = TextField::New();
3162   DALI_TEST_CHECK( field );
3163   application.GetScene().Add( field );
3164
3165   Property::Map fontStyleMapGet;
3166
3167   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
3168
3169   Property::Value* weightValue = NULL;
3170   Property::Value* widthValue = NULL;
3171   Property::Value* slantValue = NULL;
3172   weightValue = fontStyleMapGet.Find( "weight" );
3173   widthValue = fontStyleMapGet.Find( "width" );
3174   slantValue = fontStyleMapGet.Find( "slant" );
3175   DALI_TEST_CHECK( !weightValue );
3176   DALI_TEST_CHECK( !widthValue );
3177   DALI_TEST_CHECK( !slantValue );
3178
3179   END_TEST;
3180 }
3181
3182 int UtcDaliTextFieldSettingPlaceholder(void)
3183 {
3184   ToolkitTestApplication application;
3185   tet_infoline("UtcDaliTextFieldSettingPlaceholder");
3186
3187   TextField field = TextField::New();
3188   DALI_TEST_CHECK( field );
3189   application.GetScene().Add( field );
3190
3191   // Check the placeholder property with pixel size
3192   Property::Map placeholderPixelSizeMapSet;
3193   Property::Map placeholderPixelSizeMapGet;
3194   Property::Map placeholderFontstyleMap;
3195   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
3196   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
3197   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::BLUE;
3198   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
3199   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::PIXEL_SIZE ] = 15.0f;
3200   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
3201
3202   placeholderFontstyleMap.Insert( "weight", "bold" );
3203   placeholderPixelSizeMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
3204   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderPixelSizeMapSet );
3205
3206   placeholderPixelSizeMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
3207   DALI_TEST_EQUALS( placeholderPixelSizeMapGet.Count(), placeholderPixelSizeMapSet.Count(), TEST_LOCATION );
3208   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderPixelSizeMapGet, placeholderPixelSizeMapSet ), true, TEST_LOCATION );
3209
3210   // Check the placeholder property with point size
3211   Property::Map placeholderMapSet;
3212   Property::Map placeholderMapGet;
3213   placeholderMapSet[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
3214   placeholderMapSet[ Text::PlaceHolder::Property::TEXT_FOCUSED ] = "Setting Placeholder Text Focused";
3215   placeholderMapSet[ Text::PlaceHolder::Property::COLOR ] = Color::RED;
3216   placeholderMapSet[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
3217   placeholderMapSet[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
3218   placeholderMapSet[ Text::PlaceHolder::Property::ELLIPSIS ] = false;
3219
3220   // Check the placeholder font style property
3221   placeholderFontstyleMap.Clear();
3222
3223   placeholderFontstyleMap.Insert( "weight", "bold" );
3224   placeholderFontstyleMap.Insert( "width", "condensed" );
3225   placeholderFontstyleMap.Insert( "slant", "italic" );
3226   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
3227   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
3228
3229   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
3230   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
3231   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
3232
3233   // Reset font style.
3234   placeholderFontstyleMap.Clear();
3235   placeholderFontstyleMap.Insert( "weight", "normal" );
3236   placeholderFontstyleMap.Insert( "slant", "oblique" );
3237   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
3238   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
3239
3240   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
3241   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
3242   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
3243
3244   placeholderFontstyleMap.Clear();
3245   placeholderFontstyleMap.Insert( "slant", "roman" );
3246   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
3247   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
3248
3249   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
3250
3251   placeholderFontstyleMap.Clear();
3252   placeholderMapSet[ Text::PlaceHolder::Property::FONT_STYLE ] = placeholderFontstyleMap;
3253
3254   field.SetProperty( TextField::Property::PLACEHOLDER, placeholderMapSet );
3255   placeholderMapGet = field.GetProperty<Property::Map>( TextField::Property::PLACEHOLDER );
3256   DALI_TEST_EQUALS( placeholderMapGet.Count(), placeholderMapSet.Count(), TEST_LOCATION );
3257   DALI_TEST_EQUALS( DaliTestCheckMaps( placeholderMapGet, placeholderMapSet ), true, TEST_LOCATION );
3258
3259   END_TEST;
3260 }
3261
3262 int UtcDaliTextFieldPlaceholderCoverage(void)
3263 {
3264   ToolkitTestApplication application;
3265   tet_infoline("UtcDaliTextFieldPlaceholderCoverage");
3266
3267   // mPlaceholderFont is created only once, so create a new control for coverage.
3268   TextField fieldForCoverage = TextField::New();
3269   DALI_TEST_CHECK(fieldForCoverage);
3270   application.GetScene().Add(fieldForCoverage);
3271
3272   // for SetPlaceholderFontFamily() coverage.
3273   Property::Map fontFamilyMap;
3274   fontFamilyMap[Text::PlaceHolder::Property::FONT_FAMILY] = "Arial";
3275   fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontFamilyMap);
3276
3277   // mPlaceholderFont is created only once, so create a new control for coverage.
3278   fieldForCoverage = TextField::New();
3279   DALI_TEST_CHECK(fieldForCoverage);
3280   application.GetScene().Add(fieldForCoverage);
3281
3282   // for SetPlaceholderTextFontSize coverage.
3283   Property::Map fontSizeMap;
3284   fontSizeMap[Text::PlaceHolder::Property::PIXEL_SIZE] = 15.0f;
3285   fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontSizeMap);
3286
3287   // mPlaceholderFont is created only once, so create a new control for coverage.
3288   fieldForCoverage = TextField::New();
3289   DALI_TEST_CHECK(fieldForCoverage);
3290   application.GetScene().Add(fieldForCoverage);
3291
3292   // for SetPlaceholderTextFontWeight coverage.
3293   Property::Map fontStyleWeightMap;
3294   Property::Map fontStyleWeightPropertyMap;
3295   fontStyleWeightPropertyMap.Insert("weight", "bold");
3296   fontStyleWeightMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWeightPropertyMap;
3297   fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWeightMap);
3298
3299   // mPlaceholderFont is created only once, so create a new control for coverage.
3300   fieldForCoverage = TextField::New();
3301   DALI_TEST_CHECK(fieldForCoverage);
3302   application.GetScene().Add(fieldForCoverage);
3303
3304   // for SetPlaceholderTextFontWidth coverage.
3305   Property::Map fontStyleWidthMap;
3306   Property::Map fontStyleWidthPropertyMap;
3307   fontStyleWidthPropertyMap.Insert("width", "expanded");
3308   fontStyleWidthMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleWidthPropertyMap;
3309   fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleWidthMap);
3310
3311   // mPlaceholderFont is created only once, so create a new control for coverage.
3312   fieldForCoverage = TextField::New();
3313   DALI_TEST_CHECK(fieldForCoverage);
3314   application.GetScene().Add(fieldForCoverage);
3315
3316   // for SetPlaceholderTextFontSlant coverage.
3317   Property::Map fontStyleSlantMap;
3318   Property::Map fontStyleSlantPropertyMap;
3319   fontStyleSlantPropertyMap.Insert("slant", "italic");
3320   fontStyleSlantMap[Text::PlaceHolder::Property::FONT_STYLE] = fontStyleSlantPropertyMap;
3321   fieldForCoverage.SetProperty(TextField::Property::PLACEHOLDER, fontStyleSlantMap);
3322
3323   END_TEST;
3324 }
3325
3326 int UtcDaliTextFieldSetPaddingProperty(void)
3327 {
3328   ToolkitTestApplication application;
3329   tet_infoline("UtcDaliTextFieldSetPaddingProperty\n");
3330
3331   TextField field = TextField::New();
3332   DALI_TEST_CHECK( field );
3333   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3334   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3335   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3336   application.GetScene().Add( field );
3337
3338   application.SendNotification();
3339   application.Render();
3340
3341   Vector3 originalSize = field.GetNaturalSize();
3342
3343   field.SetProperty( Toolkit::Control::Property::PADDING, Extents( 10, 10, 10, 10 ) );
3344
3345   application.SendNotification();
3346   application.Render();
3347
3348   DALI_TEST_EQUALS( field.GetProperty<Extents>( Toolkit::Control::Property::PADDING ), Extents( 10, 10, 10, 10 ), TEST_LOCATION );
3349
3350   Vector3 paddingAddedSize = field.GetNaturalSize();
3351
3352   DALI_TEST_EQUALS( originalSize.width + 10 + 10 , paddingAddedSize.width, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
3353
3354   DALI_TEST_EQUALS( originalSize.height + 10 + 10 , paddingAddedSize.height, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
3355
3356   END_TEST;
3357 }
3358
3359 int UtcDaliTextFieldEnableShiftSelectionProperty(void)
3360 {
3361   ToolkitTestApplication application;
3362   tet_infoline("UtcDaliTextFieldEnableShiftSelectionProperty");
3363
3364   TextField field = TextField::New();
3365   DALI_TEST_CHECK( field );
3366   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3367   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3368   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3369   application.GetScene().Add( field );
3370
3371   application.SendNotification();
3372   application.Render();
3373
3374   // The default value of ENABLE_SHIFT_SELECTION is 'true'.
3375   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), true, TEST_LOCATION );
3376
3377   // Check the enable shift selection property
3378   field.SetProperty( DevelTextField::Property::ENABLE_SHIFT_SELECTION, false );
3379   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_SHIFT_SELECTION ), false, TEST_LOCATION );
3380
3381   application.SendNotification();
3382   application.Render();
3383
3384   END_TEST;
3385 }
3386
3387 int UtcDaliTextFieldEnableGrabHandleProperty(void)
3388 {
3389   ToolkitTestApplication application;
3390   tet_infoline("UtcDaliTextFieldEnableGrabHandleProperty");
3391
3392   TextField field = TextField::New();
3393   DALI_TEST_CHECK( field );
3394   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3395   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3396   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3397   application.GetScene().Add( field );
3398
3399   application.SendNotification();
3400   application.Render();
3401
3402   // The default value of ENABLE_GRAB_HANDLE is 'true'.
3403   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE ), true, TEST_LOCATION );
3404
3405   // Check the enable grab handle property
3406   field.SetProperty( DevelTextField::Property::ENABLE_GRAB_HANDLE, false );
3407   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::ENABLE_GRAB_HANDLE ), false, TEST_LOCATION );
3408
3409   application.SendNotification();
3410   application.Render();
3411
3412   END_TEST;
3413 }
3414
3415 int UtcDaliTextFieldMatchSystemLanguageDirectionProperty(void)
3416 {
3417   ToolkitTestApplication application;
3418   tet_infoline("UtcDaliTextFieldMatchSystemLanguageDirectionProperty");
3419
3420   TextField field = TextField::New();
3421   DALI_TEST_CHECK( field );
3422   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3423   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3424   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3425   application.GetScene().Add( field );
3426
3427   application.SendNotification();
3428   application.Render();
3429
3430   // The default value of MATCH_SYSTEM_LANGUAGE_DIRECTION is 'true'.
3431   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), true, TEST_LOCATION );
3432
3433   // Check the match system language direction property
3434   field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, false );
3435   DALI_TEST_EQUALS( field.GetProperty<bool>( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ), false, TEST_LOCATION );
3436
3437   application.SendNotification();
3438   application.Render();
3439
3440   END_TEST;
3441 }
3442
3443 int utcDaliTextFieldLayoutDirectionCoverage(void)
3444 {
3445   ToolkitTestApplication application;
3446   tet_infoline(" utcDaliTextFieldLayoutDirectionCoverage");
3447
3448   // Creates a tap event. After creating a tap event the text field should
3449   // have the focus and add text with key events should be possible.
3450   TextField field = TextField::New();
3451   DALI_TEST_CHECK( field );
3452
3453   application.GetScene().Add( field );
3454
3455   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3456   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3457   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3458
3459   // Avoid a crash when core load gl resources.
3460   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3461
3462   // Render and notify
3463   application.SendNotification();
3464   application.Render();
3465
3466   // init direction for coverage
3467   // Set horizontal alignment END
3468   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END");
3469
3470   // Create a tap event to touch the text field.
3471   TestGenerateTap( application, 150.0f, 25.0f );
3472
3473   // Render and notify
3474   application.SendNotification();
3475   application.Render();
3476
3477   // Set MATCH_SYSTEM_LANGUAGE_DIRECTION to true to use the layout direction.
3478   field.SetProperty( DevelTextField::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION, true );
3479   field.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
3480
3481   // Set horizontal alignment BEGIN
3482   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "BEGIN");
3483
3484   // Create a tap event to touch the text field.
3485   TestGenerateTap( application, 150.0f, 25.0f );
3486
3487   // Render and notify
3488   application.SendNotification();
3489   application.Render();
3490
3491   // Set horizontal alignment CENTER
3492   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER");
3493
3494   // Create a tap event to touch the text field.
3495   TestGenerateTap( application, 150.0f, 25.0f );
3496
3497   // Render and notify
3498   application.SendNotification();
3499   application.Render();
3500
3501   // Set horizontal alignment END
3502   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END");
3503
3504   // Create a tap event to touch the text field.
3505   TestGenerateTap( application, 150.0f, 25.0f );
3506
3507   // Render and notify
3508   application.SendNotification();
3509   application.Render();
3510
3511   // Generate a Esc key event. The text field should lose the focus.
3512   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3513   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3514
3515   // Render and notify
3516   application.SendNotification();
3517   application.Render();
3518
3519   DALI_TEST_EQUALS( false, field.HasKeyInputFocus(), TEST_LOCATION );
3520
3521   END_TEST;
3522 }
3523
3524 int UtcDaliTextFieldGetInputMethodContext(void)
3525 {
3526   ToolkitTestApplication application;
3527   tet_infoline("UtcDaliTextFieldGetInputMethodContext");
3528
3529   TextField field = TextField::New();
3530   DALI_TEST_CHECK( DevelTextField::GetInputMethodContext( field ) );
3531
3532   END_TEST;
3533 }
3534
3535 int UtcDaliTextFieldSelectWholeText(void)
3536 {
3537   ToolkitTestApplication application;
3538   tet_infoline(" UtcDaliTextFieldSelectWholeText ");
3539
3540   TextField textField = TextField::New();
3541
3542   application.GetScene().Add( textField );
3543
3544   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3545   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3546   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3547
3548   // Avoid a crash when core load gl resources.
3549   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3550
3551   application.SendNotification();
3552   application.Render();
3553
3554   DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION );
3555
3556   DevelTextField::SelectWholeText( textField );
3557
3558   application.SendNotification();
3559   application.Render();
3560
3561   // Nothing should have been selected. The number of children is still 1
3562   DALI_TEST_EQUALS( 1u, textField.GetChildCount(), TEST_LOCATION );
3563
3564   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
3565
3566   application.SendNotification();
3567   application.Render();
3568
3569   DevelTextField::SelectWholeText( textField );
3570
3571   application.SendNotification();
3572   application.Render();
3573
3574   // Even if resize, selection should remain.
3575   textField.SetProperty( Actor::Property::SIZE, Vector2( 150.f, 50.f ) );
3576
3577   application.SendNotification();
3578   application.Render();
3579
3580   // Should be 2 children, the stencil and the layer
3581   DALI_TEST_EQUALS( 2u, textField.GetChildCount(), TEST_LOCATION );
3582
3583   // The offscreen root actor should have two actors: the renderer and the highlight actor.
3584   Actor stencil = textField.GetChildAt( 0u );
3585
3586   // The highlight actor is drawn first, so is the first actor in the list
3587   Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u );
3588   DALI_TEST_CHECK( highlight );
3589
3590   END_TEST;
3591 }
3592
3593 int UtcDaliTextFieldSelectText(void)
3594 {
3595   ToolkitTestApplication application;
3596   tet_infoline(" UtcDaliTextFieldSelectText ");
3597
3598   TextField textField = TextField::New();
3599
3600   application.GetScene().Add( textField );
3601
3602   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3603   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3604   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3605
3606   // Avoid a crash when core load gl resources.
3607   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3608
3609   application.SendNotification();
3610   application.Render();
3611
3612   DevelTextField::SelectText( textField, 0, 5 );
3613
3614   application.SendNotification();
3615   application.Render();
3616
3617   // Nothing is selected
3618   std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3619   DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
3620
3621   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
3622
3623   application.SendNotification();
3624   application.Render();
3625
3626   // Hello is selected
3627   DevelTextField::SelectText( textField, 0, 5 );
3628
3629   application.SendNotification();
3630   application.Render();
3631
3632   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3633   DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION );
3634
3635   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 0, TEST_LOCATION );
3636   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 5, TEST_LOCATION );
3637
3638   // world is selected
3639   DevelTextField::SelectText( textField, 6, 11 );
3640
3641   application.SendNotification();
3642   application.Render();
3643
3644   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3645   DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION );
3646
3647   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 6, TEST_LOCATION );
3648   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 11, TEST_LOCATION );
3649
3650   END_TEST;
3651 }
3652
3653 int UtcDaliTextFieldSelectNone(void)
3654 {
3655   ToolkitTestApplication application;
3656   tet_infoline(" UtcDaliTextFieldSelectWholeText ");
3657
3658   TextField textField = TextField::New();
3659
3660   application.GetScene().Add( textField );
3661
3662   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3663   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3664   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3665
3666   // Avoid a crash when core load gl resources.
3667   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3668
3669   application.SendNotification();
3670   application.Render();
3671
3672   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
3673
3674   application.SendNotification();
3675   application.Render();
3676
3677   // Nothing is selected
3678   std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3679   DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
3680
3681   DevelTextField::SelectWholeText( textField );
3682
3683   application.SendNotification();
3684   application.Render();
3685
3686   // whole text is selected
3687   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3688   DALI_TEST_EQUALS( "Hello world", selectedText, TEST_LOCATION );
3689
3690   DevelTextField::SelectNone( textField );
3691
3692   application.SendNotification();
3693   application.Render();
3694
3695   // Nothing is selected
3696   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3697   DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION );
3698
3699   END_TEST;
3700 }
3701
3702 int UtcDaliTextFieldSelectRange(void)
3703 {
3704   ToolkitTestApplication application;
3705   tet_infoline(" UtcDaliTextFieldSelectRange ");
3706
3707   TextField textField = TextField::New();
3708
3709   application.GetScene().Add( textField );
3710
3711   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3712   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3713   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3714
3715   // Avoid a crash when core load gl resources.
3716   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3717
3718   application.SendNotification();
3719   application.Render();
3720
3721   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
3722
3723   application.SendNotification();
3724   application.Render();
3725
3726   textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_START , 0);
3727   textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_END , 5);
3728
3729   // Hello is selected
3730   std::string selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3731   DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION );
3732
3733   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 0, TEST_LOCATION );
3734   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 5, TEST_LOCATION );
3735
3736   textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_START , 6);
3737   textField.SetProperty( DevelTextField::Property::SELECTED_TEXT_END , 11);
3738
3739   // world is selected
3740   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
3741   DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION );
3742
3743   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 6, TEST_LOCATION );
3744   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 11, TEST_LOCATION );
3745
3746   END_TEST;
3747 }
3748
3749 int UtcDaliTextFieldEnableEditing(void)
3750 {
3751   ToolkitTestApplication application;
3752   tet_infoline(" UtcDaliTextFieldEnableEditing ");
3753
3754   TextField textField = TextField::New();
3755
3756   application.GetScene().Add( textField );
3757
3758   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3759   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3760   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3761
3762   // Avoid a crash when core load gl resources.
3763   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3764
3765   application.SendNotification();
3766   application.Render();
3767
3768   textField.SetKeyInputFocus();
3769   textField.SetProperty( DevelTextField::Property::ENABLE_EDITING, false );
3770   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3771
3772   // Render and notify
3773   application.SendNotification();
3774   application.Render();
3775
3776   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "", TEST_LOCATION );
3777   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get<bool>(), false, TEST_LOCATION );
3778
3779
3780   textField.SetKeyInputFocus();
3781   textField.SetProperty( DevelTextField::Property::ENABLE_EDITING, true );
3782   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3783
3784   // Render and notify
3785   application.SendNotification();
3786   application.Render();
3787
3788   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "D", TEST_LOCATION );
3789   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::ENABLE_EDITING ).Get<bool>(), true, TEST_LOCATION );
3790
3791   END_TEST;
3792 }
3793
3794 int UtcDaliToolkitTextFieldFontSizeScale(void)
3795 {
3796   ToolkitTestApplication application;
3797   tet_infoline(" UtcDaliToolkitTextFieldFontSizeScale");
3798
3799   TextField textField = TextField::New();
3800   textField.SetProperty( TextField::Property::POINT_SIZE, 30.f );
3801   textField.SetProperty( TextField::Property::TEXT, "Test" );
3802   Vector3 nonScaledSize = textField.GetNaturalSize();
3803
3804   TextField textFieldScaled = TextField::New();
3805   textFieldScaled.SetProperty( TextField::Property::POINT_SIZE, 15.f );
3806   textFieldScaled.SetProperty( Toolkit::DevelTextField::Property::FONT_SIZE_SCALE, 2.f );
3807   textFieldScaled.SetProperty( TextField::Property::TEXT, "Test" );
3808   Vector3 scaledSize = textFieldScaled.GetNaturalSize();
3809
3810   DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION );
3811
3812   textField.SetProperty( TextField::Property::PIXEL_SIZE, 30.f );
3813   textField.SetProperty( TextField::Property::TEXT, "Test" );
3814   nonScaledSize = textField.GetNaturalSize();
3815
3816   textFieldScaled.SetProperty( TextField::Property::PIXEL_SIZE, 15.f );
3817   textFieldScaled.SetProperty( Toolkit::DevelTextField::Property::FONT_SIZE_SCALE, 2.f );
3818   textFieldScaled.SetProperty( TextField::Property::TEXT, "Test" );
3819   scaledSize = textFieldScaled.GetNaturalSize();
3820
3821   DALI_TEST_EQUALS( nonScaledSize, scaledSize, TEST_LOCATION );
3822
3823   END_TEST;
3824 }
3825
3826 int UtcDaliTextFieldPrimaryCursorPosition(void)
3827 {
3828   ToolkitTestApplication application;
3829   tet_infoline(" UtcDaliTextFieldPrimaryCursorPosition ");
3830
3831   TextField textField = TextField::New();
3832
3833   application.GetScene().Add( textField );
3834
3835   textField.SetProperty( TextField::Property::TEXT, "ABCEF");
3836   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
3837   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
3838   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
3839
3840   // Avoid a crash when core load gl resources.
3841   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
3842
3843   textField.SetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
3844   application.SendNotification();
3845   application.Render();
3846   textField.SetKeyInputFocus();
3847
3848   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3849
3850   // Render and notify
3851   application.SendNotification();
3852   application.Render();
3853
3854   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "ABCDEF", TEST_LOCATION );
3855   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION ).Get<int>(), 4, TEST_LOCATION );
3856
3857   END_TEST;
3858 }
3859
3860 // test max length when set after setting long text
3861 int utcDaliTextFieldMaxCharactersReachedAfterSetText(void)
3862 {
3863   ToolkitTestApplication application;
3864   tet_infoline(" utcDaliTextFieldMaxCharactersReachedAfterSetText");
3865   TextField field = TextField::New();
3866   DALI_TEST_CHECK( field );
3867
3868   application.GetScene().Add( field );
3869
3870   field.SetProperty(TextField::Property::TEXT, "123456789");
3871
3872   const int maxNumberOfCharacters = 3;
3873   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
3874
3875   field.SetKeyInputFocus();
3876
3877   // connect to the text max lengh reached signal.
3878   ConnectionTracker* testTracker = new ConnectionTracker();
3879   bool maxLengthReachedSignal = false;
3880   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
3881
3882   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3883   application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::DOWN, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
3884
3885   DALI_TEST_CHECK( maxLengthReachedSignal );
3886
3887   DALI_TEST_EQUALS( field.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "123456789", TEST_LOCATION );
3888
3889   END_TEST;
3890 }
3891
3892
3893
3894 int UtcDaliTextFieldAtlasLimitationIsEnabledForLargeFontPointSize(void)
3895 {
3896   ToolkitTestApplication application;
3897   tet_infoline(" UtcDaliTextFieldAtlasLimitationIsEnabledForLargeFontPointSize ");
3898
3899   // +2: First one to handle the equal case. Second one to handle odd to even case of GetNaturalSize
3900   const uint32_t lessThanWidth = TextAbstraction::FontClient::MAX_TEXT_ATLAS_WIDTH - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2;
3901   const uint32_t lessThanHeight = TextAbstraction::FontClient::MAX_TEXT_ATLAS_HEIGHT - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2;
3902
3903   // Create a text field
3904   TextField textField = TextField::New();
3905
3906   //Set size to avoid automatic eliding
3907   textField.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
3908   //Set very large font-size using point-size
3909   textField.SetProperty( TextField::Property::POINT_SIZE, 1000) ;
3910   //Specify font-family
3911   textField.SetProperty( TextField::Property::FONT_FAMILY, "DejaVu Sans");
3912   //Set text to check if appear or not
3913   textField.SetProperty( TextField::Property::TEXT, "A");
3914
3915   application.GetScene().Add( textField );
3916
3917   application.SendNotification();
3918   application.Render();
3919   //Use GetNaturalSize to verify that size of block does not exceed Atlas size
3920   Vector3 naturalSize = textField.GetNaturalSize();
3921
3922   DALI_TEST_GREATER( lessThanWidth, static_cast<uint32_t>(naturalSize.width), TEST_LOCATION );
3923   DALI_TEST_GREATER( lessThanHeight, static_cast<uint32_t>(naturalSize.height), TEST_LOCATION );
3924
3925   END_TEST;
3926 }
3927
3928 int UtcDaliTextFieldAtlasLimitationIsEnabledPerformanceCases(void)
3929 {
3930   ToolkitTestApplication application;
3931   tet_infoline(" UtcDaliTextFieldAtlasLimitationIsEnabledPerformanceCases ");
3932
3933   // +2: First one to handle the equal case. Second one to handle odd to even case of GetNaturalSize
3934   const uint32_t lessThanWidth = TextAbstraction::FontClient::MAX_TEXT_ATLAS_WIDTH - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2;
3935   const uint32_t lessThanHeight = TextAbstraction::FontClient::MAX_TEXT_ATLAS_HEIGHT - TextAbstraction::FontClient::PADDING_TEXT_ATLAS_BLOCK + 2;
3936
3937   Vector3 naturalSize; //Use GetNaturalSize to verify that size of block does not exceed Atlas size
3938   // Create a text editor
3939   TextField textField = TextField::New();
3940
3941   //Set size to avoid automatic eliding
3942   textField.SetProperty( Actor::Property::SIZE, Vector2(1025, 1025));
3943   textField.SetProperty( TextField::Property::FONT_FAMILY, "DejaVu Sans");
3944   textField.SetProperty( TextField::Property::TEXT, "A");
3945
3946   const int numberOfCases = 6;
3947   int arrayCases[numberOfCases] = {323, 326, 330, 600, 1630, 2500};
3948
3949   for (int index=0; index < numberOfCases; index++)
3950   {
3951     tet_printf(" UtcDaliTextFieldAtlasLimitationIsEnabledPerformanceCases point-size= %d \n", arrayCases[index]);
3952     textField.SetProperty( TextField::Property::POINT_SIZE, arrayCases[index]) ;
3953     application.GetScene().Add( textField );
3954     application.SendNotification();
3955     application.Render();
3956     naturalSize = textField.GetNaturalSize();
3957     DALI_TEST_GREATER( lessThanWidth, static_cast<uint32_t>(naturalSize.width), TEST_LOCATION );
3958     DALI_TEST_GREATER( lessThanHeight, static_cast<uint32_t>(naturalSize.height), TEST_LOCATION );
3959
3960   }
3961
3962   END_TEST;
3963 }
3964
3965 int UtcDaliToolkitTextFieldEllipsisPositionProperty(void)
3966 {
3967   ToolkitTestApplication application;
3968   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty ");
3969   TextField textField = TextField::New();
3970
3971   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty - Default is END");
3972   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION );
3973
3974   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty - Change to START");
3975   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::START);
3976   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION );
3977
3978   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty - Change to MIDDLE");
3979   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::MIDDLE);
3980   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION );
3981
3982   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty - Change to END");
3983   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::END);
3984   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION );
3985
3986   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty - Change to START using integer");
3987   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, 1);
3988   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION );
3989
3990   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty - Change to MIDDLE using integer");
3991   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, 2);
3992   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION );
3993
3994   tet_infoline(" UtcDaliToolkitTextFieldEllipsisPositionProperty - Change to END using integer");
3995   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, 0);
3996   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION );
3997
3998   tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to START using string - uppercase");
3999   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, "START");
4000   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION );
4001
4002   tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to MIDDLE using string - uppercase");
4003   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, "MIDDLE");
4004   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION );
4005
4006   tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to END using string - uppercase");
4007   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, "END");
4008   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION );
4009
4010   tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to START using string - lowercase");
4011   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, "start");
4012   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::START ), TEST_LOCATION );
4013
4014   tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to MIDDLE using string - lowercase");
4015   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, "middle");
4016   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::MIDDLE ), TEST_LOCATION );
4017
4018   tet_infoline(" UtcDaliToolkitTextlabelEllipsisPositionProperty - Change to END using string - lowercase");
4019   textField.SetProperty(DevelTextField::Property::ELLIPSIS_POSITION, "end");
4020   DALI_TEST_EQUALS( textField.GetProperty< int >( DevelTextField::Property::ELLIPSIS_POSITION ), static_cast< int >( Toolkit::DevelText::EllipsisPosition::END ), TEST_LOCATION );
4021
4022   END_TEST;
4023 }
4024
4025 int UtcDaliTextFieldCopyText(void)
4026 {
4027   ToolkitTestApplication application;
4028   tet_infoline(" UtcDaliTextFieldCopyText ");
4029
4030   TextField textField = TextField::New();
4031
4032   std::string selectedText = "";
4033   std::string copiedText = "";
4034
4035   application.GetScene().Add( textField );
4036
4037   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
4038   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4039   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4040
4041   // Avoid a crash when core load gl resources.
4042   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4043
4044   application.SendNotification();
4045   application.Render();
4046
4047   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
4048
4049   application.SendNotification();
4050   application.Render();
4051
4052   // Hello is selected
4053   DevelTextField::SelectText( textField, 0, 5 );
4054
4055   application.SendNotification();
4056   application.Render();
4057
4058   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
4059   DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION );
4060
4061   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 0, TEST_LOCATION );
4062   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 5, TEST_LOCATION );
4063
4064   // Hello is copied
4065   copiedText = DevelTextField::CopyText( textField );
4066   DALI_TEST_EQUALS( "Hello", copiedText, TEST_LOCATION );
4067
4068   // world is selected
4069   DevelTextField::SelectText( textField, 6, 11 );
4070
4071   application.SendNotification();
4072   application.Render();
4073
4074   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
4075   DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION );
4076
4077   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 6, TEST_LOCATION );
4078   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 11, TEST_LOCATION );
4079
4080   // world is copied
4081   copiedText = DevelTextField::CopyText( textField );
4082   DALI_TEST_EQUALS( "world", copiedText, TEST_LOCATION );
4083
4084   // "lo wo" is selected
4085   DevelTextField::SelectText( textField, 3, 8 );
4086
4087   application.SendNotification();
4088   application.Render();
4089
4090   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
4091   DALI_TEST_EQUALS( "lo wo", selectedText, TEST_LOCATION );
4092
4093   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 3, TEST_LOCATION );
4094   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 8, TEST_LOCATION );
4095
4096   // "lo wo" is copied
4097   copiedText = DevelTextField::CopyText( textField );
4098   DALI_TEST_EQUALS( "lo wo", copiedText, TEST_LOCATION );
4099
4100   END_TEST;
4101 }
4102
4103 int UtcDaliTextFieldCutText(void)
4104 {
4105   ToolkitTestApplication application;
4106   tet_infoline(" UtcDaliTextFieldCutText ");
4107
4108   TextField textField = TextField::New();
4109
4110   std::string selectedText = "";
4111
4112   application.GetScene().Add( textField );
4113
4114   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
4115   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4116   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4117
4118   // Avoid a crash when core load gl resources.
4119   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4120
4121   application.SendNotification();
4122   application.Render();
4123
4124   textField.SetProperty( TextField::Property::TEXT, "Hello world" );
4125
4126   application.SendNotification();
4127   application.Render();
4128
4129   // Hello is selected
4130   DevelTextField::SelectText( textField, 0, 5 );
4131
4132   application.SendNotification();
4133   application.Render();
4134
4135   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
4136   DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION );
4137
4138   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 0, TEST_LOCATION );
4139   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 5, TEST_LOCATION );
4140
4141   // Hello is cut
4142   DALI_TEST_EQUALS( "Hello", DevelTextField::CutText( textField ), TEST_LOCATION );
4143
4144   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), " world", TEST_LOCATION );
4145
4146   // " w" is selected
4147   DevelTextField::SelectText( textField, 0, 2 );
4148
4149   application.SendNotification();
4150   application.Render();
4151
4152   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
4153   DALI_TEST_EQUALS( " w", selectedText, TEST_LOCATION );
4154
4155   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 0, TEST_LOCATION );
4156   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 2, TEST_LOCATION );
4157
4158   // " w" is cut
4159   DALI_TEST_EQUALS( " w", DevelTextField::CutText( textField ), TEST_LOCATION );
4160
4161   application.SendNotification();
4162   application.Render();
4163
4164   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "orld", TEST_LOCATION );
4165
4166   // Test Cut from the middle
4167
4168   // "rl" is selected
4169   DevelTextField::SelectText( textField, 1, 3 );
4170
4171   application.SendNotification();
4172   application.Render();
4173
4174   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
4175   DALI_TEST_EQUALS( "rl", selectedText, TEST_LOCATION );
4176
4177   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 1, TEST_LOCATION );
4178   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 3, TEST_LOCATION );
4179
4180   // "rl" is cut
4181   DALI_TEST_EQUALS( "rl", DevelTextField::CutText( textField ), TEST_LOCATION );
4182
4183   application.SendNotification();
4184   application.Render();
4185
4186   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "od", TEST_LOCATION );
4187
4188   // Test Cut from the end
4189
4190   // "d" is selected
4191   DevelTextField::SelectText( textField, 1, 2 );
4192
4193   application.SendNotification();
4194   application.Render();
4195
4196   selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get<std::string>();
4197   DALI_TEST_EQUALS( "d", selectedText, TEST_LOCATION );
4198
4199   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get<int>(), 1, TEST_LOCATION );
4200   DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get<int>(), 2, TEST_LOCATION );
4201
4202   // "d" is cut
4203   DALI_TEST_EQUALS( "d", DevelTextField::CutText( textField ), TEST_LOCATION );
4204
4205   application.SendNotification();
4206   application.Render();
4207
4208   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "o", TEST_LOCATION );
4209
4210   END_TEST;
4211 }
4212
4213 int UtcDaliTextFieldPasteText(void)
4214 {
4215   ToolkitTestApplication application;
4216   tet_infoline(" UtcDaliTextFieldPasteText ");
4217
4218   TextField textField = TextField::New();
4219
4220   application.GetScene().Add( textField );
4221
4222   std::string cutText = "";
4223   std::string copiedText = "";
4224
4225   textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
4226   textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4227   textField.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4228
4229   // Avoid a crash when core load gl resources.
4230   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4231
4232   application.SendNotification();
4233   application.Render();
4234
4235   textField.SetProperty( TextField::Property::TEXT, "Hello World" );
4236
4237   application.SendNotification();
4238   application.Render();
4239
4240   // Tap on the text editor
4241   TestGenerateTap( application, 3.0f, 25.0f );
4242
4243   // Render and notify
4244   application.SendNotification();
4245   application.Render();
4246
4247   // Select some text in the right of the current cursor position
4248   DevelTextField::SelectText( textField, 0, 3 );
4249
4250   // Render and notify
4251   application.SendNotification();
4252   application.Render();
4253
4254   // Cut the selected text
4255   cutText = DevelTextField::CutText(textField);
4256
4257   // Render and notify
4258   application.SendNotification();
4259   application.Render();
4260
4261   DALI_TEST_EQUALS( "Hel", cutText, TEST_LOCATION );
4262   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "lo World", TEST_LOCATION );
4263
4264   DevelTextField::SelectText( textField, 0, 3 );
4265
4266   // Render and notify
4267   application.SendNotification();
4268   application.Render();
4269
4270   // Copy the selected text
4271   copiedText = DevelTextField::CopyText(textField);
4272
4273   // Render and notify
4274   application.SendNotification();
4275   application.Render();
4276
4277   DALI_TEST_EQUALS( "lo ", copiedText, TEST_LOCATION );
4278   DALI_TEST_EQUALS( "lo World", textField.GetProperty<std::string>( TextField::Property::TEXT ), TEST_LOCATION );
4279
4280   // Move the cursor to the end of the line
4281   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4282   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4283   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4284   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4285   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4286   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4287   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4288   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4289
4290   // Render and notify
4291   application.SendNotification();
4292   application.Render();
4293
4294   // Paste the selected text at the current cursor position
4295   DevelTextField::PasteText(textField);
4296
4297   // Render and notify
4298   application.SendNotification();
4299   application.Render();
4300
4301   DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get<std::string>(), "lo Worldlo ", TEST_LOCATION );
4302
4303   END_TEST;
4304 }
4305 int utcDaliTextFieldCursorPositionChangedSignal(void)
4306 {
4307   ToolkitTestApplication application;
4308   tet_infoline(" utcDaliTextFieldCursorPositionChangedSignal");
4309
4310   TextField field = TextField::New();
4311   DALI_TEST_CHECK( field );
4312
4313   application.GetScene().Add( field );
4314
4315   // connect to the selection changed signal.
4316   ConnectionTracker* testTracker = new ConnectionTracker();
4317   DevelTextField::CursorPositionChangedSignal(field).Connect(&TestCursorPositionChangedCallback);
4318   bool cursorPositionChangedSignal = false;
4319   field.ConnectSignal( testTracker, "cursorPositionChanged",   CallbackFunctor(&cursorPositionChangedSignal) );
4320
4321   field.SetProperty( TextField::Property::TEXT, "Hello world Hello world" );
4322   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
4323   field.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) );
4324   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4325   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4326
4327   // Avoid a crash when core load gl resources.
4328   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4329
4330   // Render and notify
4331   application.SendNotification();
4332   application.Render();
4333
4334   field.SetKeyInputFocus();
4335
4336   // Tap on the text field
4337   TestGenerateTap( application, 3.0f, 25.0f );
4338
4339   // Render and notify
4340   application.SendNotification();
4341   application.Render();
4342
4343   DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
4344   DALI_TEST_EQUALS(oldCursorPos, 23, TEST_LOCATION);
4345
4346   gCursorPositionChangedCallbackCalled = false;
4347
4348   // Move to left.
4349   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4350
4351   // Render and notify
4352   application.SendNotification();
4353   application.Render();
4354
4355   DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
4356   DALI_TEST_EQUALS(oldCursorPos, 17, TEST_LOCATION);
4357
4358   gCursorPositionChangedCallbackCalled = false;
4359
4360   // Insert D
4361   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4362
4363   // Render and notify
4364   application.SendNotification();
4365   application.Render();
4366
4367   DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
4368   DALI_TEST_EQUALS(oldCursorPos, 16, TEST_LOCATION);
4369
4370   gCursorPositionChangedCallbackCalled = false;
4371
4372   //delete one character
4373   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4374
4375   // Render and notify
4376   application.SendNotification();
4377   application.Render();
4378
4379   DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
4380   DALI_TEST_EQUALS(oldCursorPos, 17, TEST_LOCATION);
4381
4382   gCursorPositionChangedCallbackCalled = false;
4383
4384   field.SetProperty( TextField::Property::TEXT, "Hello" );
4385
4386   // Render and notify
4387   application.SendNotification();
4388   application.Render();
4389
4390   DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
4391   DALI_TEST_EQUALS(oldCursorPos, 16, TEST_LOCATION);
4392
4393   gCursorPositionChangedCallbackCalled = false;
4394
4395   field.SetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
4396
4397   // Render and notify
4398   application.SendNotification();
4399   application.Render();
4400
4401   DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled);
4402   DALI_TEST_EQUALS(oldCursorPos, 5, TEST_LOCATION);
4403
4404   END_TEST;
4405 }
4406
4407 int utcDaliTextFieldGeometryEllipsisStart(void)
4408 {
4409   ToolkitTestApplication application;
4410   tet_infoline(" utcDaliTextFieldGeometryEllipsisStart");
4411
4412   TextField field = TextField::New();
4413   DALI_TEST_CHECK( field );
4414
4415   application.GetScene().Add( field );
4416
4417   field.SetProperty( TextField::Property::POINT_SIZE, 7.f );
4418   field.SetProperty( Actor::Property::SIZE, Vector2( 250.f, 50.f ) );
4419   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4420   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4421   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
4422   field.SetProperty( DevelTextField::Property::ELLIPSIS, true );
4423   field.SetProperty( DevelTextField::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::START );
4424   field.SetProperty( TextField::Property::TEXT, "Hello World" );
4425
4426   // Avoid a crash when core load gl resources.
4427   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4428
4429   // Render and notify
4430   application.SendNotification();
4431   application.Render();
4432
4433   unsigned int expectedCount = 1;
4434   unsigned int startIndex = 0;
4435   unsigned int endIndex = 10;
4436
4437   Vector<Vector2> positionsList = DevelTextField::GetTextPosition(field, startIndex, endIndex);
4438   Vector<Vector2> sizeList = DevelTextField::GetTextSize(field, startIndex, endIndex);
4439
4440   DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION);
4441   DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION);
4442
4443   Vector<Vector2> expectedSizes;
4444   Vector<Vector2> expectedPositions;
4445
4446   expectedPositions.PushBack(Vector2(14, 0));
4447   expectedSizes.PushBack(Vector2(106, 25));
4448
4449   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
4450
4451   END_TEST;
4452 }
4453
4454 int utcDaliTextFieldGeometryEllipsisEnd(void)
4455 {
4456   ToolkitTestApplication application;
4457   tet_infoline(" utcDaliTextFieldGeometryEllipsisEnd");
4458
4459   TextField field = TextField::New();
4460   DALI_TEST_CHECK( field );
4461
4462   application.GetScene().Add( field );
4463
4464   field.SetProperty( TextField::Property::POINT_SIZE, 7.f );
4465   field.SetProperty( Actor::Property::SIZE, Vector2( 250.f, 50.f ) );
4466   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4467   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4468   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
4469   field.SetProperty( DevelTextField::Property::ELLIPSIS, true );
4470   field.SetProperty( DevelTextField::Property::ELLIPSIS_POSITION, DevelText::EllipsisPosition::END );
4471   field.SetProperty( TextField::Property::TEXT, "Hello World" );
4472
4473   // Avoid a crash when core load gl resources.
4474   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4475
4476   // Render and notify
4477   application.SendNotification();
4478   application.Render();
4479
4480   unsigned int expectedCount = 1;
4481   unsigned int startIndex = 0;
4482   unsigned int endIndex = 10;
4483
4484   Vector<Vector2> positionsList = DevelTextField::GetTextPosition(field, startIndex, endIndex);
4485   Vector<Vector2> sizeList = DevelTextField::GetTextSize(field, startIndex, endIndex);
4486
4487   DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION);
4488   DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION);
4489
4490   Vector<Vector2> expectedSizes;
4491   Vector<Vector2> expectedPositions;
4492
4493   expectedPositions.PushBack(Vector2(-2, 0));
4494   expectedSizes.PushBack(Vector2(122, 25));
4495
4496   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
4497
4498   END_TEST;
4499 }
4500
4501 int utcDaliTextFieldGeometryRTL(void)
4502 {
4503   ToolkitTestApplication application;
4504   tet_infoline(" utcDaliTextFieldGeometryRTL");
4505
4506   TextField field = TextField::New();
4507   DALI_TEST_CHECK( field );
4508
4509   application.GetScene().Add( field );
4510
4511   field.SetProperty( TextField::Property::POINT_SIZE, 7.f );
4512   field.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) );
4513   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4514   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4515   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
4516   field.SetProperty( TextField::Property::TEXT, "السطر الاخير" );
4517
4518   // Avoid a crash when core load gl resources.
4519   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4520
4521   // Render and notify
4522   application.SendNotification();
4523   application.Render();
4524
4525   unsigned int expectedCount = 1;
4526   unsigned int startIndex = 1;
4527   unsigned int endIndex = 7;
4528
4529   Vector<Vector2> positionsList = DevelTextField::GetTextPosition(field, startIndex, endIndex);
4530   Vector<Vector2> sizeList = DevelTextField::GetTextSize(field, startIndex, endIndex);
4531
4532   DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION);
4533   DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION);
4534
4535   Vector<Vector2> expectedSizes;
4536   Vector<Vector2> expectedPositions;
4537
4538   expectedPositions.PushBack(Vector2(38, 0));
4539   expectedSizes.PushBack(Vector2(73, 25));
4540
4541   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
4542
4543   END_TEST;
4544 }
4545
4546 int utcDaliTextFieldGeometryGlyphMiddle(void)
4547 {
4548   ToolkitTestApplication application;
4549   tet_infoline(" utcDaliTextFieldGeometryGlyphMiddle");
4550
4551   TextField field = TextField::New();
4552   DALI_TEST_CHECK( field );
4553
4554   application.GetScene().Add( field );
4555
4556   field.SetProperty( TextField::Property::POINT_SIZE, 7.f );
4557   field.SetProperty( Actor::Property::SIZE, Vector2( 150.f, 200.f ) );
4558   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4559   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4560   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
4561   field.SetProperty( TextField::Property::TEXT, "لا تحتوي على لا" );
4562
4563   // Avoid a crash when core load gl resources.
4564   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4565
4566   // Render and notify
4567   application.SendNotification();
4568   application.Render();
4569
4570   unsigned int expectedCount = 1;
4571   unsigned int startIndex = 1;
4572   unsigned int endIndex = 13;
4573
4574   Vector<Vector2> positionsList = DevelTextField::GetTextPosition(field, startIndex, endIndex);
4575   Vector<Vector2> sizeList = DevelTextField::GetTextSize(field, startIndex, endIndex);
4576
4577   DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION);
4578   DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION);
4579
4580   Vector<Vector2> expectedSizes;
4581   Vector<Vector2> expectedPositions;
4582
4583   expectedPositions.PushBack(Vector2(6, 0));
4584   expectedSizes.PushBack(Vector2(124, 25));
4585
4586   TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes);
4587
4588   END_TEST;
4589 }
4590
4591 int utcDaliTextFieldSelectionClearedSignal(void)
4592 {
4593   ToolkitTestApplication application;
4594   tet_infoline(" utcDaliTextFieldSelectionClearedSignal");
4595
4596   TextField field = TextField::New();
4597   DALI_TEST_CHECK( field );
4598
4599   application.GetScene().Add( field );
4600
4601   // connect to the selection changed signal.
4602   ConnectionTracker* testTracker = new ConnectionTracker();
4603   DevelTextField::SelectionClearedSignal(field).Connect(&TestSelectionClearedCallback);
4604   bool selectionClearedSignal = false;
4605   field.ConnectSignal( testTracker, "selectionCleared",   CallbackFunctor(&selectionClearedSignal) );
4606
4607   field.SetProperty( TextField::Property::TEXT, "Hello\nworld\nHello world" );
4608   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
4609   field.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) );
4610   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4611   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4612
4613   // Avoid a crash when core load gl resources.
4614   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4615
4616   // Render and notify
4617   application.SendNotification();
4618   application.Render();
4619
4620   // Tap on the text editor
4621   TestGenerateTap( application, 3.0f, 25.0f );
4622
4623   // Render and notify
4624   application.SendNotification();
4625   application.Render();
4626
4627   // Move to second line of the text & Select some text in the right of the current cursor position
4628   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); 
4629   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4630
4631   // remove selection
4632   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4633
4634   // Render and notify
4635   application.SendNotification();
4636   application.Render();
4637
4638   DALI_TEST_CHECK(gSelectionClearedCallbackCalled);
4639
4640   // Render and notify
4641   application.SendNotification();
4642   application.Render();
4643
4644   // Tap on the text editor
4645   TestGenerateTap( application, 3.0f, 25.0f );
4646
4647   // Render and notify
4648   application.SendNotification();
4649   application.Render();
4650
4651   gSelectionClearedCallbackCalled = false;
4652
4653   // Move to second line of the text & select.
4654   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4655   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4656
4657   //remove selection
4658   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4659
4660   // Render and notify
4661   application.SendNotification();
4662   application.Render();
4663
4664   DALI_TEST_CHECK(gSelectionClearedCallbackCalled);
4665
4666   gSelectionClearedCallbackCalled = false;
4667
4668   // Render and notify
4669   application.SendNotification();
4670   application.Render();
4671
4672   // Move to second line of the text & select.
4673   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4674   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4675
4676   // replace D with selected text
4677   application.ProcessEvent( GenerateKey( "D", "", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::DOWN, "D", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4678
4679   // Render and notify
4680   application.SendNotification();
4681   application.Render();
4682
4683   DALI_TEST_CHECK(gSelectionClearedCallbackCalled);
4684
4685   gSelectionClearedCallbackCalled = false;
4686
4687   // Render and notify
4688   application.SendNotification();
4689   application.Render();
4690
4691   DevelTextField::SelectText( field ,1, 3 );
4692
4693   // Render and notify
4694   application.SendNotification();
4695   application.Render();
4696
4697   field.SetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
4698
4699   // Render and notify
4700   application.SendNotification();
4701   application.Render();
4702
4703   DALI_TEST_CHECK(gSelectionClearedCallbackCalled);
4704
4705   gSelectionClearedCallbackCalled = false;
4706
4707   DevelTextField::SelectText( field ,1, 3 );
4708
4709   // Render and notify
4710   application.SendNotification();
4711   application.Render();
4712
4713   // select none
4714   DevelTextField::SelectNone(field);
4715
4716   // Render and notify
4717   application.SendNotification();
4718   application.Render();
4719
4720   DALI_TEST_CHECK(gSelectionClearedCallbackCalled);
4721
4722   END_TEST;
4723 }
4724
4725 int utcDaliTextFieldSelectionChangedSignal(void)
4726 {
4727   ToolkitTestApplication application;
4728   tet_infoline(" utcDaliTextFieldSelectionChangedSignal");
4729
4730   TextField field = TextField::New();
4731   DALI_TEST_CHECK( field );
4732
4733   application.GetScene().Add( field );
4734
4735   // connect to the selection changed signal.
4736   ConnectionTracker* testTracker = new ConnectionTracker();
4737   DevelTextField::SelectionChangedSignal(field).Connect(&TestSelectionChangedCallback);
4738   bool selectionChangedSignal = false;
4739   field.ConnectSignal( testTracker, "selectionChanged",   CallbackFunctor(&selectionChangedSignal) );
4740
4741   field.SetProperty( TextField::Property::TEXT, "Hello world Hello world" );
4742   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
4743   field.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) );
4744   field.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
4745   field.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
4746
4747   // Avoid a crash when core load gl resources.
4748   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
4749
4750   // Render and notify
4751   application.SendNotification();
4752   application.Render();
4753
4754   // Tap on the text field
4755   TestGenerateTap( application, 3.0f, 25.0f );
4756
4757   // Render and notify
4758   application.SendNotification();
4759   application.Render();
4760
4761   // Select some text in the right of the current cursor position
4762   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_SHIFT_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4763   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4764
4765   // Render and notify
4766   application.SendNotification();
4767   application.Render();
4768
4769   DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
4770   DALI_TEST_EQUALS(oldSelectionStart, oldSelectionEnd, TEST_LOCATION);
4771
4772   gSelectionChangedCallbackCalled = false;
4773
4774   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4775
4776   // Render and notify
4777   application.SendNotification();
4778   application.Render();
4779
4780   DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
4781   DALI_TEST_EQUALS(oldSelectionStart, 0, TEST_LOCATION);
4782   DALI_TEST_EQUALS(oldSelectionEnd, 1, TEST_LOCATION);
4783
4784   gSelectionChangedCallbackCalled = false;
4785
4786   application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_ESCAPE, 0, 0, Integration::KeyEvent::UP, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) );
4787
4788   // Render and notify
4789   application.SendNotification();
4790   application.Render();
4791
4792   DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
4793   DALI_TEST_EQUALS(oldSelectionStart, 0, TEST_LOCATION);
4794   DALI_TEST_EQUALS(oldSelectionEnd, 2, TEST_LOCATION);
4795
4796   gSelectionChangedCallbackCalled = false;
4797   field.SetKeyInputFocus();
4798
4799   // Render and notify
4800   application.SendNotification();
4801   application.Render();
4802
4803   DevelTextField::SelectText( field ,0, 5 );
4804
4805   application.SendNotification();
4806   application.Render();
4807
4808   DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
4809   DALI_TEST_EQUALS(oldSelectionStart, oldSelectionEnd, TEST_LOCATION);
4810
4811   gSelectionChangedCallbackCalled = false;
4812
4813   field.SetProperty( DevelTextField::Property::PRIMARY_CURSOR_POSITION, 3);
4814
4815   // Render and notify
4816   application.SendNotification();
4817   application.Render();
4818
4819   DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
4820   DALI_TEST_EQUALS(oldSelectionStart, 0, TEST_LOCATION);
4821   DALI_TEST_EQUALS(oldSelectionEnd, 5, TEST_LOCATION);
4822
4823   gSelectionChangedCallbackCalled = false;
4824
4825   // select all text
4826   DevelTextField::SelectWholeText(field);
4827
4828   // Render and notify
4829   application.SendNotification();
4830   application.Render();
4831
4832   DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
4833   DALI_TEST_EQUALS(oldSelectionStart, oldSelectionEnd, TEST_LOCATION);
4834
4835   gSelectionChangedCallbackCalled = false;
4836
4837   // select none
4838   DevelTextField::SelectNone(field);
4839
4840   // Render and notify
4841   application.SendNotification();
4842   application.Render();
4843
4844   DALI_TEST_CHECK(gSelectionChangedCallbackCalled);
4845   DALI_TEST_EQUALS(oldSelectionStart, 0, TEST_LOCATION);
4846   DALI_TEST_EQUALS(oldSelectionEnd, 23, TEST_LOCATION);
4847
4848   END_TEST;
4849 }