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