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