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