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