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