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