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