[3.0] Fixed issue of LOOPING, MUTED, and VOLUME properties
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextField.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <unistd.h>
21
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/integration-api/events/key-event-integ.h>
24 #include <dali/integration-api/events/tap-gesture-event.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/pan-gesture-event.h>
27 #include <dali/integration-api/events/long-press-gesture-event.h>
28 #include <dali-toolkit-test-suite-utils.h>
29 #include <dali-toolkit/dali-toolkit.h>
30 #include "toolkit-clipboard.h"
31
32 using namespace Dali;
33 using namespace Toolkit;
34
35 void dali_textfield_startup(void)
36 {
37   test_return_value = TET_UNDEF;
38 }
39
40 void dali_textfield_cleanup(void)
41 {
42   test_return_value = TET_PASS;
43 }
44
45 namespace
46 {
47
48 const char* const PROPERTY_NAME_RENDERING_BACKEND                    = "renderingBackend";
49 const char* const PROPERTY_NAME_TEXT                                 = "text";
50 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT                     = "placeholderText";
51 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED             = "placeholderTextFocused";
52 const char* const PROPERTY_NAME_FONT_FAMILY                          = "fontFamily";
53 const char* const PROPERTY_NAME_FONT_STYLE                           = "fontStyle";
54 const char* const PROPERTY_NAME_POINT_SIZE                           = "pointSize";
55 const char* const PROPERTY_NAME_MAX_LENGTH                           = "maxLength";
56 const char* const PROPERTY_NAME_EXCEED_POLICY                        = "exceedPolicy";
57 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT                 = "horizontalAlignment";
58 const char* const PROPERTY_NAME_VERTICAL_ALIGNMENT                   = "verticalAlignment";
59 const char* const PROPERTY_NAME_TEXT_COLOR                           = "textColor";
60 const char* const PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR               = "placeholderTextColor";
61 const char* const PROPERTY_NAME_SHADOW_OFFSET                        = "shadowOffset";
62 const char* const PROPERTY_NAME_SHADOW_COLOR                         = "shadowColor";
63 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR                 = "primaryCursorColor";
64 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR               = "secondaryCursorColor";
65 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK                  = "enableCursorBlink";
66 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL                = "cursorBlinkInterval";
67 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION                = "cursorBlinkDuration";
68 const char* const PROPERTY_NAME_CURSOR_WIDTH                         = "cursorWidth";
69 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHandleImage";
70 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
71 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
72 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
73 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
74 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
75 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
76 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
77 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT   = "selectionHandleMarkerImageLeft";
78 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = "selectionHandleMarkerImageRight";
79 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR            = "selectionHighlightColor";
80 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX              = "decorationBoundingBox";
81 const char* const PROPERTY_NAME_INPUT_METHOD_SETTINGS                = "inputMethodSettings";
82 const char* const PROPERTY_NAME_INPUT_COLOR                          = "inputColor";
83 const char* const PROPERTY_NAME_ENABLE_MARKUP                        = "enableMarkup";
84 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY                    = "inputFontFamily";
85 const char* const PROPERTY_NAME_INPUT_FONT_STYLE                     = "inputFontStyle";
86 const char* const PROPERTY_NAME_INPUT_POINT_SIZE                     = "inputPointSize";
87
88 const char* const PROPERTY_NAME_UNDERLINE                            = "underline";
89 const char* const PROPERTY_NAME_INPUT_UNDERLINE                      = "inputUnderline";
90 const char* const PROPERTY_NAME_SHADOW                               = "shadow";
91 const char* const PROPERTY_NAME_INPUT_SHADOW                         = "inputShadow";
92 const char* const PROPERTY_NAME_EMBOSS                               = "emboss";
93 const char* const PROPERTY_NAME_INPUT_EMBOSS                         = "inputEmboss";
94 const char* const PROPERTY_NAME_OUTLINE                              = "outline";
95 const char* const PROPERTY_NAME_INPUT_OUTLINE                        = "inputOutline";
96
97 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
98
99 const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f );
100 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
101
102 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
103 const float RENDER_FRAME_INTERVAL = 16.66f;
104
105 const float TO_MILLISECONDS = 1000.f;
106 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
107
108 const float SCROLL_THRESHOLD = 10.f;
109 const float SCROLL_SPEED = 300.f;
110
111 const unsigned int DEFAULT_FONT_SIZE = 1152u;
112 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
113
114 const int KEY_A_CODE = 38;
115 const int KEY_D_CODE = 40;
116
117 static bool gTextChangedCallBackCalled;
118 static bool gMaxCharactersCallBackCalled;
119 static bool gInputStyleChangedCallbackCalled;
120 static Dali::Toolkit::TextField::InputStyle::Mask gInputStyleMask;
121
122 static void LoadBitmapResource(TestPlatformAbstraction& platform, int width, int height)
123 {
124   Integration::ResourceRequest* request = platform.GetRequest();
125   Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::OWNED_DISCARD );
126   Integration::ResourcePointer resource(bitmap);
127   bitmap->GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGBA8888, width, height, width, height);
128
129   if(request)
130   {
131     platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resource);
132   }
133 }
134
135 static void LoadMarkerImages(ToolkitTestApplication& app, TextField textField)
136 {
137   int width(40);
138   int height(40);
139   LoadBitmapResource( app.GetPlatform(), width, height );
140
141   Property::Map propertyMap;
142   propertyMap["filename"] = "image.png";
143   propertyMap["width"] = width;
144   propertyMap["height"] = height;
145   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, propertyMap );
146   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, propertyMap );
147   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, propertyMap );
148   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, propertyMap );
149   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, propertyMap );
150   textField.SetProperty( Toolkit::TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, propertyMap );
151   textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_IMAGE, propertyMap );
152   textField.SetProperty( Toolkit::TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, propertyMap );
153 }
154
155 // Generate a PanGestureEvent to send to Core
156 static Integration::PanGestureEvent GeneratePan(
157     Gesture::State state,
158     const Vector2& previousPosition,
159     const Vector2& currentPosition,
160     unsigned long timeDelta,
161     unsigned int numberOfTouches = 1)
162 {
163   Integration::PanGestureEvent pan(state);
164
165   pan.previousPosition = previousPosition;
166   pan.currentPosition = currentPosition;
167   pan.timeDelta = timeDelta;
168   pan.numberOfTouches = numberOfTouches;
169
170   return pan;
171 }
172
173 /**
174  * Helper to generate PanGestureEvent
175  *
176  * @param[in] application Application instance
177  * @param[in] state The Gesture State
178  * @param[in] pos The current position of touch.
179  */
180 static void SendPan(ToolkitTestApplication& application, Gesture::State state, const Vector2& pos)
181 {
182   static Vector2 last;
183
184   if( (state == Gesture::Started) ||
185       (state == Gesture::Possible) )
186   {
187     last.x = pos.x;
188     last.y = pos.y;
189   }
190
191   application.ProcessEvent(GeneratePan(state, last, pos, 16));
192
193   last.x = pos.x;
194   last.y = pos.y;
195 }
196
197 /*
198  * Simulate time passed by.
199  *
200  * @note this will always process at least 1 frame (1/60 sec)
201  *
202  * @param application Test application instance
203  * @param duration Time to pass in milliseconds.
204  * @return The actual time passed in milliseconds
205  */
206 static int Wait(ToolkitTestApplication& application, int duration = 0)
207 {
208   int time = 0;
209
210   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
211   {
212     application.SendNotification();
213     application.Render(RENDER_FRAME_INTERVAL);
214     time += RENDER_FRAME_INTERVAL;
215   }
216
217   return time;
218 }
219
220 Dali::Integration::Point GetPointDownInside( Vector2& pos )
221 {
222   Dali::Integration::Point point;
223   point.SetState( PointState::DOWN );
224   point.SetScreenPosition( pos );
225   return point;
226 }
227
228 Dali::Integration::Point GetPointUpInside( Vector2& pos )
229 {
230   Dali::Integration::Point point;
231   point.SetState( PointState::UP );
232   point.SetScreenPosition( pos );
233   return point;
234 }
235
236 struct CallbackFunctor
237 {
238   CallbackFunctor(bool* callbackFlag)
239   : mCallbackFlag( callbackFlag )
240   {
241   }
242
243   void operator()()
244   {
245     *mCallbackFlag = true;
246   }
247   bool* mCallbackFlag;
248 };
249
250 static void TestTextChangedCallback( TextField control )
251 {
252   tet_infoline(" TestTextChangedCallback");
253
254   gTextChangedCallBackCalled = true;
255 }
256
257 static void TestMaxLengthReachedCallback( TextField control )
258 {
259   tet_infoline(" TestMaxLengthReachedCallback");
260
261   gMaxCharactersCallBackCalled = true;
262 }
263
264 static void TestInputStyleChangedCallback( TextField control, TextField::InputStyle::Mask mask )
265 {
266   tet_infoline(" TestInputStyleChangedCallback");
267
268   gInputStyleChangedCallbackCalled = true;
269   gInputStyleMask = mask;
270 }
271
272 // Generate a TapGestureEvent to send to Core.
273 Integration::TapGestureEvent GenerateTap(
274     Gesture::State state,
275     unsigned int numberOfTaps,
276     unsigned int numberOfTouches,
277     Vector2 point)
278 {
279   Integration::TapGestureEvent tap( state );
280
281   tap.numberOfTaps = numberOfTaps;
282   tap.numberOfTouches = numberOfTouches;
283   tap.point = point;
284
285   return tap;
286 }
287
288
289 Integration::LongPressGestureEvent GenerateLongPress(
290     Gesture::State state,
291     unsigned int numberOfTouches,
292     Vector2 point)
293 {
294   Integration::LongPressGestureEvent longPress( state );
295
296   longPress.numberOfTouches = numberOfTouches;
297   longPress.point = point;
298   return longPress;
299 }
300
301 // Generate a KeyEvent to send to Core.
302 Integration::KeyEvent GenerateKey( const std::string& keyName,
303                                    const std::string& keyString,
304                                    int keyCode,
305                                    int keyModifier,
306                                    unsigned long timeStamp,
307                                    const Integration::KeyEvent::State& keyState )
308 {
309   return Integration::KeyEvent( keyName,
310                                 keyString,
311                                 keyCode,
312                                 keyModifier,
313                                 timeStamp,
314                                 keyState );
315 }
316
317 } // namespace
318
319 int UtcDaliToolkitTextFieldConstructorP(void)
320 {
321   ToolkitTestApplication application;
322   tet_infoline(" UtcDaliToolkitTextFieldConstructorP");
323   TextField textField;
324   DALI_TEST_CHECK( !textField );
325   END_TEST;
326 }
327
328 int UtcDaliToolkitTextFieldNewP(void)
329 {
330   ToolkitTestApplication application;
331   tet_infoline(" UtcDaliToolkitTextFieldNewP");
332   TextField textField = TextField::New();
333   DALI_TEST_CHECK( textField );
334   END_TEST;
335 }
336
337 int UtcDaliToolkitTextFieldDownCastP(void)
338 {
339   ToolkitTestApplication application;
340   tet_infoline(" UtcDaliToolkitTextFieldDownCastP");
341   TextField textField1 = TextField::New();
342   BaseHandle object( textField1 );
343
344   TextField textField2 = TextField::DownCast( object );
345   DALI_TEST_CHECK( textField2 );
346
347   TextField textField3 = DownCast< TextField >( object );
348   DALI_TEST_CHECK( textField3 );
349   END_TEST;
350 }
351
352 int UtcDaliToolkitTextFieldDownCastN(void)
353 {
354   ToolkitTestApplication application;
355   tet_infoline(" UtcDaliToolkitTextFieldDownCastN");
356   BaseHandle uninitializedObject;
357   TextField textField1 = TextField::DownCast( uninitializedObject );
358   DALI_TEST_CHECK( !textField1 );
359
360   TextField textField2 = DownCast< TextField >( uninitializedObject );
361   DALI_TEST_CHECK( !textField2 );
362   END_TEST;
363 }
364
365 int UtcDaliToolkitTextFieldCopyConstructorP(void)
366 {
367   ToolkitTestApplication application;
368   tet_infoline(" UtcDaliToolkitTextFieldCopyConstructorP");
369   TextField textField = TextField::New();
370   textField.SetProperty( TextField::Property::TEXT, "Test" );
371
372   TextField copy( textField );
373   DALI_TEST_CHECK( copy );
374   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextLabel::Property::TEXT ) == textField.GetProperty<std::string>( TextLabel::Property::TEXT ) );
375   END_TEST;
376 }
377
378 int UtcDaliToolkitTextFieldAssignmentOperatorP(void)
379 {
380   ToolkitTestApplication application;
381   tet_infoline(" UtcDaliToolkitTextFieldAssignmentOperatorP");
382   TextField textField = TextField::New();
383   textField.SetProperty( TextField::Property::TEXT, "Test" );
384
385   TextField copy = textField;
386   DALI_TEST_CHECK( copy );
387   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextField::Property::TEXT ) == textField.GetProperty<std::string>( TextField::Property::TEXT ) );
388   END_TEST;
389 }
390
391 int UtcDaliTextFieldNewP(void)
392 {
393   ToolkitTestApplication application;
394   tet_infoline(" UtcDaliToolkitTextFieldNewP");
395   TextField textField = TextField::New();
396   DALI_TEST_CHECK( textField );
397   END_TEST;
398 }
399
400 // Positive test case for a method
401 int UtcDaliTextFieldGetPropertyP(void)
402 {
403   ToolkitTestApplication application;
404   tet_infoline(" UtcDaliToolkitTextFieldGetPropertyP");
405   TextField field = TextField::New();
406   DALI_TEST_CHECK( field );
407
408   // Check Property Indices are correct
409   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextField::Property::RENDERING_BACKEND );
410   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextField::Property::TEXT );
411   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT ) == TextField::Property::PLACEHOLDER_TEXT );
412   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_FOCUSED ) == TextField::Property::PLACEHOLDER_TEXT_FOCUSED );
413   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextField::Property::FONT_FAMILY );
414   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextField::Property::FONT_STYLE );
415   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextField::Property::POINT_SIZE );
416   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == TextField::Property::MAX_LENGTH );
417   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EXCEED_POLICY ) == TextField::Property::EXCEED_POLICY );
418   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextField::Property::HORIZONTAL_ALIGNMENT );
419   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_VERTICAL_ALIGNMENT ) == TextField::Property::VERTICAL_ALIGNMENT );
420   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextField::Property::TEXT_COLOR );
421   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PLACEHOLDER_TEXT_COLOR ) == TextField::Property::PLACEHOLDER_TEXT_COLOR );
422   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_OFFSET ) == TextField::Property::SHADOW_OFFSET );
423   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW_COLOR ) == TextField::Property::SHADOW_COLOR );
424   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextField::Property::PRIMARY_CURSOR_COLOR );
425   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextField::Property::SECONDARY_CURSOR_COLOR );
426   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextField::Property::ENABLE_CURSOR_BLINK );
427   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextField::Property::CURSOR_BLINK_INTERVAL );
428   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextField::Property::CURSOR_BLINK_DURATION );
429   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextField::Property::CURSOR_WIDTH );
430   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextField::Property::GRAB_HANDLE_IMAGE );
431   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextField::Property::GRAB_HANDLE_PRESSED_IMAGE );
432   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextField::Property::SCROLL_THRESHOLD );
433   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextField::Property::SCROLL_SPEED );
434   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_IMAGE_LEFT );
435   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT );
436   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
437   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
438   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
439   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
440   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextField::Property::SELECTION_HIGHLIGHT_COLOR );
441   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextField::Property::DECORATION_BOUNDING_BOX );
442   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_METHOD_SETTINGS ) == TextField::Property::INPUT_METHOD_SETTINGS );
443   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextField::Property::INPUT_COLOR );
444   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextField::Property::ENABLE_MARKUP );
445   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextField::Property::INPUT_FONT_FAMILY );
446   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextField::Property::INPUT_FONT_STYLE );
447   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextField::Property::INPUT_POINT_SIZE );
448   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextField::Property::UNDERLINE );
449   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextField::Property::INPUT_UNDERLINE );
450   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextField::Property::SHADOW );
451   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextField::Property::INPUT_SHADOW );
452   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextField::Property::EMBOSS );
453   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextField::Property::INPUT_EMBOSS );
454   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextField::Property::OUTLINE );
455   DALI_TEST_CHECK( field.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextField::Property::INPUT_OUTLINE );
456
457   END_TEST;
458 }
459
460 bool SetPropertyMapRetrieved( TextField& field, const Property::Index property, const std::string mapKey, const std::string mapValue )
461 {
462   bool result = false;
463   Property::Map imageMap;
464   imageMap[mapKey] =mapValue;
465
466   field.SetProperty( property , imageMap );
467   Property::Value propValue = field.GetProperty( property );
468   Property::Map* resultMap = propValue.GetMap();
469
470   if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
471   {
472     result = true;
473   }
474
475   return result;
476 }
477
478 // Positive test case for a method
479 int UtcDaliTextFieldSetPropertyP(void)
480 {
481   ToolkitTestApplication application;
482   tet_infoline(" UtcDaliToolkitTextFieldSetPropertyP");
483   TextField field = TextField::New();
484   DALI_TEST_CHECK( field );
485   Stage::GetCurrent().Add( field );
486
487   // Note - we can't check the defaults since the stylesheets are platform-specific
488
489   // Check the render backend property.
490   field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
491   DALI_TEST_EQUALS( (Text::RenderingType)field.GetProperty<int>( TextField::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
492
493   // Check text property.
494   field.SetProperty( TextField::Property::TEXT, "Setting Text" );
495   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
496
497   // Check placeholder text properties.
498   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
499   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT ), std::string("Setting Placeholder Text"), TEST_LOCATION );
500
501   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Setting Placeholder Text Focused" );
502   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::PLACEHOLDER_TEXT_FOCUSED ), std::string("Setting Placeholder Text Focused"), TEST_LOCATION );
503
504   // Check font properties.
505   field.SetProperty( TextField::Property::FONT_FAMILY, "Setting font family" );
506   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
507   field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
508   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}"), TEST_LOCATION );
509   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
510   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
511
512   // Reset font style.
513   field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
514   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
515   field.SetProperty( TextField::Property::FONT_STYLE, "{\"slant\":\"roman\"}" );
516   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
517   field.SetProperty( TextField::Property::FONT_STYLE, "" );
518   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), std::string(""), TEST_LOCATION );
519
520   // Check that the MAX_LENGTH property can be correctly set
521   const int maxNumberOfCharacters = 20;
522   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
523   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION );
524
525   // Check exceed policy
526   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_CLIP );
527   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_CLIP ), TEST_LOCATION );
528   field.SetProperty( TextField::Property::EXCEED_POLICY, Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL );
529   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::EXCEED_POLICY ), static_cast<int>( Dali::Toolkit::TextField::EXCEED_POLICY_ORIGINAL ), TEST_LOCATION );
530
531   // Check that the Alignment properties can be correctly set
532   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
533   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
534   field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
535   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
536
537   // Check text's color property
538   field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
539   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
540
541   // Check placeholder text's color property.
542   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
543   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
544
545   // Check shadow properties.
546   field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
547   DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
548   field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
549   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
550
551   // Check cursor properties
552   field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
553   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
554   field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
555   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
556
557   field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
558   DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
559   field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
560   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
561   field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
562   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
563   field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
564   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
565
566   // Check scroll properties.
567   field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
568   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
569   field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
570   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
571
572   // Check handle images
573   field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
574   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
575   field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
576   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
577   field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
578
579   // Check handle images
580   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" )  );
581   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" )  );
582   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" )  );
583   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" )  );
584   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" )  );
585   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" )  );
586
587   // Check the highlight color
588   field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
589   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
590
591   // Decoration bounding box
592   field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
593   DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
594
595   // Check input color property.
596   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
597   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
598
599   // Check the enable markup property.
600   DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
601   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
602   DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
603
604   // Check input font properties.
605   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
606   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
607   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
608   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"width\":\"condensed\",\"slant\":\"italic\"}", TEST_LOCATION );
609   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
610   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
611
612   // Reset input font style.
613   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"normal\",\"slant\":\"oblique\"}" );
614   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"weight\":\"normal\",\"slant\":\"oblique\"}"), TEST_LOCATION );
615   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"slant\":\"roman\"}" );
616   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string("{\"slant\":\"normal\"}"), TEST_LOCATION );
617   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "" );
618   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), std::string(""), TEST_LOCATION );
619
620   // Check the underline property
621   field.SetProperty( TextField::Property::UNDERLINE, "Underline properties" );
622   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::UNDERLINE ), std::string("Underline properties"), TEST_LOCATION );
623
624   // Check the input underline property
625   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
626   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
627
628   // Check the shadow property
629   field.SetProperty( TextField::Property::SHADOW, "Shadow properties" );
630   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::SHADOW ), std::string("Shadow properties"), TEST_LOCATION );
631
632   // Check the input shadow property
633   field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
634   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
635
636   // Check the emboss property
637   field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
638   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
639
640   // Check the input emboss property
641   field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
642   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
643
644   // Check the outline property
645   field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
646   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
647
648   // Check the input outline property
649   field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
650   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
651
652   END_TEST;
653 }
654
655 // Positive Atlas Text Renderer test
656 int utcDaliTextFieldAtlasRenderP(void)
657 {
658   ToolkitTestApplication application;
659   tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
660   StyleManager styleManager = StyleManager::Get();
661   styleManager.ApplyDefaultTheme();
662   TextField field = TextField::New();
663   DALI_TEST_CHECK( field );
664
665   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
666
667   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
668
669   Stage::GetCurrent().Add( field );
670
671   try
672   {
673     // Render some text with the shared atlas backend
674     field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
675     application.SendNotification();
676     application.Render();
677   }
678   catch( ... )
679   {
680     tet_result(TET_FAIL);
681   }
682   END_TEST;
683 }
684
685 // Positive test for the textChanged signal.
686 int utcDaliTextFieldTextChangedP(void)
687 {
688   ToolkitTestApplication application;
689   tet_infoline(" utcDaliTextFieldTextChangedP");
690   TextField field = TextField::New();
691   DALI_TEST_CHECK( field );
692
693   Stage::GetCurrent().Add( field );
694
695   // connect to the text changed signal.
696   ConnectionTracker* testTracker = new ConnectionTracker();
697   field.TextChangedSignal().Connect(&TestTextChangedCallback);
698   bool textChangedSignal = false;
699   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
700
701   gTextChangedCallBackCalled = false;
702   field.SetProperty( TextField::Property::TEXT, "ABC" );
703   DALI_TEST_CHECK( gTextChangedCallBackCalled );
704   DALI_TEST_CHECK( textChangedSignal );
705
706   application.SendNotification();
707
708   field.SetKeyInputFocus();
709
710   gTextChangedCallBackCalled = false;
711   application.ProcessEvent( GenerateKey( "D", "D", KEY_D_CODE, 0, 0, Integration::KeyEvent::Down ) );
712   DALI_TEST_CHECK( gTextChangedCallBackCalled );
713
714   END_TEST;
715 }
716
717 // Negative test for the textChanged signal.
718 int utcDaliTextFieldTextChangedN(void)
719 {
720   ToolkitTestApplication application;
721   tet_infoline(" utcDaliTextFieldTextChangedN");
722   TextField field = TextField::New();
723   DALI_TEST_CHECK( field );
724
725   Stage::GetCurrent().Add( field );
726
727   // connect to the text changed signal.
728   ConnectionTracker* testTracker = new ConnectionTracker();
729   field.TextChangedSignal().Connect(&TestTextChangedCallback);
730   bool textChangedSignal = false;
731   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
732
733   gTextChangedCallBackCalled = false;
734   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
735   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
736   DALI_TEST_CHECK( !textChangedSignal );
737
738   END_TEST;
739 }
740
741 // Positive test for Max Characters reached signal.
742 int utcDaliTextFieldMaxCharactersReachedP(void)
743 {
744   ToolkitTestApplication application;
745   tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
746   TextField field = TextField::New();
747   DALI_TEST_CHECK( field );
748
749   Stage::GetCurrent().Add( field );
750
751   const int maxNumberOfCharacters = 1;
752   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
753
754   field.SetKeyInputFocus();
755
756   // connect to the text changed signal.
757   ConnectionTracker* testTracker = new ConnectionTracker();
758   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
759   bool maxLengthReachedSignal = false;
760   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
761
762   gMaxCharactersCallBackCalled = false;
763
764   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
765   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
766
767   DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
768   DALI_TEST_CHECK( maxLengthReachedSignal );
769
770   END_TEST;
771 }
772
773 // Negative test for Max Characters reached signal.
774 int utcDaliTextFieldMaxCharactersReachedN(void)
775 {
776   ToolkitTestApplication application;
777   tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
778   TextField field = TextField::New();
779   DALI_TEST_CHECK( field );
780
781   Stage::GetCurrent().Add( field );
782
783   const int maxNumberOfCharacters = 3;
784   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
785
786   field.SetKeyInputFocus();
787
788   // connect to the text changed signal.
789   ConnectionTracker* testTracker = new ConnectionTracker();
790   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
791   bool maxLengthReachedSignal = false;
792   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
793
794   gMaxCharactersCallBackCalled = false;
795
796   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
797   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
798
799   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
800   DALI_TEST_CHECK( !maxLengthReachedSignal );
801
802   END_TEST;
803 }
804
805 int utcDaliTextFieldInputStyleChanged01(void)
806 {
807   ToolkitTestApplication application;
808   tet_infoline(" utcDaliTextFieldInputStyleChanged01");
809
810   // The text-field emits signals when the input style changes. These changes of style are
811   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
812   // can't be emitted during the size negotiation as the callbacks may update the UI.
813   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
814   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
815   application.CreateAdaptor();
816
817   // Load some fonts.
818
819   char* pathNamePtr = get_current_dir_name();
820   const std::string pathName( pathNamePtr );
821   free( pathNamePtr );
822
823   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
824   fontClient.SetDpi( 93u, 93u );
825
826   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
827   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
828
829   TextField field = TextField::New();
830   DALI_TEST_CHECK( field );
831
832
833   field.SetSize( 300.f, 50.f );
834   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
835   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
836
837   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
838   field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
839
840   // connect to the text changed signal.
841   ConnectionTracker* testTracker = new ConnectionTracker();
842   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
843   bool inputStyleChangedSignal = false;
844   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
845
846   Stage::GetCurrent().Add( field );
847
848   // Render and notify
849   application.SendNotification();
850   application.Render();
851
852   // Executes the idle callbacks added by the text control on the change of input style.
853   application.RunIdles();
854
855   gInputStyleChangedCallbackCalled = false;
856   gInputStyleMask = TextField::InputStyle::NONE;
857   inputStyleChangedSignal = false;
858
859   // Create a tap event to touch the text field.
860   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
861   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
862
863   // Render and notify
864   application.SendNotification();
865   application.Render();
866
867   // Executes the idle callbacks added by the text control on the change of input style.
868   application.RunIdles();
869
870   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
871   if( gInputStyleChangedCallbackCalled )
872   {
873     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
874
875     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
876     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
877
878     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
879     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
880   }
881   DALI_TEST_CHECK( inputStyleChangedSignal );
882
883   gInputStyleChangedCallbackCalled = false;
884   gInputStyleMask = TextField::InputStyle::NONE;
885   inputStyleChangedSignal = false;
886
887   // Create a tap event to touch the text field.
888   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
889   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
890
891   // Render and notify
892   application.SendNotification();
893   application.Render();
894
895   // Executes the idle callbacks added by the text control on the change of input style.
896   application.RunIdles();
897
898   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
899   DALI_TEST_CHECK( !inputStyleChangedSignal );
900
901   gInputStyleChangedCallbackCalled = false;
902   gInputStyleMask = TextField::InputStyle::NONE;
903   inputStyleChangedSignal = false;
904
905   // Create a tap event to touch the text field.
906   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
907   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
908
909   // Render and notify
910   application.SendNotification();
911   application.Render();
912
913   // Executes the idle callbacks added by the text control on the change of input style.
914   application.RunIdles();
915
916   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
917   if( gInputStyleChangedCallbackCalled )
918   {
919     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
920
921     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
922     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
923   }
924   DALI_TEST_CHECK( inputStyleChangedSignal );
925
926   gInputStyleChangedCallbackCalled = false;
927   gInputStyleMask = TextField::InputStyle::NONE;
928   inputStyleChangedSignal = false;
929
930   // Create a tap event to touch the text field.
931   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
932   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
933
934   // Render and notify
935   application.SendNotification();
936   application.Render();
937
938   // Executes the idle callbacks added by the text control on the change of input style.
939   application.RunIdles();
940
941   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
942   if( gInputStyleChangedCallbackCalled )
943   {
944     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
945
946     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
947     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
948
949     const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
950     DALI_TEST_EQUALS( style, "{\"weight\":\"bold\"}", TEST_LOCATION );
951   }
952   DALI_TEST_CHECK( inputStyleChangedSignal );
953
954   gInputStyleChangedCallbackCalled = false;
955   gInputStyleMask = TextField::InputStyle::NONE;
956   inputStyleChangedSignal = false;
957
958   // Create a tap event to touch the text field.
959   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
960   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
961
962   // Render and notify
963   application.SendNotification();
964   application.Render();
965
966   // Executes the idle callbacks added by the text control on the change of input style.
967   application.RunIdles();
968
969   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
970   DALI_TEST_CHECK( !inputStyleChangedSignal );
971
972   gInputStyleChangedCallbackCalled = false;
973   gInputStyleMask = TextField::InputStyle::NONE;
974   inputStyleChangedSignal = false;
975
976   // Create a tap event to touch the text field.
977   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
978   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
979
980   // Render and notify
981   application.SendNotification();
982   application.Render();
983
984   // Executes the idle callbacks added by the text control on the change of input style.
985   application.RunIdles();
986
987   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
988   if( gInputStyleChangedCallbackCalled )
989   {
990     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
991
992     const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
993     DALI_TEST_CHECK( style.empty() );
994   }
995   DALI_TEST_CHECK( inputStyleChangedSignal );
996
997   gInputStyleChangedCallbackCalled = false;
998   gInputStyleMask = TextField::InputStyle::NONE;
999   inputStyleChangedSignal = false;
1000
1001   // Create a tap event to touch the text field.
1002   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1003   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1004
1005   // Render and notify
1006   application.SendNotification();
1007   application.Render();
1008
1009   // Executes the idle callbacks added by the text control on the change of input style.
1010   application.RunIdles();
1011
1012   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1013   DALI_TEST_CHECK( !inputStyleChangedSignal );
1014
1015   END_TEST;
1016 }
1017
1018 int utcDaliTextFieldInputStyleChanged02(void)
1019 {
1020   ToolkitTestApplication application;
1021   tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1022
1023   // The text-field emits signals when the input style changes. These changes of style are
1024   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1025   // can't be emitted during the size negotiation as the callbacks may update the UI.
1026   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1027   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1028   application.CreateAdaptor();
1029
1030   // Load some fonts.
1031
1032   char* pathNamePtr = get_current_dir_name();
1033   const std::string pathName( pathNamePtr );
1034   free( pathNamePtr );
1035
1036   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1037   fontClient.SetDpi( 93u, 93u );
1038
1039   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1040   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1041
1042   TextField field = TextField::New();
1043   DALI_TEST_CHECK( field );
1044
1045
1046   field.SetSize( 300.f, 50.f );
1047   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1048   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1049
1050   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1051   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>" );
1052
1053   // connect to the text changed signal.
1054   ConnectionTracker* testTracker = new ConnectionTracker();
1055   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1056   bool inputStyleChangedSignal = false;
1057   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1058
1059   Stage::GetCurrent().Add( field );
1060
1061   // Render and notify
1062   application.SendNotification();
1063   application.Render();
1064
1065   // Executes the idle callbacks added by the text control on the change of input style.
1066   application.RunIdles();
1067
1068   gInputStyleChangedCallbackCalled = false;
1069   gInputStyleMask = TextField::InputStyle::NONE;
1070   inputStyleChangedSignal = false;
1071
1072   // Create a tap event to touch the text field.
1073   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1074   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1075   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1076   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1077
1078   // Render and notify
1079   application.SendNotification();
1080   application.Render();
1081
1082   // Executes the idle callbacks added by the text control on the change of input style.
1083   application.RunIdles();
1084
1085   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1086   if( gInputStyleChangedCallbackCalled )
1087   {
1088     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1089                       static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1090                                                  TextField::InputStyle::POINT_SIZE  |
1091                                                  TextField::InputStyle::COLOR ),
1092                       TEST_LOCATION );
1093
1094     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1095     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1096
1097     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1098     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1099
1100     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1101     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1102   }
1103   DALI_TEST_CHECK( inputStyleChangedSignal );
1104
1105   gInputStyleChangedCallbackCalled = false;
1106   gInputStyleMask = TextField::InputStyle::NONE;
1107   inputStyleChangedSignal = false;
1108
1109   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1110
1111   // Render and notify
1112   application.SendNotification();
1113   application.Render();
1114
1115   // Executes the idle callbacks added by the text control on the change of input style.
1116   application.RunIdles();
1117
1118   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1119   if( gInputStyleChangedCallbackCalled )
1120   {
1121     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1122                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1123                       TEST_LOCATION );
1124
1125     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1126     DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1127   }
1128   DALI_TEST_CHECK( inputStyleChangedSignal );
1129
1130   gInputStyleChangedCallbackCalled = false;
1131   gInputStyleMask = TextField::InputStyle::NONE;
1132   inputStyleChangedSignal = false;
1133
1134   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1135
1136   // Render and notify
1137   application.SendNotification();
1138   application.Render();
1139
1140   // Executes the idle callbacks added by the text control on the change of input style.
1141   application.RunIdles();
1142
1143   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1144   DALI_TEST_CHECK( !inputStyleChangedSignal );
1145
1146   gInputStyleChangedCallbackCalled = false;
1147   gInputStyleMask = TextField::InputStyle::NONE;
1148   inputStyleChangedSignal = false;
1149
1150   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1151
1152   // Render and notify
1153   application.SendNotification();
1154   application.Render();
1155
1156   // Executes the idle callbacks added by the text control on the change of input style.
1157   application.RunIdles();
1158
1159   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1160   if( gInputStyleChangedCallbackCalled )
1161   {
1162     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1163                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1164                       TEST_LOCATION );
1165
1166     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1167     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1168   }
1169   DALI_TEST_CHECK( inputStyleChangedSignal );
1170
1171   gInputStyleChangedCallbackCalled = false;
1172   gInputStyleMask = TextField::InputStyle::NONE;
1173   inputStyleChangedSignal = false;
1174
1175   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1176
1177   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"thin\",\"width\":\"condensed\",\"slant\":\"italic\"}" );
1178   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1179
1180   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1181   field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1182   field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1183   field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1184
1185   // Render and notify
1186   application.SendNotification();
1187   application.Render();
1188
1189   // Executes the idle callbacks added by the text control on the change of input style.
1190   application.RunIdles();
1191
1192   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1193   DALI_TEST_CHECK( !inputStyleChangedSignal );
1194
1195   // Create a tap event to touch the text field.
1196   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1197   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1198
1199   // Render and notify
1200   application.SendNotification();
1201   application.Render();
1202
1203   // Executes the idle callbacks added by the text control on the change of input style.
1204   application.RunIdles();
1205
1206   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1207   if( gInputStyleChangedCallbackCalled )
1208   {
1209     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1210                       static_cast<unsigned int>( TextField::InputStyle::COLOR |
1211                                                  TextField::InputStyle::POINT_SIZE |
1212                                                  TextField::InputStyle::FONT_STYLE |
1213                                                  TextField::InputStyle::UNDERLINE |
1214                                                  TextField::InputStyle::SHADOW |
1215                                                  TextField::InputStyle::EMBOSS |
1216                                                  TextField::InputStyle::OUTLINE ),
1217                       TEST_LOCATION );
1218
1219     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1220     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1221   }
1222   DALI_TEST_CHECK( inputStyleChangedSignal );
1223
1224   END_TEST;
1225 }
1226
1227 int utcDaliTextFieldEvent01(void)
1228 {
1229   ToolkitTestApplication application;
1230   tet_infoline(" utcDaliTextFieldEvent01");
1231
1232   // Creates a tap event. After creating a tap event the text field should
1233   // have the focus and add text with key events should be possible.
1234
1235   TextField field = TextField::New();
1236   DALI_TEST_CHECK( field );
1237
1238   Stage::GetCurrent().Add( field );
1239
1240   field.SetSize( 300.f, 50.f );
1241   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1242   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1243
1244   // Avoid a crash when core load gl resources.
1245   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1246
1247   // Render and notify
1248   application.SendNotification();
1249   application.Render();
1250
1251   // Add a key event but as the text field has not the focus it should do nothing.
1252   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1253
1254   // Render and notify
1255   application.SendNotification();
1256   application.Render();
1257
1258   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1259
1260   // Create a tap event to touch the text field.
1261   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1262   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1263
1264   // Render and notify
1265   application.SendNotification();
1266   application.Render();
1267
1268   // Now the text field has the focus, so it can handle the key events.
1269   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1270   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1271
1272   // Render and notify
1273   application.SendNotification();
1274   application.Render();
1275
1276   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1277
1278   // Create a second text field and send key events to it.
1279   TextField field2 = TextField::New();
1280
1281   field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1282   field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1283   field2.SetSize( 100.f, 100.f );
1284   field2.SetPosition( 100.f, 100.f );
1285
1286   Stage::GetCurrent().Add( field2 );
1287
1288   // Render and notify
1289   application.SendNotification();
1290   application.Render();
1291
1292   // Create a tap event on the second text field.
1293   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1294   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1295
1296   // Render and notify
1297   application.SendNotification();
1298   application.Render();
1299
1300   // The second text field has the focus. It should handle the key events.
1301   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1302   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1303
1304   // Render and notify
1305   application.SendNotification();
1306   application.Render();
1307
1308   // Check the text has been added to the second text field.
1309   DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1310
1311   END_TEST;
1312 }
1313
1314 int utcDaliTextFieldEvent02(void)
1315 {
1316   ToolkitTestApplication application;
1317   tet_infoline(" utcDaliTextFieldEvent02");
1318
1319   // Checks if the right number of actors are created.
1320
1321   TextField field = TextField::New();
1322   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1323   DALI_TEST_CHECK( field );
1324   LoadMarkerImages(application, field);
1325
1326   Stage::GetCurrent().Add( field );
1327
1328   field.SetSize( 300.f, 50.f );
1329   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1330   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1331
1332   // Avoid a crash when core load gl resources.
1333   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1334
1335   // Render and notify
1336   application.SendNotification();
1337   application.Render();
1338
1339   // Check there are the expected number of children ( stencil ).
1340   DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1341
1342   Actor stencil = field.GetChildAt( 0u );
1343   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1344
1345   // Create a tap event to touch the text field.
1346   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1347   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1348
1349   // Render and notify
1350   application.SendNotification();
1351   application.Render();
1352
1353   Actor layer = field.GetChildAt( 1u );
1354   DALI_TEST_CHECK( layer.IsLayer() );
1355
1356   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1357   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1358
1359   // Now the text field has the focus, so it can handle the key events.
1360   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1361   application.ProcessEvent( GenerateKey( "a", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down ) );
1362
1363   // Render and notify
1364   application.SendNotification();
1365   application.Render();
1366
1367   // Checks the cursor and the renderer have been created.
1368   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1369   DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The renderer
1370
1371   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1372   DALI_TEST_CHECK( cursor );
1373
1374   // The offscreen root actor has a container with all the actors which contain the text renderers.
1375   Actor container = stencil.GetChildAt( 0u );
1376   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1377   {
1378     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1379     DALI_TEST_CHECK( renderer );
1380   }
1381
1382   // Move the cursor and check the position changes.
1383   Vector3 position1 = cursor.GetCurrentPosition();
1384
1385   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1386   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1387
1388   // Render and notify
1389   application.SendNotification();
1390   application.Render();
1391
1392   Vector3 position2 = cursor.GetCurrentPosition();
1393
1394   DALI_TEST_CHECK( position2.x < position1.x );
1395
1396   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1397   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1398
1399   // Render and notify
1400   application.SendNotification();
1401   application.Render();
1402
1403   Vector3 position3 = cursor.GetCurrentPosition();
1404
1405   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1406
1407   // Send some taps and check the cursor positions.
1408
1409   // Try to tap at the beginning.
1410   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1411   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1412
1413   // Render and notify
1414   application.SendNotification();
1415   application.Render();
1416
1417   // Cursor position should be the same than position1.
1418   Vector3 position4 = cursor.GetCurrentPosition();
1419
1420   DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1421
1422   // Tap away from the start position.
1423   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1424   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1425
1426   // Render and notify
1427   application.SendNotification();
1428   application.Render();
1429
1430   Vector3 position5 = cursor.GetCurrentPosition();
1431
1432   DALI_TEST_CHECK( position5.x > position4.x );
1433
1434   // Remove all the text.
1435   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1436   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1437   field.SetProperty( TextField::Property::TEXT, "" );
1438
1439   // Render and notify
1440   application.SendNotification();
1441   application.Render();
1442
1443   // Cursor position should be the same than position2.
1444   Vector3 position6 = cursor.GetCurrentPosition();
1445
1446   DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1447
1448   // Should not be a renderer.
1449   DALI_TEST_EQUALS( stencil.GetChildCount(), 0u, TEST_LOCATION );
1450
1451   END_TEST;
1452 }
1453
1454 int utcDaliTextFieldEvent03(void)
1455 {
1456   ToolkitTestApplication application;
1457   tet_infoline(" utcDaliTextFieldEvent03");
1458
1459   // Checks if the highlight actor is created.
1460
1461   TextField field = TextField::New();
1462   DALI_TEST_CHECK( field );
1463
1464   Stage::GetCurrent().Add( field );
1465
1466   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1467   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1468   field.SetSize( 30.f, 50.f );
1469   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1470   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1471
1472   // Avoid a crash when core load gl resources.
1473   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1474   LoadMarkerImages(application, field);
1475
1476   // Render and notify
1477   application.SendNotification();
1478   application.Render();
1479
1480   // Tap first to get the focus.
1481   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1482   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1483
1484   // Render and notify
1485   application.SendNotification();
1486   application.Render();
1487
1488   // Double tap to select a word.
1489   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1490   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1491
1492   // Render and notify
1493   application.SendNotification();
1494   application.Render();
1495
1496   // The offscreen root actor should have two actors: the renderer and the highlight actor.
1497   Actor stencil = field.GetChildAt( 0u );
1498
1499   // The offscreen root actor has a container with all the actors which contain the text renderers.
1500   Actor container = stencil.GetChildAt( 0u );
1501   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1502   {
1503     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1504     DALI_TEST_CHECK( renderer );
1505   }
1506
1507   Renderer highlight = stencil.GetChildAt( 1u ).GetRendererAt( 0u );
1508   DALI_TEST_CHECK( highlight );
1509
1510   END_TEST;
1511 }
1512
1513 int utcDaliTextFieldEvent04(void)
1514 {
1515   ToolkitTestApplication application;
1516   tet_infoline(" utcDaliTextFieldEvent04");
1517
1518   // Checks if the highlight actor is created.
1519
1520   TextField field = TextField::New();
1521   DALI_TEST_CHECK( field );
1522   Stage::GetCurrent().Add( field );
1523   LoadMarkerImages(application, field);
1524   // Render and notify
1525   application.SendNotification();
1526   application.Render();
1527
1528   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1529   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1530   field.SetSize( 300.f, 50.f );
1531   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1532   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1533
1534   // Avoid a crash when core load gl resources.
1535   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1536   // Render and notify
1537   application.SendNotification();
1538   application.Render();
1539
1540   // Create a tap event to touch the text field.
1541   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1542   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1543   // Render and notify
1544   application.SendNotification();
1545   application.Render();
1546
1547
1548   // Tap first to get the focus.
1549   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1550   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1551
1552   // Render and notify
1553   application.SendNotification();
1554   application.Render();
1555
1556   // Double tap to select a word.
1557   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1558   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1559
1560   // Render and notify
1561   application.SendNotification();
1562   application.Render();
1563
1564   // Tap grab handle
1565   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1566   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1567   END_TEST;
1568 }
1569
1570 int utcDaliTextFieldEvent05(void)
1571 {
1572   ToolkitTestApplication application;
1573   tet_infoline(" utcDaliTextFieldEvent05");
1574
1575   // Checks dragging of cursor/grab handle
1576
1577   TextField field = TextField::New();
1578   DALI_TEST_CHECK( field );
1579   Stage::GetCurrent().Add( field );
1580   LoadMarkerImages(application, field);
1581   // Render and notify
1582   application.SendNotification();
1583   application.Render();
1584
1585   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1586   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1587   field.SetSize( 300.f, 50.f );
1588   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1589   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1590
1591   // Avoid a crash when core load gl resources.
1592   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1593   // Render and notify
1594   application.SendNotification();
1595   application.Render();
1596
1597   // Create a tap event to touch the text field.
1598   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1599   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1600   // Render and notify
1601   application.SendNotification();
1602   application.Render();
1603
1604
1605   // Tap first to get the focus.
1606   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1607   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1608
1609   // Render and notify
1610   application.SendNotification();
1611   application.Render();
1612
1613   // Double tap to select a word.
1614   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1615   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1616
1617   // Render and notify
1618   application.SendNotification();
1619   application.Render();
1620
1621   // drag grab handle right
1622   Vector2 pos(0.0f, 40.0f);
1623   SendPan(application, Gesture::Possible, pos);
1624   SendPan(application, Gesture::Started, pos);
1625   pos.x += 5.0f;
1626   Wait(application, 100);
1627
1628   for(int i = 0;i<20;i++)
1629   {
1630     SendPan(application, Gesture::Continuing, pos);
1631     pos.x += 5.0f;
1632     Wait(application);
1633   }
1634
1635   SendPan(application, Gesture::Finished, pos);
1636   Wait(application, RENDER_FRAME_INTERVAL);
1637
1638   Actor stencil = field.GetChildAt( 1u );
1639   END_TEST;
1640 }
1641
1642 int utcDaliTextFieldEvent06(void)
1643 {
1644   ToolkitTestApplication application;
1645   tet_infoline(" utcDaliTextFieldEvent06");
1646
1647   // Checks Longpress when in edit mode
1648
1649   TextField field = TextField::New();
1650   DALI_TEST_CHECK( field );
1651   Stage::GetCurrent().Add( field );
1652   LoadMarkerImages(application, field);
1653   // Render and notify
1654   application.SendNotification();
1655   application.Render();
1656
1657   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1658   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1659   field.SetSize( 300.f, 50.f );
1660   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1661   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1662
1663   // Avoid a crash when core load gl resources.
1664   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1665   // Render and notify
1666   application.SendNotification();
1667   application.Render();
1668
1669   // Create a tap event to touch the text field.
1670   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1671   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1672   // Render and notify
1673   application.SendNotification();
1674   application.Render();
1675
1676
1677   // Tap first to get the focus.
1678   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1679   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1680
1681   // Render and notify
1682   application.SendNotification();
1683   application.Render();
1684
1685   // Long Press
1686   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1687   application.ProcessEvent( GenerateLongPress( Gesture::Started,  1u, Vector2( 1.f, 25.0f ) ) );
1688
1689   // Render and notify
1690   application.SendNotification();
1691   application.Render();
1692
1693   END_TEST;
1694 }
1695
1696 int utcDaliTextFieldEvent07(void)
1697 {
1698   ToolkitTestApplication application;
1699   tet_infoline(" utcDaliTextFieldEvent07");
1700
1701   // Checks Longpress to start edit mode
1702
1703   TextField field = TextField::New();
1704   DALI_TEST_CHECK( field );
1705   Stage::GetCurrent().Add( field );
1706   LoadMarkerImages(application, field);
1707   // Render and notify
1708   application.SendNotification();
1709   application.Render();
1710
1711   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1712   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1713   field.SetSize( 300.f, 50.f );
1714   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1715   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1716
1717   // Avoid a crash when core load gl resources.
1718   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1719   // Render and notify
1720   application.SendNotification();
1721   application.Render();
1722
1723   // Long Press
1724   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1725   application.ProcessEvent( GenerateLongPress( Gesture::Started,  1u, Vector2( 1.f, 25.0f ) ) );
1726
1727   // Render and notify
1728   application.SendNotification();
1729   application.Render();
1730
1731   END_TEST;
1732 }
1733
1734 int utcDaliTextFieldEvent08(void)
1735 {
1736   ToolkitTestApplication application;
1737   tet_infoline(" utcDaliTextFieldEvent08");
1738
1739   Dali::Clipboard clipboard = Clipboard::Get();
1740   clipboard.SetItem("testTextFieldEvent");
1741
1742   // Checks Longpress when only place holder text
1743
1744   TextField field = TextField::New();
1745   DALI_TEST_CHECK( field );
1746   Stage::GetCurrent().Add( field );
1747   LoadMarkerImages(application, field);
1748   // Render and notify
1749   application.SendNotification();
1750   application.Render();
1751
1752   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
1753   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1754   field.SetSize( 300.f, 50.f );
1755   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1756   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1757
1758   // Avoid a crash when core load gl resources.
1759   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1760   // Render and notify
1761   application.SendNotification();
1762   application.Render();
1763
1764   // Long Press
1765   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1766   application.ProcessEvent( GenerateLongPress( Gesture::Started,  1u, Vector2( 1.f, 25.0f ) ) );
1767
1768   // Render and notify
1769   application.SendNotification();
1770   application.Render();
1771
1772   Wait(application, 500);
1773
1774   Stage stage = Stage::GetCurrent();
1775   Layer layer = stage.GetRootLayer();
1776   Actor actor = layer.FindChildByName("optionPaste");
1777
1778   if (actor)
1779   {
1780     Vector3 worldPosition = actor.GetCurrentWorldPosition();
1781     Vector2 halfStageSize = stage.GetSize() / 2.0f;
1782     Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
1783
1784     Dali::Integration::TouchEvent event;
1785     event = Dali::Integration::TouchEvent();
1786     event.AddPoint( GetPointDownInside( position ) );
1787     application.ProcessEvent( event );
1788
1789     event = Dali::Integration::TouchEvent();
1790     event.AddPoint( GetPointUpInside( position ) );
1791     application.ProcessEvent( event );
1792   }
1793   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
1794   END_TEST;
1795 }
1796
1797 int utcDaliTextFieldStyleWhilstSelected(void)
1798 {
1799   ToolkitTestApplication application;
1800   tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
1801
1802   // Change font and styles whilst text is selected whilst word selected
1803
1804   TextField field = TextField::New();
1805   DALI_TEST_CHECK( field );
1806   Stage::GetCurrent().Add( field );
1807   LoadMarkerImages(application, field);
1808   // Render and notify
1809   application.SendNotification();
1810   application.Render();
1811
1812   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1813   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1814   field.SetSize( 300.f, 50.f );
1815   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1816   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1817
1818   // Avoid a crash when core load gl resources.
1819   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1820   // Render and notify
1821   application.SendNotification();
1822   application.Render();
1823
1824   // Create a tap event to touch the text field.
1825   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1826   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1827   // Render and notify
1828   application.SendNotification();
1829   application.Render();
1830
1831
1832   // Tap first to get the focus.
1833   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1834   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1835
1836   // Render and notify
1837   application.SendNotification();
1838   application.Render();
1839
1840   // Double tap to select a word.
1841   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1842   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1843
1844   // Render and notify
1845   application.SendNotification();
1846   application.Render();
1847
1848   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
1849   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
1850
1851   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1852   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1853
1854   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, "{\"width\":\"expanded\",\"slant\":\"italic\"}" );
1855   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_STYLE ), "{\"width\":\"expanded\",\"slant\":\"italic\"}", TEST_LOCATION );
1856
1857   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
1858   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1859
1860   field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
1861   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
1862
1863   field.SetProperty( TextField::Property::FONT_STYLE, "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
1864   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"weight\":\"bold\",\"slant\":\"italic\"}", TEST_LOCATION );
1865
1866   field.SetProperty( TextField::Property::FONT_STYLE, "{\"width\":\"expanded\"}" );
1867   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::FONT_STYLE ), "{\"width\":\"expanded\"}", TEST_LOCATION );
1868
1869   END_TEST;
1870 }
1871
1872 int utcDaliTextFieldCursorVisibility(void)
1873 {
1874   ToolkitTestApplication application;
1875   tet_infoline(" utcDaliTextFieldCursorVisibility");
1876
1877   // Load a font.
1878
1879   char* pathNamePtr = get_current_dir_name();
1880   const std::string pathName( pathNamePtr );
1881   free( pathNamePtr );
1882
1883   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1884   fontClient.SetDpi( 93u, 93u );
1885
1886   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" );
1887   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansHebrewRegular.ttf" );
1888
1889   // Checks if the right number of actors are created.
1890
1891   TextField field = TextField::New();
1892   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1893   DALI_TEST_CHECK( field );
1894
1895   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1896   field.SetProperty( TextField::Property::TEXT, "<font family='TizenSans' size='18'>Hello <font family='TizenSansHebrew' size='18'>שלום עולם</font> world</font>" );
1897
1898   Stage::GetCurrent().Add( field );
1899
1900   field.SetSize( 300.f, 30.f );
1901   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1902   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1903
1904   // Avoid a crash when core load gl resources.
1905   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1906
1907   // Render and notify
1908   application.SendNotification();
1909   application.Render();
1910
1911   // Check there are the expected number of children ( stencil ).
1912   DALI_TEST_EQUALS( field.GetChildCount(), 1u, TEST_LOCATION );
1913
1914   Actor stencil = field.GetChildAt( 0u );
1915   DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The text renderer.
1916
1917   // Create a tap event to touch the text field.
1918   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 56.0f, 25.0f ) ) );
1919   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 56.0f, 25.0f ) ) );
1920
1921   // Render and notify
1922   application.SendNotification();
1923   application.Render();
1924
1925   Actor layer = field.GetChildAt( 1u );
1926   DALI_TEST_CHECK( layer.IsLayer() );
1927
1928   DALI_TEST_EQUALS( layer.GetChildCount(), 2u, TEST_LOCATION ); // The two cursors.
1929   DALI_TEST_EQUALS( stencil.GetChildCount(), 1u, TEST_LOCATION ); // The text renderer.
1930
1931   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1932   DALI_TEST_CHECK( cursor );
1933
1934   Vector3 size = cursor.GetCurrentSize();
1935   Vector3 position = cursor.GetCurrentPosition();
1936
1937   DALI_TEST_EQUALS( position, Vector3(56.f, 0.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1938   DALI_TEST_EQUALS( size, Vector3(1.f, 14.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1939
1940   // Change the size of the control (with a height smaller than the size of the cursor).
1941   field.SetSize( 300.f, 20.f );
1942
1943   // Create a tap event to touch the text field.
1944   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 56.0f, 15.0f ) ) );
1945   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 56.0f, 15.0f ) ) );
1946
1947   // Render and notify
1948   application.SendNotification();
1949   application.Render();
1950
1951   size = cursor.GetCurrentSize();
1952   position = cursor.GetCurrentPosition();
1953
1954   // Checks the size of the cursor fits the control's height.
1955   DALI_TEST_EQUALS( position, Vector3(56.f, 0.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1956   DALI_TEST_EQUALS( size, Vector3(1.f, 5.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1957
1958   // Change the size of the control (with a height smaller than the size of the secondary cursor).
1959   field.SetSize( 300.f, 10.f );
1960
1961   // Create a tap event to touch the text field.
1962   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 56.0f, 5.0f ) ) );
1963   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 56.0f, 5.0f ) ) );
1964
1965   // Render and notify
1966   application.SendNotification();
1967   application.Render();
1968
1969   Control cursor2 = Control::DownCast( layer.GetChildAt( 1u ) );
1970   DALI_TEST_CHECK( cursor2 );
1971
1972   size = cursor2.GetCurrentSize();
1973   position = cursor2.GetCurrentPosition();
1974
1975   // Checks the size of the cursor fits the control's height.
1976   DALI_TEST_EQUALS( position, Vector3(155.f, 0.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1977   DALI_TEST_EQUALS( size, Vector3(1.f, 10.f, 0.f), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1978
1979   END_TEST;
1980 }