Text - UNDERLINE, SHADOW, INPUT_UNDERLINE and INPUT_SHADOW properties refactor.
[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   // Set a different exceed policy is not implemented.
589
590   // Check that the Alignment properties can be correctly set
591   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "END" );
592   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
593   field.SetProperty( TextField::Property::VERTICAL_ALIGNMENT, "CENTER" );
594   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::VERTICAL_ALIGNMENT ), "CENTER", TEST_LOCATION );
595
596   // Check text's color property
597   field.SetProperty( TextField::Property::TEXT_COLOR, Color::WHITE );
598   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
599
600   // Check placeholder text's color property.
601   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::RED );
602   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PLACEHOLDER_TEXT_COLOR ), Color::RED, TEST_LOCATION );
603
604   // Check shadow properties.
605   field.SetProperty( TextField::Property::SHADOW_OFFSET, Vector2( 1.f, 1.f ) );
606   DALI_TEST_EQUALS( field.GetProperty<Vector2>( TextField::Property::SHADOW_OFFSET ), Vector2( 1.f, 1.f ), TEST_LOCATION );
607   field.SetProperty( TextField::Property::SHADOW_COLOR, Color::GREEN );
608   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SHADOW_COLOR ), Color::GREEN, TEST_LOCATION );
609
610   // Check cursor properties
611   field.SetProperty( TextField::Property::PRIMARY_CURSOR_COLOR, Color::RED );
612   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
613   field.SetProperty( TextField::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
614   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
615
616   field.SetProperty( TextField::Property::ENABLE_CURSOR_BLINK, false );
617   DALI_TEST_EQUALS( field.GetProperty<bool>( TextField::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
618   field.SetProperty( TextField::Property::CURSOR_BLINK_INTERVAL, 1.f );
619   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
620   field.SetProperty( TextField::Property::CURSOR_BLINK_DURATION, 10.f );
621   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
622   field.SetProperty( TextField::Property::CURSOR_WIDTH, 1 );
623   DALI_TEST_EQUALS( field.GetProperty<int>( TextField::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
624
625   // Check scroll properties.
626   field.SetProperty( TextField::Property::SCROLL_THRESHOLD, 1.f );
627   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
628   field.SetProperty( TextField::Property::SCROLL_SPEED, 100.f );
629   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
630
631   // Check handle images
632   field.SetProperty( TextField::Property::GRAB_HANDLE_IMAGE, "image1" );
633   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
634   field.SetProperty( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
635   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
636   field.SetProperty( TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
637
638   // Check handle images
639   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" )  );
640   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" )  );
641   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" )  );
642   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" )  );
643   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" )  );
644   DALI_TEST_CHECK( SetPropertyMapRetrieved( field, TextField::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" )  );
645
646   // Check the highlight color
647   field.SetProperty( TextField::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
648   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
649
650   // Decoration bounding box
651   field.SetProperty( TextField::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
652   DALI_TEST_EQUALS( field.GetProperty<Rect <int > >( TextField::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
653
654   // Check input color property.
655   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
656   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
657
658   // Check the enable markup property.
659   DALI_TEST_CHECK( !field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
660   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
661   DALI_TEST_CHECK( field.GetProperty<bool>( TextField::Property::ENABLE_MARKUP ) );
662
663   // Check input font properties.
664   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
665   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
666
667   fontStyleMapSet.Clear();
668   fontStyleMapSet.Insert( "weight", "bold" );
669   fontStyleMapSet.Insert( "width", "condensed" );
670   fontStyleMapSet.Insert( "slant", "italic" );
671
672   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
673   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
674   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
675   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
676
677   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
678   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
679
680   // Reset input font style.
681   fontStyleMapSet.Clear();
682   fontStyleMapSet.Insert( "weight", "normal" );
683   fontStyleMapSet.Insert( "slant", "oblique" );
684
685   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
686   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
687   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
688   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
689
690   fontStyleMapSet.Clear();
691   fontStyleMapSet.Insert( "slant", "roman" );
692
693   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
694   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
695
696   // Replace 'roman' for 'normal'.
697   slantValue = fontStyleMapGet.Find( "slant" );
698   if( NULL != slantValue )
699   {
700     if( "normal" == slantValue->Get<std::string>() )
701     {
702       fontStyleMapGet["slant"] = "roman";
703     }
704   }
705   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
706   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
707
708   fontStyleMapSet.Clear();
709
710   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
711   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
712   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
713   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
714
715   Property::Map underlineMapSet;
716   Property::Map underlineMapGet;
717
718   underlineMapSet.Insert( "enable", "true" );
719   underlineMapSet.Insert( "color", "red" );
720   underlineMapSet.Insert( "height", "1" );
721
722   // Check the underline property
723   field.SetProperty( TextField::Property::UNDERLINE, underlineMapSet );
724
725   underlineMapGet = field.GetProperty<Property::Map>( TextField::Property::UNDERLINE );
726   DALI_TEST_EQUALS( underlineMapGet.Count(), underlineMapSet.Count(), TEST_LOCATION );
727   DALI_TEST_EQUALS( DaliTestCheckMaps( underlineMapGet, underlineMapSet ), true, TEST_LOCATION );
728
729   // Check the input underline property
730   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "Underline input properties" );
731   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
732
733   // Check the shadow property
734   Property::Map shadowMapSet;
735   Property::Map shadowMapGet;
736
737   shadowMapSet.Insert( "color", "green" );
738   shadowMapSet.Insert( "offset", "2 2" );
739
740   field.SetProperty( TextField::Property::SHADOW, shadowMapSet );
741
742   shadowMapGet = field.GetProperty<Property::Map>( TextField::Property::SHADOW );
743   DALI_TEST_EQUALS( shadowMapGet.Count(), shadowMapSet.Count(), TEST_LOCATION );
744   DALI_TEST_EQUALS( DaliTestCheckMaps( shadowMapGet, shadowMapSet ), true, TEST_LOCATION );
745
746   // Check the input shadow property
747   field.SetProperty( TextField::Property::INPUT_SHADOW, "Shadow input properties" );
748   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
749
750   // Check the emboss property
751   field.SetProperty( TextField::Property::EMBOSS, "Emboss properties" );
752   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
753
754   // Check the input emboss property
755   field.SetProperty( TextField::Property::INPUT_EMBOSS, "Emboss input properties" );
756   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
757
758   // Check the outline property
759   field.SetProperty( TextField::Property::OUTLINE, "Outline properties" );
760   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
761
762   // Check the input outline property
763   field.SetProperty( TextField::Property::INPUT_OUTLINE, "Outline input properties" );
764   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
765
766   END_TEST;
767 }
768
769 // Positive Atlas Text Renderer test
770 int utcDaliTextFieldAtlasRenderP(void)
771 {
772   ToolkitTestApplication application;
773   tet_infoline(" UtcDaliToolkitTextFieldAtlasRenderP");
774   StyleManager styleManager = StyleManager::Get();
775   styleManager.ApplyDefaultTheme();
776   TextField field = TextField::New();
777   DALI_TEST_CHECK( field );
778
779   field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
780
781   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
782
783   Stage::GetCurrent().Add( field );
784
785   try
786   {
787     // Render some text with the shared atlas backend
788     field.SetProperty( TextField::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
789     application.SendNotification();
790     application.Render();
791   }
792   catch( ... )
793   {
794     tet_result(TET_FAIL);
795   }
796   END_TEST;
797 }
798
799 // Positive test for the textChanged signal.
800 int utcDaliTextFieldTextChangedP(void)
801 {
802   ToolkitTestApplication application;
803   tet_infoline(" utcDaliTextFieldTextChangedP");
804   TextField field = TextField::New();
805   DALI_TEST_CHECK( field );
806
807   Stage::GetCurrent().Add( field );
808
809   // connect to the text changed signal.
810   ConnectionTracker* testTracker = new ConnectionTracker();
811   field.TextChangedSignal().Connect(&TestTextChangedCallback);
812   bool textChangedSignal = false;
813   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
814
815   gTextChangedCallBackCalled = false;
816   field.SetProperty( TextField::Property::TEXT, "ABC" );
817   DALI_TEST_CHECK( gTextChangedCallBackCalled );
818   DALI_TEST_CHECK( textChangedSignal );
819
820   application.SendNotification();
821
822   field.SetKeyInputFocus();
823
824   gTextChangedCallBackCalled = false;
825   application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
826   DALI_TEST_CHECK( gTextChangedCallBackCalled );
827
828   END_TEST;
829 }
830
831 // Negative test for the textChanged signal.
832 int utcDaliTextFieldTextChangedN(void)
833 {
834   ToolkitTestApplication application;
835   tet_infoline(" utcDaliTextFieldTextChangedN");
836   TextField field = TextField::New();
837   DALI_TEST_CHECK( field );
838
839   Stage::GetCurrent().Add( field );
840
841   // connect to the text changed signal.
842   ConnectionTracker* testTracker = new ConnectionTracker();
843   field.TextChangedSignal().Connect(&TestTextChangedCallback);
844   bool textChangedSignal = false;
845   field.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
846
847   gTextChangedCallBackCalled = false;
848   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "ABC" ); // Setting placeholder, not TEXT
849   DALI_TEST_CHECK( !gTextChangedCallBackCalled );
850   DALI_TEST_CHECK( !textChangedSignal );
851
852   END_TEST;
853 }
854
855 // Positive test for Max Characters reached signal.
856 int utcDaliTextFieldMaxCharactersReachedP(void)
857 {
858   ToolkitTestApplication application;
859   tet_infoline(" utcDaliTextFieldMaxCharactersReachedP");
860   TextField field = TextField::New();
861   DALI_TEST_CHECK( field );
862
863   Stage::GetCurrent().Add( field );
864
865   const int maxNumberOfCharacters = 1;
866   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
867
868   field.SetKeyInputFocus();
869
870   // connect to the text changed signal.
871   ConnectionTracker* testTracker = new ConnectionTracker();
872   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
873   bool maxLengthReachedSignal = false;
874   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
875
876   gMaxCharactersCallBackCalled = false;
877
878   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
879   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
880
881   DALI_TEST_CHECK( gMaxCharactersCallBackCalled );
882   DALI_TEST_CHECK( maxLengthReachedSignal );
883
884   END_TEST;
885 }
886
887 // Negative test for Max Characters reached signal.
888 int utcDaliTextFieldMaxCharactersReachedN(void)
889 {
890   ToolkitTestApplication application;
891   tet_infoline(" utcDaliTextFieldMaxCharactersReachedN");
892   TextField field = TextField::New();
893   DALI_TEST_CHECK( field );
894
895   Stage::GetCurrent().Add( field );
896
897   const int maxNumberOfCharacters = 3;
898   field.SetProperty( TextField::Property::MAX_LENGTH, maxNumberOfCharacters );
899
900   field.SetKeyInputFocus();
901
902   // connect to the text changed signal.
903   ConnectionTracker* testTracker = new ConnectionTracker();
904   field.MaxLengthReachedSignal().Connect(&TestMaxLengthReachedCallback);
905   bool maxLengthReachedSignal = false;
906   field.ConnectSignal( testTracker, "maxLengthReached",   CallbackFunctor(&maxLengthReachedSignal) );
907
908   gMaxCharactersCallBackCalled = false;
909
910   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
911   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
912
913   DALI_TEST_CHECK( !gMaxCharactersCallBackCalled );
914   DALI_TEST_CHECK( !maxLengthReachedSignal );
915
916   END_TEST;
917 }
918
919 int utcDaliTextFieldInputStyleChanged01(void)
920 {
921   ToolkitTestApplication application;
922   tet_infoline(" utcDaliTextFieldInputStyleChanged01");
923
924   // The text-field emits signals when the input style changes. These changes of style are
925   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
926   // can't be emitted during the size negotiation as the callbacks may update the UI.
927   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
928   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
929   application.CreateAdaptor();
930
931   // Load some fonts.
932
933   char* pathNamePtr = get_current_dir_name();
934   const std::string pathName( pathNamePtr );
935   free( pathNamePtr );
936
937   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
938   fontClient.SetDpi( 93u, 93u );
939
940   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
941   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
942
943   TextField field = TextField::New();
944   DALI_TEST_CHECK( field );
945
946
947   field.SetSize( 300.f, 50.f );
948   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
949   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
950
951   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
952   field.SetProperty( TextField::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
953
954   // connect to the text changed signal.
955   ConnectionTracker* testTracker = new ConnectionTracker();
956   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
957   bool inputStyleChangedSignal = false;
958   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
959
960   Stage::GetCurrent().Add( field );
961
962   // Render and notify
963   application.SendNotification();
964   application.Render();
965
966   // Executes the idle callbacks added by the text control on the change of input style.
967   application.RunIdles();
968
969   gInputStyleChangedCallbackCalled = false;
970   gInputStyleMask = TextField::InputStyle::NONE;
971   inputStyleChangedSignal = false;
972
973   // Create a tap event to touch the text field.
974   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
975   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
976
977   // Render and notify
978   application.SendNotification();
979   application.Render();
980
981   // Executes the idle callbacks added by the text control on the change of input style.
982   application.RunIdles();
983
984   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
985   if( gInputStyleChangedCallbackCalled )
986   {
987     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY | TextField::InputStyle::POINT_SIZE ), TEST_LOCATION );
988
989     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
990     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
991
992     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
993     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
994   }
995   DALI_TEST_CHECK( inputStyleChangedSignal );
996
997   gInputStyleChangedCallbackCalled = false;
998   gInputStyleMask = TextField::InputStyle::NONE;
999   inputStyleChangedSignal = false;
1000
1001   // Create a tap event to touch the text field.
1002   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1003   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1004
1005   // Render and notify
1006   application.SendNotification();
1007   application.Render();
1008
1009   // Executes the idle callbacks added by the text control on the change of input style.
1010   application.RunIdles();
1011
1012   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1013   DALI_TEST_CHECK( !inputStyleChangedSignal );
1014
1015   gInputStyleChangedCallbackCalled = false;
1016   gInputStyleMask = TextField::InputStyle::NONE;
1017   inputStyleChangedSignal = false;
1018
1019   // Create a tap event to touch the text field.
1020   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1021   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
1022
1023   // Render and notify
1024   application.SendNotification();
1025   application.Render();
1026
1027   // Executes the idle callbacks added by the text control on the change of input style.
1028   application.RunIdles();
1029
1030   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1031   if( gInputStyleChangedCallbackCalled )
1032   {
1033     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR ), TEST_LOCATION );
1034
1035     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1036     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1037   }
1038   DALI_TEST_CHECK( inputStyleChangedSignal );
1039
1040   gInputStyleChangedCallbackCalled = false;
1041   gInputStyleMask = TextField::InputStyle::NONE;
1042   inputStyleChangedSignal = false;
1043
1044   // Create a tap event to touch the text field.
1045   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1046   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
1047
1048   // Render and notify
1049   application.SendNotification();
1050   application.Render();
1051
1052   // Executes the idle callbacks added by the text control on the change of input style.
1053   application.RunIdles();
1054
1055   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1056   if( gInputStyleChangedCallbackCalled )
1057   {
1058     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::COLOR | TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1059
1060     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1061     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1062
1063     const Property::Map fontStyleMapGet = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<Property::Map>();
1064
1065     Property::Map fontStyleMapSet;
1066     fontStyleMapSet.Insert( "weight", "bold" );
1067
1068     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1069     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1070   }
1071   DALI_TEST_CHECK( inputStyleChangedSignal );
1072
1073   gInputStyleChangedCallbackCalled = false;
1074   gInputStyleMask = TextField::InputStyle::NONE;
1075   inputStyleChangedSignal = false;
1076
1077   // Create a tap event to touch the text field.
1078   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1079   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
1080
1081   // Render and notify
1082   application.SendNotification();
1083   application.Render();
1084
1085   // Executes the idle callbacks added by the text control on the change of input style.
1086   application.RunIdles();
1087
1088   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1089   DALI_TEST_CHECK( !inputStyleChangedSignal );
1090
1091   gInputStyleChangedCallbackCalled = false;
1092   gInputStyleMask = TextField::InputStyle::NONE;
1093   inputStyleChangedSignal = false;
1094
1095   // Create a tap event to touch the text field.
1096   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1097   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
1098
1099   // Render and notify
1100   application.SendNotification();
1101   application.Render();
1102
1103   // Executes the idle callbacks added by the text control on the change of input style.
1104   application.RunIdles();
1105
1106   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1107   if( gInputStyleChangedCallbackCalled )
1108   {
1109     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextField::InputStyle::FONT_STYLE ), TEST_LOCATION );
1110
1111     const std::string style = field.GetProperty( TextField::Property::INPUT_FONT_STYLE ).Get<std::string>();
1112     DALI_TEST_CHECK( style.empty() );
1113   }
1114   DALI_TEST_CHECK( inputStyleChangedSignal );
1115
1116   gInputStyleChangedCallbackCalled = false;
1117   gInputStyleMask = TextField::InputStyle::NONE;
1118   inputStyleChangedSignal = false;
1119
1120   // Create a tap event to touch the text field.
1121   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1122   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
1123
1124   // Render and notify
1125   application.SendNotification();
1126   application.Render();
1127
1128   // Executes the idle callbacks added by the text control on the change of input style.
1129   application.RunIdles();
1130
1131   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1132   DALI_TEST_CHECK( !inputStyleChangedSignal );
1133
1134   END_TEST;
1135 }
1136
1137 int utcDaliTextFieldInputStyleChanged02(void)
1138 {
1139   ToolkitTestApplication application;
1140   tet_infoline(" utcDaliTextFieldInputStyleChanged02");
1141
1142   // The text-field emits signals when the input style changes. These changes of style are
1143   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
1144   // can't be emitted during the size negotiation as the callbacks may update the UI.
1145   // The text-field adds an idle callback to the adaptor to emit the signals after the size negotiation.
1146   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
1147   application.CreateAdaptor();
1148
1149   // Load some fonts.
1150
1151   char* pathNamePtr = get_current_dir_name();
1152   const std::string pathName( pathNamePtr );
1153   free( pathNamePtr );
1154
1155   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
1156   fontClient.SetDpi( 93u, 93u );
1157
1158   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
1159   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
1160
1161   TextField field = TextField::New();
1162   DALI_TEST_CHECK( field );
1163
1164
1165   field.SetSize( 300.f, 50.f );
1166   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1167   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1168
1169   field.SetProperty( TextField::Property::ENABLE_MARKUP, true );
1170   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>" );
1171
1172   // connect to the text changed signal.
1173   ConnectionTracker* testTracker = new ConnectionTracker();
1174   field.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
1175   bool inputStyleChangedSignal = false;
1176   field.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
1177
1178   Stage::GetCurrent().Add( field );
1179
1180   // Render and notify
1181   application.SendNotification();
1182   application.Render();
1183
1184   // Executes the idle callbacks added by the text control on the change of input style.
1185   application.RunIdles();
1186
1187   gInputStyleChangedCallbackCalled = false;
1188   gInputStyleMask = TextField::InputStyle::NONE;
1189   inputStyleChangedSignal = false;
1190
1191   // Create a tap event to touch the text field.
1192   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1193   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
1194   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1195   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
1196
1197   // Render and notify
1198   application.SendNotification();
1199   application.Render();
1200
1201   // Executes the idle callbacks added by the text control on the change of input style.
1202   application.RunIdles();
1203
1204   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1205   if( gInputStyleChangedCallbackCalled )
1206   {
1207     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1208                       static_cast<unsigned int>( TextField::InputStyle::FONT_FAMILY |
1209                                                  TextField::InputStyle::POINT_SIZE  |
1210                                                  TextField::InputStyle::COLOR ),
1211                       TEST_LOCATION );
1212
1213     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1214     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
1215
1216     const std::string fontFamily = field.GetProperty( TextField::Property::INPUT_FONT_FAMILY ).Get<std::string>();
1217     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
1218
1219     const float pointSize = field.GetProperty( TextField::Property::INPUT_POINT_SIZE ).Get<float>();
1220     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
1221   }
1222   DALI_TEST_CHECK( inputStyleChangedSignal );
1223
1224   gInputStyleChangedCallbackCalled = false;
1225   gInputStyleMask = TextField::InputStyle::NONE;
1226   inputStyleChangedSignal = false;
1227
1228   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1229
1230   // Render and notify
1231   application.SendNotification();
1232   application.Render();
1233
1234   // Executes the idle callbacks added by the text control on the change of input style.
1235   application.RunIdles();
1236
1237   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1238   if( gInputStyleChangedCallbackCalled )
1239   {
1240     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1241                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1242                       TEST_LOCATION );
1243
1244     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1245     DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
1246   }
1247   DALI_TEST_CHECK( inputStyleChangedSignal );
1248
1249   gInputStyleChangedCallbackCalled = false;
1250   gInputStyleMask = TextField::InputStyle::NONE;
1251   inputStyleChangedSignal = false;
1252
1253   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1254
1255   // Render and notify
1256   application.SendNotification();
1257   application.Render();
1258
1259   // Executes the idle callbacks added by the text control on the change of input style.
1260   application.RunIdles();
1261
1262   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1263   DALI_TEST_CHECK( !inputStyleChangedSignal );
1264
1265   gInputStyleChangedCallbackCalled = false;
1266   gInputStyleMask = TextField::InputStyle::NONE;
1267   inputStyleChangedSignal = false;
1268
1269   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1270
1271   // Render and notify
1272   application.SendNotification();
1273   application.Render();
1274
1275   // Executes the idle callbacks added by the text control on the change of input style.
1276   application.RunIdles();
1277
1278   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1279   if( gInputStyleChangedCallbackCalled )
1280   {
1281     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1282                       static_cast<unsigned int>( TextField::InputStyle::COLOR ),
1283                       TEST_LOCATION );
1284
1285     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1286     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1287   }
1288   DALI_TEST_CHECK( inputStyleChangedSignal );
1289
1290   gInputStyleChangedCallbackCalled = false;
1291   gInputStyleMask = TextField::InputStyle::NONE;
1292   inputStyleChangedSignal = false;
1293
1294   field.SetProperty( TextField::Property::INPUT_COLOR, Color::YELLOW );
1295
1296   Property::Map fontStyleMapSet;
1297   fontStyleMapSet.Insert( "weight", "thin" );
1298   fontStyleMapSet.Insert( "width", "condensed" );
1299   fontStyleMapSet.Insert( "slant", "italic" );
1300
1301   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1302   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 20.f );
1303
1304   field.SetProperty( TextField::Property::INPUT_UNDERLINE, "underline" );
1305   field.SetProperty( TextField::Property::INPUT_SHADOW, "shadow" );
1306   field.SetProperty( TextField::Property::INPUT_EMBOSS, "emboss" );
1307   field.SetProperty( TextField::Property::INPUT_OUTLINE, "outline" );
1308
1309   // Render and notify
1310   application.SendNotification();
1311   application.Render();
1312
1313   // Executes the idle callbacks added by the text control on the change of input style.
1314   application.RunIdles();
1315
1316   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1317   DALI_TEST_CHECK( !inputStyleChangedSignal );
1318
1319   // Create a tap event to touch the text field.
1320   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1321   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1322
1323   // Render and notify
1324   application.SendNotification();
1325   application.Render();
1326
1327   // Executes the idle callbacks added by the text control on the change of input style.
1328   application.RunIdles();
1329
1330   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1331   if( gInputStyleChangedCallbackCalled )
1332   {
1333     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1334                       static_cast<unsigned int>( TextField::InputStyle::COLOR |
1335                                                  TextField::InputStyle::POINT_SIZE |
1336                                                  TextField::InputStyle::FONT_STYLE |
1337                                                  TextField::InputStyle::UNDERLINE |
1338                                                  TextField::InputStyle::SHADOW |
1339                                                  TextField::InputStyle::EMBOSS |
1340                                                  TextField::InputStyle::OUTLINE ),
1341                       TEST_LOCATION );
1342
1343     const Vector4 color = field.GetProperty( TextField::Property::INPUT_COLOR ).Get<Vector4>();
1344     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1345   }
1346   DALI_TEST_CHECK( inputStyleChangedSignal );
1347
1348   END_TEST;
1349 }
1350
1351 int utcDaliTextFieldEvent01(void)
1352 {
1353   ToolkitTestApplication application;
1354   tet_infoline(" utcDaliTextFieldEvent01");
1355
1356   // Creates a tap event. After creating a tap event the text field should
1357   // have the focus and add text with key events should be possible.
1358
1359   TextField field = TextField::New();
1360   DALI_TEST_CHECK( field );
1361
1362   Stage::GetCurrent().Add( field );
1363
1364   field.SetSize( 300.f, 50.f );
1365   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1366   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1367
1368   // Avoid a crash when core load gl resources.
1369   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1370
1371   // Render and notify
1372   application.SendNotification();
1373   application.Render();
1374
1375   // Add a key event but as the text field has not the focus it should do nothing.
1376   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1377
1378   // Render and notify
1379   application.SendNotification();
1380   application.Render();
1381
1382   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string(""), TEST_LOCATION );
1383
1384   // Create a tap event to touch the text field.
1385   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1386   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1387
1388   // Render and notify
1389   application.SendNotification();
1390   application.Render();
1391
1392   // Now the text field has the focus, so it can handle the key events.
1393   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1394   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1395
1396   // Render and notify
1397   application.SendNotification();
1398   application.Render();
1399
1400   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1401
1402   // Create a second text field and send key events to it.
1403   TextField field2 = TextField::New();
1404
1405   field2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1406   field2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1407   field2.SetSize( 100.f, 100.f );
1408   field2.SetPosition( 100.f, 100.f );
1409
1410   Stage::GetCurrent().Add( field2 );
1411
1412   // Render and notify
1413   application.SendNotification();
1414   application.Render();
1415
1416   // Create a tap event on the second text field.
1417   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1418   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1419
1420   // Render and notify
1421   application.SendNotification();
1422   application.Render();
1423
1424   // The second text field has the focus. It should handle the key events.
1425   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1426   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1427
1428   // Render and notify
1429   application.SendNotification();
1430   application.Render();
1431
1432   // Check the text has been added to the second text field.
1433   DALI_TEST_EQUALS( field2.GetProperty<std::string>( TextField::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1434
1435   END_TEST;
1436 }
1437
1438 int utcDaliTextFieldEvent02(void)
1439 {
1440   ToolkitTestApplication application;
1441   tet_infoline(" utcDaliTextFieldEvent02");
1442
1443   // Checks if the right number of actors are created.
1444
1445   TextField field = TextField::New();
1446   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1447   DALI_TEST_CHECK( field );
1448   LoadMarkerImages(application, field);
1449
1450   Stage::GetCurrent().Add( field );
1451
1452   field.SetSize( 300.f, 50.f );
1453   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1454   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1455
1456   // Avoid a crash when core load gl resources.
1457   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1458
1459   // Render and notify
1460   application.SendNotification();
1461   application.Render();
1462
1463   // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
1464   DALI_TEST_EQUALS( field.GetChildCount(), 2u, TEST_LOCATION );
1465
1466   Actor offscreenRoot = field.GetChildAt( 0u );
1467   DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1468   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1469
1470   Actor offscreenImage = field.GetChildAt( 1u );
1471   DALI_TEST_CHECK( offscreenImage );
1472
1473   // Create a tap event to touch the text field.
1474   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1475   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1476
1477   // Render and notify
1478   application.SendNotification();
1479   application.Render();
1480
1481   Actor layer = field.GetChildAt( 2u );
1482   DALI_TEST_CHECK( layer.IsLayer() );
1483
1484   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1485   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1486
1487   // Now the text field has the focus, so it can handle the key events.
1488   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1489   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1490
1491   // Render and notify
1492   application.SendNotification();
1493   application.Render();
1494
1495   // Checks the cursor and the renderer have been created.
1496   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1497   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
1498
1499   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1500   DALI_TEST_CHECK( cursor );
1501
1502   CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1503   DALI_TEST_CHECK( camera );
1504
1505   // The offscreen root actor has a container with all the actors which contain the text renderers.
1506   Actor container = offscreenRoot.GetChildAt( 1u );
1507   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1508   {
1509     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1510     DALI_TEST_CHECK( renderer );
1511   }
1512
1513   // Move the cursor and check the position changes.
1514   Vector3 position1 = cursor.GetCurrentPosition();
1515
1516   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1517   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1518
1519   // Render and notify
1520   application.SendNotification();
1521   application.Render();
1522
1523   Vector3 position2 = cursor.GetCurrentPosition();
1524
1525   DALI_TEST_CHECK( position2.x < position1.x );
1526
1527   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1528   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1529
1530   // Render and notify
1531   application.SendNotification();
1532   application.Render();
1533
1534   Vector3 position3 = cursor.GetCurrentPosition();
1535
1536   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1537
1538   // Send some taps and check the cursor positions.
1539
1540   // Try to tap at the beginning.
1541   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1542   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1543
1544   // Render and notify
1545   application.SendNotification();
1546   application.Render();
1547
1548   // Cursor position should be the same than position1.
1549   Vector3 position4 = cursor.GetCurrentPosition();
1550
1551   DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1552
1553   // Tap away from the start position.
1554   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1555   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1556
1557   // Render and notify
1558   application.SendNotification();
1559   application.Render();
1560
1561   Vector3 position5 = cursor.GetCurrentPosition();
1562
1563   DALI_TEST_CHECK( position5.x > position4.x );
1564
1565   // Remove all the text.
1566   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1567   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1568   field.SetProperty( TextField::Property::TEXT, "" );
1569
1570   // Render and notify
1571   application.SendNotification();
1572   application.Render();
1573
1574   // Cursor position should be the same than position2.
1575   Vector3 position6 = cursor.GetCurrentPosition();
1576
1577   DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1578
1579   // Should not be a renderer.
1580   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
1581
1582   END_TEST;
1583 }
1584
1585 int utcDaliTextFieldEvent03(void)
1586 {
1587   ToolkitTestApplication application;
1588   tet_infoline(" utcDaliTextFieldEvent03");
1589
1590   // Checks if the highlight actor is created.
1591
1592   TextField field = TextField::New();
1593   DALI_TEST_CHECK( field );
1594
1595   Stage::GetCurrent().Add( field );
1596
1597   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1598   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1599   field.SetSize( 30.f, 50.f );
1600   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1601   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1602
1603   // Avoid a crash when core load gl resources.
1604   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1605   LoadMarkerImages(application, field);
1606
1607   // Render and notify
1608   application.SendNotification();
1609   application.Render();
1610
1611   // Tap first to get the focus.
1612   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1613   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1614
1615   // Render and notify
1616   application.SendNotification();
1617   application.Render();
1618
1619   // Double tap to select a word.
1620   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1621   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1622
1623   // Render and notify
1624   application.SendNotification();
1625   application.Render();
1626
1627   // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
1628   Actor offscreenRoot = field.GetChildAt( 1u );
1629   DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1630
1631   CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1632   DALI_TEST_CHECK( camera );
1633
1634   // The offscreen root actor has a container with all the actors which contain the text renderers.
1635   Actor container = offscreenRoot.GetChildAt( 1u );
1636   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1637   {
1638     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1639     DALI_TEST_CHECK( renderer );
1640   }
1641
1642   Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
1643   DALI_TEST_CHECK( highlight );
1644
1645   END_TEST;
1646 }
1647
1648 int utcDaliTextFieldEvent04(void)
1649 {
1650   ToolkitTestApplication application;
1651   tet_infoline(" utcDaliTextFieldEvent04");
1652
1653   // Checks if the highlight actor is created.
1654
1655   TextField field = TextField::New();
1656   DALI_TEST_CHECK( field );
1657   Stage::GetCurrent().Add( field );
1658   LoadMarkerImages(application, field);
1659   // Render and notify
1660   application.SendNotification();
1661   application.Render();
1662
1663   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1664   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1665   field.SetSize( 300.f, 50.f );
1666   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1667   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1668
1669   // Avoid a crash when core load gl resources.
1670   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1671   // Render and notify
1672   application.SendNotification();
1673   application.Render();
1674
1675   // Create a tap event to touch the text field.
1676   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1677   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1678   // Render and notify
1679   application.SendNotification();
1680   application.Render();
1681
1682
1683   // Tap first to get the focus.
1684   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1685   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1686
1687   // Render and notify
1688   application.SendNotification();
1689   application.Render();
1690
1691   // Double tap to select a word.
1692   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1693   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1694
1695   // Render and notify
1696   application.SendNotification();
1697   application.Render();
1698
1699   // Tap grab handle
1700   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1701   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 0.f, 40.0f ) ) );
1702   END_TEST;
1703 }
1704
1705 int utcDaliTextFieldEvent05(void)
1706 {
1707   ToolkitTestApplication application;
1708   tet_infoline(" utcDaliTextFieldEvent05");
1709
1710   // Checks dragging of cursor/grab handle
1711
1712   TextField field = TextField::New();
1713   DALI_TEST_CHECK( field );
1714   Stage::GetCurrent().Add( field );
1715   LoadMarkerImages(application, field);
1716   // Render and notify
1717   application.SendNotification();
1718   application.Render();
1719
1720   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1721   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1722   field.SetSize( 300.f, 50.f );
1723   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1724   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1725
1726   // Avoid a crash when core load gl resources.
1727   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1728   // Render and notify
1729   application.SendNotification();
1730   application.Render();
1731
1732   // Create a tap event to touch the text field.
1733   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1734   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1735   // Render and notify
1736   application.SendNotification();
1737   application.Render();
1738
1739
1740   // Tap first to get the focus.
1741   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1742   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1743
1744   // Render and notify
1745   application.SendNotification();
1746   application.Render();
1747
1748   // Double tap to select a word.
1749   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1750   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1751
1752   // Render and notify
1753   application.SendNotification();
1754   application.Render();
1755
1756   // drag grab handle right
1757   Vector2 pos(0.0f, 40.0f);
1758   SendPan(application, Gesture::Possible, pos);
1759   SendPan(application, Gesture::Started, pos);
1760   pos.x += 5.0f;
1761   Wait(application, 100);
1762
1763   for(int i = 0;i<20;i++)
1764   {
1765     SendPan(application, Gesture::Continuing, pos);
1766     pos.x += 5.0f;
1767     Wait(application);
1768   }
1769
1770   SendPan(application, Gesture::Finished, pos);
1771   Wait(application, RENDER_FRAME_INTERVAL);
1772
1773   Actor offscreenRoot = field.GetChildAt( 1u );
1774   END_TEST;
1775 }
1776
1777 int utcDaliTextFieldEvent06(void)
1778 {
1779   ToolkitTestApplication application;
1780   tet_infoline(" utcDaliTextFieldEvent06");
1781
1782   // Checks Longpress when in edit mode
1783
1784   TextField field = TextField::New();
1785   DALI_TEST_CHECK( field );
1786   Stage::GetCurrent().Add( field );
1787   LoadMarkerImages(application, field);
1788   // Render and notify
1789   application.SendNotification();
1790   application.Render();
1791
1792   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1793   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1794   field.SetSize( 300.f, 50.f );
1795   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1796   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1797
1798   // Avoid a crash when core load gl resources.
1799   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1800   // Render and notify
1801   application.SendNotification();
1802   application.Render();
1803
1804   // Create a tap event to touch the text field.
1805   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1806   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1807   // Render and notify
1808   application.SendNotification();
1809   application.Render();
1810
1811
1812   // Tap first to get the focus.
1813   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1814   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1815
1816   // Render and notify
1817   application.SendNotification();
1818   application.Render();
1819
1820   // Long Press
1821   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1822   application.ProcessEvent( GenerateLongPress( Gesture::Started,  1u, Vector2( 1.f, 25.0f ) ) );
1823
1824   // Render and notify
1825   application.SendNotification();
1826   application.Render();
1827
1828   END_TEST;
1829 }
1830
1831 int utcDaliTextFieldEvent07(void)
1832 {
1833   ToolkitTestApplication application;
1834   tet_infoline(" utcDaliTextFieldEvent07");
1835
1836   // Checks Longpress to start edit mode
1837
1838   TextField field = TextField::New();
1839   DALI_TEST_CHECK( field );
1840   Stage::GetCurrent().Add( field );
1841   LoadMarkerImages(application, field);
1842   // Render and notify
1843   application.SendNotification();
1844   application.Render();
1845
1846   field.SetProperty( TextField::Property::TEXT, "Thisisalongtextforthesizeofthetextfield." );
1847   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1848   field.SetSize( 300.f, 50.f );
1849   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1850   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1851
1852   // Avoid a crash when core load gl resources.
1853   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1854   // Render and notify
1855   application.SendNotification();
1856   application.Render();
1857
1858   // Long Press
1859   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1860   application.ProcessEvent( GenerateLongPress( Gesture::Started,  1u, Vector2( 1.f, 25.0f ) ) );
1861
1862   // Render and notify
1863   application.SendNotification();
1864   application.Render();
1865
1866   END_TEST;
1867 }
1868
1869 int utcDaliTextFieldEvent08(void)
1870 {
1871   ToolkitTestApplication application;
1872   tet_infoline(" utcDaliTextFieldEvent08");
1873
1874   Dali::Clipboard clipboard = Clipboard::Get();
1875   clipboard.SetItem("testTextFieldEvent");
1876
1877   // Checks Longpress when only place holder text
1878
1879   TextField field = TextField::New();
1880   DALI_TEST_CHECK( field );
1881   Stage::GetCurrent().Add( field );
1882   LoadMarkerImages(application, field);
1883   // Render and notify
1884   application.SendNotification();
1885   application.Render();
1886
1887   field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Setting Placeholder Text" );
1888   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1889   field.SetSize( 300.f, 50.f );
1890   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1891   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1892
1893   // Avoid a crash when core load gl resources.
1894   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1895   // Render and notify
1896   application.SendNotification();
1897   application.Render();
1898
1899   // Long Press
1900   application.ProcessEvent( GenerateLongPress( Gesture::Possible, 1u, Vector2( 1.f, 25.0f ) ) );
1901   application.ProcessEvent( GenerateLongPress( Gesture::Started,  1u, Vector2( 1.f, 25.0f ) ) );
1902
1903   // Render and notify
1904   application.SendNotification();
1905   application.Render();
1906
1907   Wait(application, 500);
1908
1909   Stage stage = Stage::GetCurrent();
1910   Layer layer = stage.GetRootLayer();
1911   Actor actor = layer.FindChildByName("optionPaste");
1912
1913   if (actor)
1914   {
1915     Vector3 worldPosition = actor.GetCurrentWorldPosition();
1916     Vector2 halfStageSize = stage.GetSize() / 2.0f;
1917     Vector2 position(worldPosition.x + halfStageSize.width, worldPosition.y + halfStageSize.height);
1918
1919     Dali::Integration::TouchEvent event;
1920     event = Dali::Integration::TouchEvent();
1921     event.AddPoint( GetPointDownInside( position ) );
1922     application.ProcessEvent( event );
1923
1924     event = Dali::Integration::TouchEvent();
1925     event.AddPoint( GetPointUpInside( position ) );
1926     application.ProcessEvent( event );
1927   }
1928   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("testTextFieldEvent"), TEST_LOCATION );
1929   END_TEST;
1930 }
1931
1932 int utcDaliTextFieldStyleWhilstSelected(void)
1933 {
1934   ToolkitTestApplication application;
1935   tet_infoline(" utcDaliTextFieldStyleWhilstSelected");
1936
1937   // Change font and styles whilst text is selected whilst word selected
1938
1939   TextField field = TextField::New();
1940   DALI_TEST_CHECK( field );
1941   Stage::GetCurrent().Add( field );
1942   LoadMarkerImages(application, field);
1943   // Render and notify
1944   application.SendNotification();
1945   application.Render();
1946
1947   field.SetProperty( TextField::Property::TEXT, "This is a long text for the size of the text-field." );
1948   field.SetProperty( TextField::Property::POINT_SIZE, 10.f );
1949   field.SetSize( 300.f, 50.f );
1950   field.SetParentOrigin( ParentOrigin::TOP_LEFT );
1951   field.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1952
1953   // Avoid a crash when core load gl resources.
1954   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1955   // Render and notify
1956   application.SendNotification();
1957   application.Render();
1958
1959   // Create a tap event to touch the text field.
1960   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1961   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1962   // Render and notify
1963   application.SendNotification();
1964   application.Render();
1965
1966
1967   // Tap first to get the focus.
1968   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1969   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1970
1971   // Render and notify
1972   application.SendNotification();
1973   application.Render();
1974
1975   // Double tap to select a word.
1976   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1977   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 1.f, 25.0f ) ) );
1978
1979   // Render and notify
1980   application.SendNotification();
1981   application.Render();
1982
1983   field.SetProperty( TextField::Property::INPUT_FONT_FAMILY, "Setting input font family" );
1984   DALI_TEST_EQUALS( field.GetProperty<std::string>( TextField::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
1985
1986   Property::Map fontStyleMapSet;
1987   Property::Map fontStyleMapGet;
1988
1989   fontStyleMapSet.Insert( "weight", "bold" );
1990   fontStyleMapSet.Insert( "slant", "italic" );
1991   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1992
1993   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
1994   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
1995   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
1996
1997   fontStyleMapSet.Clear();
1998   fontStyleMapSet.Insert( "width", "expanded" );
1999   fontStyleMapSet.Insert( "slant", "italic" );
2000   field.SetProperty( TextField::Property::INPUT_FONT_STYLE, fontStyleMapSet );
2001
2002   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::INPUT_FONT_STYLE );
2003   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2004   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2005
2006   field.SetProperty( TextField::Property::INPUT_POINT_SIZE, 12.f );
2007   DALI_TEST_EQUALS( field.GetProperty<float>( TextField::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
2008
2009   field.SetProperty( TextField::Property::TEXT_COLOR, Color::RED );
2010   DALI_TEST_EQUALS( field.GetProperty<Vector4>( TextField::Property::TEXT_COLOR ), Color::RED, TEST_LOCATION );
2011
2012   fontStyleMapSet.Clear();
2013   fontStyleMapSet.Insert( "weight", "bold" );
2014   fontStyleMapSet.Insert( "slant", "italic" );
2015
2016   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2017
2018   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2019   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2020   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2021
2022   fontStyleMapSet.Clear();
2023   fontStyleMapSet.Insert( "width", "expanded" );
2024
2025   field.SetProperty( TextField::Property::FONT_STYLE, fontStyleMapSet );
2026
2027   fontStyleMapGet = field.GetProperty<Property::Map>( TextField::Property::FONT_STYLE );
2028   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
2029   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
2030
2031   END_TEST;
2032 }