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