1532883913d8217b9e83382f728ff74ce9d89e39
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-TextEditor.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <unistd.h>
21
22 #include <dali/public-api/rendering/renderer.h>
23 #include <dali/devel-api/adaptor-framework/clipboard.h>
24 #include <dali/integration-api/events/key-event-integ.h>
25 #include <dali/integration-api/events/tap-gesture-event.h>
26 #include <dali-toolkit-test-suite-utils.h>
27 #include <dali-toolkit/dali-toolkit.h>
28
29 using namespace Dali;
30 using namespace Toolkit;
31
32 void dali_texteditor_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void dali_texteditor_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44
45 const char* const PROPERTY_NAME_RENDERING_BACKEND                    = "renderingBackend";
46 const char* const PROPERTY_NAME_TEXT                                 = "text";
47 const char* const PROPERTY_NAME_TEXT_COLOR                           = "textColor";
48 const char* const PROPERTY_NAME_FONT_FAMILY                          = "fontFamily";
49 const char* const PROPERTY_NAME_FONT_STYLE                           = "fontStyle";
50 const char* const PROPERTY_NAME_POINT_SIZE                           = "pointSize";
51 const char* const PROPERTY_NAME_HORIZONTAL_ALIGNMENT                 = "horizontalAlignment";
52 const char* const PROPERTY_NAME_SCROLL_THRESHOLD                     = "scrollThreshold";
53 const char* const PROPERTY_NAME_SCROLL_SPEED                         = "scrollSpeed";
54 const char* const PROPERTY_NAME_PRIMARY_CURSOR_COLOR                 = "primaryCursorColor";
55 const char* const PROPERTY_NAME_SECONDARY_CURSOR_COLOR               = "secondaryCursorColor";
56 const char* const PROPERTY_NAME_ENABLE_CURSOR_BLINK                  = "enableCursorBlink";
57 const char* const PROPERTY_NAME_CURSOR_BLINK_INTERVAL                = "cursorBlinkInterval";
58 const char* const PROPERTY_NAME_CURSOR_BLINK_DURATION                = "cursorBlinkDuration";
59 const char* const PROPERTY_NAME_CURSOR_WIDTH                         = "cursorWidth";
60 const char* const PROPERTY_NAME_GRAB_HANDLE_IMAGE                    = "grabHandleImage";
61 const char* const PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE            = "grabHandlePressedImage";
62 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT          = "selectionHandleImageLeft";
63 const char* const PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT         = "selectionHandleImageRight";
64 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT  = "selectionHandlePressedImageLeft";
65 const char* const PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT = "selectionHandlePressedImageRight";
66 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT   = "selectionHandleMarkerImageLeft";
67 const char* const PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT  = "selectionHandleMarkerImageRight";
68 const char* const PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR            = "selectionHighlightColor";
69 const char* const PROPERTY_NAME_DECORATION_BOUNDING_BOX              = "decorationBoundingBox";
70 const char* const PROPERTY_NAME_ENABLE_MARKUP                        = "enableMarkup";
71 const char* const PROPERTY_NAME_INPUT_COLOR                          = "inputColor";
72 const char* const PROPERTY_NAME_INPUT_FONT_FAMILY                    = "inputFontFamily";
73 const char* const PROPERTY_NAME_INPUT_FONT_STYLE                     = "inputFontStyle";
74 const char* const PROPERTY_NAME_INPUT_POINT_SIZE                     = "inputPointSize";
75
76 const char* const PROPERTY_NAME_LINE_SPACING                         = "lineSpacing";
77 const char* const PROPERTY_NAME_INPUT_LINE_SPACING                   = "inputLineSpacing";
78 const char* const PROPERTY_NAME_UNDERLINE                            = "underline";
79 const char* const PROPERTY_NAME_INPUT_UNDERLINE                      = "inputUnderline";
80 const char* const PROPERTY_NAME_SHADOW                               = "shadow";
81 const char* const PROPERTY_NAME_INPUT_SHADOW                         = "inputShadow";
82 const char* const PROPERTY_NAME_EMBOSS                               = "emboss";
83 const char* const PROPERTY_NAME_INPUT_EMBOSS                         = "inputEmboss";
84 const char* const PROPERTY_NAME_OUTLINE                              = "outline";
85 const char* const PROPERTY_NAME_INPUT_OUTLINE                        = "inputOutline";
86
87 const int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
88
89 const Dali::Vector4 LIGHT_BLUE( 0.75f, 0.96f, 1.f, 1.f ); // The text highlight color.
90
91 const unsigned int CURSOR_BLINK_INTERVAL = 500u; // Cursor blink interval
92 const float TO_MILLISECONDS = 1000.f;
93 const float TO_SECONDS = 1.f / TO_MILLISECONDS;
94
95 const float SCROLL_THRESHOLD = 10.f;
96 const float SCROLL_SPEED = 300.f;
97
98 const unsigned int DEFAULT_FONT_SIZE = 1152u;
99 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
100
101 static bool gTextChangedCallBackCalled;
102 static bool gInputStyleChangedCallbackCalled;
103 static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask;
104
105 struct CallbackFunctor
106 {
107   CallbackFunctor(bool* callbackFlag)
108   : mCallbackFlag( callbackFlag )
109   {
110   }
111
112   void operator()()
113   {
114     *mCallbackFlag = true;
115   }
116   bool* mCallbackFlag;
117 };
118
119 static void TestTextChangedCallback( TextEditor control )
120 {
121   tet_infoline(" TestTextChangedCallback");
122
123   gTextChangedCallBackCalled = true;
124 }
125
126 static void TestInputStyleChangedCallback( TextEditor control, TextEditor::InputStyle::Mask mask )
127 {
128   tet_infoline(" TestInputStyleChangedCallback");
129
130   gInputStyleChangedCallbackCalled = true;
131   gInputStyleMask = mask;
132 }
133
134 // Generate a TapGestureEvent to send to Core.
135 Integration::TapGestureEvent GenerateTap(
136     Gesture::State state,
137     unsigned int numberOfTaps,
138     unsigned int numberOfTouches,
139     Vector2 point)
140 {
141   Integration::TapGestureEvent tap( state );
142
143   tap.numberOfTaps = numberOfTaps;
144   tap.numberOfTouches = numberOfTouches;
145   tap.point = point;
146
147   return tap;
148 }
149
150 // Generate a KeyEvent to send to Core.
151 Integration::KeyEvent GenerateKey( const std::string& keyName,
152                                    const std::string& keyString,
153                                    int keyCode,
154                                    int keyModifier,
155                                    unsigned long timeStamp,
156                                    const Integration::KeyEvent::State& keyState )
157 {
158   return Integration::KeyEvent( keyName,
159                                 keyString,
160                                 keyCode,
161                                 keyModifier,
162                                 timeStamp,
163                                 keyState );
164 }
165
166 bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Map& fontStyleMapSet )
167 {
168   if( fontStyleMapGet.Count() == fontStyleMapSet.Count() )
169   {
170     for( unsigned int index = 0u; index < fontStyleMapGet.Count(); ++index )
171     {
172       const KeyValuePair& valueGet = fontStyleMapGet.GetKeyValue( index );
173
174       Property::Value* valueSet = fontStyleMapSet.Find( valueGet.first.stringKey );
175       if( NULL != valueSet )
176       {
177         if( valueGet.second.Get<std::string>() != valueSet->Get<std::string>() )
178         {
179           tet_printf( "  Value got : [%s], expected : [%s]", valueGet.second.Get<std::string>().c_str(), valueSet->Get<std::string>().c_str() );
180           return false;
181         }
182       }
183       else
184       {
185         tet_printf( "  The key %s doesn't exist.", valueGet.first.stringKey.c_str() );
186         return false;
187       }
188     }
189   }
190
191   return true;
192 }
193
194 } // namespace
195
196 int UtcDaliToolkitTextEditorConstructorP(void)
197 {
198   ToolkitTestApplication application;
199   tet_infoline(" UtcDaliToolkitTextEditorConstructorP");
200   TextEditor textEditor;
201   DALI_TEST_CHECK( !textEditor );
202   END_TEST;
203 }
204
205 int UtcDaliToolkitTextEditorNewP(void)
206 {
207   ToolkitTestApplication application;
208   tet_infoline(" UtcDaliToolkitTextEditorNewP");
209   TextEditor textEditor = TextEditor::New();
210   DALI_TEST_CHECK( textEditor );
211   END_TEST;
212 }
213
214 int UtcDaliToolkitTextEditorDownCastP(void)
215 {
216   ToolkitTestApplication application;
217   tet_infoline(" UtcDaliToolkitTextEditorDownCastP");
218   TextEditor textEditor1 = TextEditor::New();
219   BaseHandle object( textEditor1 );
220
221   TextEditor textEditor2 = TextEditor::DownCast( object );
222   DALI_TEST_CHECK( textEditor2 );
223
224   TextEditor textEditor3 = DownCast< TextEditor >( object );
225   DALI_TEST_CHECK( textEditor3 );
226   END_TEST;
227 }
228
229 int UtcDaliToolkitTextEditorDownCastN(void)
230 {
231   ToolkitTestApplication application;
232   tet_infoline(" UtcDaliToolkitTextEditorDownCastN");
233   BaseHandle uninitializedObject;
234   TextEditor textEditor1 = TextEditor::DownCast( uninitializedObject );
235   DALI_TEST_CHECK( !textEditor1 );
236
237   TextEditor textEditor2 = DownCast< TextEditor >( uninitializedObject );
238   DALI_TEST_CHECK( !textEditor2 );
239   END_TEST;
240 }
241
242 int UtcDaliToolkitTextEditorCopyConstructorP(void)
243 {
244   ToolkitTestApplication application;
245   tet_infoline(" UtcDaliToolkitTextEditorCopyConstructorP");
246   TextEditor textEditor = TextEditor::New();
247   textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
248
249   TextEditor copy( textEditor );
250   DALI_TEST_CHECK( copy );
251   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
252   END_TEST;
253 }
254
255 int UtcDaliToolkitTextEditorAssignmentOperatorP(void)
256 {
257   ToolkitTestApplication application;
258   tet_infoline(" UtcDaliToolkitTextEditorAssignmentOperatorP");
259   TextEditor textEditor = TextEditor::New();
260   textEditor.SetProperty( TextEditor::Property::TEXT, "Test" );
261
262   TextEditor copy = textEditor;
263   DALI_TEST_CHECK( copy );
264   DALI_TEST_CHECK( copy.GetProperty<std::string>( TextEditor::Property::TEXT ) == textEditor.GetProperty<std::string>( TextEditor::Property::TEXT ) );
265   END_TEST;
266 }
267
268 int UtcDaliTextEditorNewP(void)
269 {
270   ToolkitTestApplication application;
271   tet_infoline(" UtcDaliToolkitTextEditorNewP");
272   TextEditor textEditor = TextEditor::New();
273   DALI_TEST_CHECK( textEditor );
274   END_TEST;
275 }
276
277 // Positive test case for a method
278 int UtcDaliTextEditorGetPropertyP(void)
279 {
280   ToolkitTestApplication application;
281   tet_infoline(" UtcDaliToolkitTextEditorGetPropertyP");
282   TextEditor editor = TextEditor::New();
283   DALI_TEST_CHECK( editor );
284
285   // Check Property Indices are correct
286   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_RENDERING_BACKEND ) == TextEditor::Property::RENDERING_BACKEND );
287   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT ) == TextEditor::Property::TEXT );
288   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_TEXT_COLOR ) == TextEditor::Property::TEXT_COLOR );
289   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_FAMILY ) == TextEditor::Property::FONT_FAMILY );
290   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_FONT_STYLE ) == TextEditor::Property::FONT_STYLE );
291   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_POINT_SIZE ) == TextEditor::Property::POINT_SIZE );
292   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_HORIZONTAL_ALIGNMENT ) == TextEditor::Property::HORIZONTAL_ALIGNMENT );
293   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_THRESHOLD ) == TextEditor::Property::SCROLL_THRESHOLD );
294   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SCROLL_SPEED ) == TextEditor::Property::SCROLL_SPEED );
295   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_PRIMARY_CURSOR_COLOR ) == TextEditor::Property::PRIMARY_CURSOR_COLOR );
296   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SECONDARY_CURSOR_COLOR ) == TextEditor::Property::SECONDARY_CURSOR_COLOR );
297   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_CURSOR_BLINK ) == TextEditor::Property::ENABLE_CURSOR_BLINK );
298   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_INTERVAL ) == TextEditor::Property::CURSOR_BLINK_INTERVAL );
299   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_BLINK_DURATION ) == TextEditor::Property::CURSOR_BLINK_DURATION );
300   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_CURSOR_WIDTH ) == TextEditor::Property::CURSOR_WIDTH );
301   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_IMAGE ) == TextEditor::Property::GRAB_HANDLE_IMAGE );
302   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_GRAB_HANDLE_PRESSED_IMAGE ) == TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE );
303   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT );
304   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT );
305   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT );
306   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_PRESSED_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT );
307   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_LEFT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT );
308   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HANDLE_MARKER_IMAGE_RIGHT ) == TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT );
309   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SELECTION_HIGHLIGHT_COLOR ) == TextEditor::Property::SELECTION_HIGHLIGHT_COLOR );
310   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_DECORATION_BOUNDING_BOX ) == TextEditor::Property::DECORATION_BOUNDING_BOX );
311   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_MARKUP ) == TextEditor::Property::ENABLE_MARKUP );
312   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_COLOR ) == TextEditor::Property::INPUT_COLOR );
313   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_FAMILY ) == TextEditor::Property::INPUT_FONT_FAMILY );
314   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_FONT_STYLE ) == TextEditor::Property::INPUT_FONT_STYLE );
315   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_POINT_SIZE ) == TextEditor::Property::INPUT_POINT_SIZE );
316
317   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_LINE_SPACING ) == TextEditor::Property::LINE_SPACING );
318   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_LINE_SPACING ) == TextEditor::Property::INPUT_LINE_SPACING );
319   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_UNDERLINE ) == TextEditor::Property::UNDERLINE );
320   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_UNDERLINE ) == TextEditor::Property::INPUT_UNDERLINE );
321   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_SHADOW ) == TextEditor::Property::SHADOW );
322   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_SHADOW ) == TextEditor::Property::INPUT_SHADOW );
323   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_EMBOSS ) == TextEditor::Property::EMBOSS );
324   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_EMBOSS ) == TextEditor::Property::INPUT_EMBOSS );
325   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_OUTLINE ) == TextEditor::Property::OUTLINE );
326   DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_INPUT_OUTLINE ) == TextEditor::Property::INPUT_OUTLINE );
327
328   END_TEST;
329 }
330
331 bool SetPropertyMapRetrieved( TextEditor& editor, const Property::Index property, const std::string mapKey, const std::string mapValue )
332 {
333   bool result = false;
334   Property::Map imageMap;
335   imageMap[mapKey] =mapValue;
336
337   editor.SetProperty( property , imageMap );
338   Property::Value propValue = editor.GetProperty( property );
339   Property::Map* resultMap = propValue.GetMap();
340
341   if ( resultMap->Find( mapKey )->Get< std::string>() == mapValue )
342   {
343     result = true;
344   }
345
346   return result;
347 }
348
349 // Positive test case for a method
350 int UtcDaliTextEditorSetPropertyP(void)
351 {
352   ToolkitTestApplication application;
353   tet_infoline(" UtcDaliToolkitTextEditorSetPropertyP");
354   TextEditor editor = TextEditor::New();
355   DALI_TEST_CHECK( editor );
356   Stage::GetCurrent().Add( editor );
357
358   // Note - we can't check the defaults since the stylesheets are platform-specific
359
360   // Check the render backend property.
361   editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
362   DALI_TEST_EQUALS( (Text::RenderingType)editor.GetProperty<int>( TextEditor::Property::RENDERING_BACKEND ), Text::RENDERING_SHARED_ATLAS, TEST_LOCATION );
363
364   // Check text property.
365   editor.SetProperty( TextEditor::Property::TEXT, "Setting Text" );
366   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("Setting Text"), TEST_LOCATION );
367
368   // Check text's color property
369   editor.SetProperty( TextEditor::Property::TEXT_COLOR, Color::WHITE );
370   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::TEXT_COLOR ), Color::WHITE, TEST_LOCATION );
371
372   // Check font properties.
373   editor.SetProperty( TextEditor::Property::FONT_FAMILY, "Setting font family" );
374   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::FONT_FAMILY ), std::string("Setting font family"), TEST_LOCATION );
375
376   Property::Map fontStyleMapSet;
377   Property::Map fontStyleMapGet;
378   Property::Value* slantValue = NULL;
379
380   fontStyleMapSet.Insert( "weight", "bold" );
381   fontStyleMapSet.Insert( "width", "condensed" );
382   fontStyleMapSet.Insert( "slant", "italic" );
383
384   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
385   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
386   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
387   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
388
389   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
390   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::POINT_SIZE ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
391
392   // Reset font style.
393   fontStyleMapSet.Clear();
394   fontStyleMapSet.Insert( "weight", "normal" );
395   fontStyleMapSet.Insert( "slant", "oblique" );
396   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
397   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
398   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
399   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
400
401   fontStyleMapSet.Clear();
402   fontStyleMapSet.Insert( "slant", "roman" );
403   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
404   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
405
406   // Replace 'roman' for 'normal'.
407   slantValue = fontStyleMapGet.Find( "slant" );
408   if( NULL != slantValue )
409   {
410     if( "normal" == slantValue->Get<std::string>() )
411     {
412       fontStyleMapGet["slant"] = "roman";
413     }
414   }
415   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
416   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
417
418   fontStyleMapSet.Clear();
419
420   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
421   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::FONT_STYLE );
422   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
423   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
424
425   // Check that the Alignment properties can be correctly set
426   editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "END" );
427   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::HORIZONTAL_ALIGNMENT ), "END", TEST_LOCATION );
428
429   // Check scroll properties.
430   editor.SetProperty( TextEditor::Property::SCROLL_THRESHOLD, 1.f );
431   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_THRESHOLD ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
432   editor.SetProperty( TextEditor::Property::SCROLL_SPEED, 100.f );
433   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::SCROLL_SPEED ), 100.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
434
435   // Check cursor properties
436   editor.SetProperty( TextEditor::Property::PRIMARY_CURSOR_COLOR, Color::RED );
437   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::PRIMARY_CURSOR_COLOR ), Color::RED, TEST_LOCATION );
438   editor.SetProperty( TextEditor::Property::SECONDARY_CURSOR_COLOR, Color::BLUE );
439   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SECONDARY_CURSOR_COLOR ), Color::BLUE, TEST_LOCATION );
440
441   editor.SetProperty( TextEditor::Property::ENABLE_CURSOR_BLINK, false );
442   DALI_TEST_EQUALS( editor.GetProperty<bool>( TextEditor::Property::ENABLE_CURSOR_BLINK ), false, TEST_LOCATION );
443   editor.SetProperty( TextEditor::Property::CURSOR_BLINK_INTERVAL, 1.f );
444   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_INTERVAL ), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
445   editor.SetProperty( TextEditor::Property::CURSOR_BLINK_DURATION, 10.f );
446   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::CURSOR_BLINK_DURATION ), 10.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
447   editor.SetProperty( TextEditor::Property::CURSOR_WIDTH, 1 );
448   DALI_TEST_EQUALS( editor.GetProperty<int>( TextEditor::Property::CURSOR_WIDTH ), 1, TEST_LOCATION );
449
450   // Check handle images
451   editor.SetProperty( TextEditor::Property::GRAB_HANDLE_IMAGE, "image1" );
452   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_IMAGE ), "image1", TEST_LOCATION );
453   editor.SetProperty( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE, "image2" );
454   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::GRAB_HANDLE_PRESSED_IMAGE ), "image2", TEST_LOCATION );
455   editor.SetProperty( TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "image3" );
456
457   // Check handle images
458   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_LEFT, "filename", "leftHandleImage" )  );
459   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_IMAGE_RIGHT, "filename", "rightHandleImage" )  );
460   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_LEFT, "filename", "leftHandleImagePressed" )  );
461   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_PRESSED_IMAGE_RIGHT, "filename", "rightHandleImagePressed" )  );
462   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_LEFT, "filename", "leftHandleMarkerImage" )  );
463   DALI_TEST_CHECK( SetPropertyMapRetrieved( editor, TextEditor::Property::SELECTION_HANDLE_MARKER_IMAGE_RIGHT, "filename", "rightHandleMarkerImage" )  );
464
465   // Check the highlight color
466   editor.SetProperty( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR, Color::GREEN );
467   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::SELECTION_HIGHLIGHT_COLOR ), Color::GREEN, TEST_LOCATION );
468
469   // Decoration bounding box
470   editor.SetProperty( TextEditor::Property::DECORATION_BOUNDING_BOX, Rect<int>( 0, 0, 1, 1 ) );
471   DALI_TEST_EQUALS( editor.GetProperty<Rect <int > >( TextEditor::Property::DECORATION_BOUNDING_BOX ), Rect<int>( 0, 0, 1, 1 ), TEST_LOCATION );
472
473   // Check the enable markup property.
474   DALI_TEST_CHECK( !editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
475   editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
476   DALI_TEST_CHECK( editor.GetProperty<bool>( TextEditor::Property::ENABLE_MARKUP ) );
477
478   // Check input color property.
479   editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
480   DALI_TEST_EQUALS( editor.GetProperty<Vector4>( TextEditor::Property::INPUT_COLOR ), Color::YELLOW, TEST_LOCATION );
481
482   // Check input font properties.
483   editor.SetProperty( TextEditor::Property::INPUT_FONT_FAMILY, "Setting input font family" );
484   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_FONT_FAMILY ), "Setting input font family", TEST_LOCATION );
485
486   fontStyleMapSet.Clear();
487   fontStyleMapSet.Insert( "weight", "bold" );
488   fontStyleMapSet.Insert( "width", "condensed" );
489   fontStyleMapSet.Insert( "slant", "italic" );
490
491   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
492   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
493   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
494   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
495
496   editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 12.f );
497   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_POINT_SIZE ), 12.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
498
499   // Reset input font style.
500   fontStyleMapSet.Clear();
501   fontStyleMapSet.Insert( "weight", "normal" );
502   fontStyleMapSet.Insert( "slant", "oblique" );
503
504   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
505   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
506   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
507   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
508
509   fontStyleMapSet.Clear();
510   fontStyleMapSet.Insert( "slant", "roman" );
511
512   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
513   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
514
515   // Replace 'roman' for 'normal'.
516   slantValue = fontStyleMapGet.Find( "slant" );
517   if( NULL != slantValue )
518   {
519     if( "normal" == slantValue->Get<std::string>() )
520     {
521       fontStyleMapGet["slant"] = "roman";
522     }
523   }
524   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
525   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
526
527   fontStyleMapSet.Clear();
528
529   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
530   fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
531   DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
532   DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
533
534   // Check the line spacing property
535   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
536   editor.SetProperty( TextEditor::Property::LINE_SPACING, 10.f );
537   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::LINE_SPACING ), 10.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
538
539   // Check the input line spacing property
540   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 0.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
541   editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 20.f );
542   DALI_TEST_EQUALS( editor.GetProperty<float>( TextEditor::Property::INPUT_LINE_SPACING ), 20.0f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
543
544   // Check the underline property
545   editor.SetProperty( TextEditor::Property::UNDERLINE, "{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}" );
546   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::UNDERLINE ), std::string("{\"enable\":\"true\",\"color\":\"red\",\"height\":\"1\"}"), TEST_LOCATION );
547
548   // Check the input underline property
549   editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "Underline input properties" );
550   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_UNDERLINE ), std::string("Underline input properties"), TEST_LOCATION );
551
552   // Check the shadow property
553   editor.SetProperty( TextEditor::Property::SHADOW, "{\"color\":\"green\",\"offset\":\"2 2\"}" );
554   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::SHADOW ), std::string("{\"color\":\"green\",\"offset\":\"2 2\"}"), TEST_LOCATION );
555
556   // Check the input shadow property
557   editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "Shadow input properties" );
558   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_SHADOW ), std::string("Shadow input properties"), TEST_LOCATION );
559
560   // Check the emboss property
561   editor.SetProperty( TextEditor::Property::EMBOSS, "Emboss properties" );
562   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::EMBOSS ), std::string("Emboss properties"), TEST_LOCATION );
563
564   // Check the input emboss property
565   editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "Emboss input properties" );
566   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_EMBOSS ), std::string("Emboss input properties"), TEST_LOCATION );
567
568   // Check the outline property
569   editor.SetProperty( TextEditor::Property::OUTLINE, "Outline properties" );
570   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::OUTLINE ), std::string("Outline properties"), TEST_LOCATION );
571
572   // Check the input outline property
573   editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "Outline input properties" );
574   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::INPUT_OUTLINE ), std::string("Outline input properties"), TEST_LOCATION );
575
576   END_TEST;
577 }
578
579 // Positive Atlas Text Renderer test
580 int utcDaliTextEditorAtlasRenderP(void)
581 {
582   ToolkitTestApplication application;
583   tet_infoline(" UtcDaliToolkitTextEditorAtlasRenderP");
584   StyleManager styleManager = StyleManager::Get();
585   styleManager.ApplyDefaultTheme();
586   TextEditor editor = TextEditor::New();
587   DALI_TEST_CHECK( editor );
588
589   editor.SetProperty( TextEditor::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
590
591   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
592
593   Stage::GetCurrent().Add( editor );
594
595   try
596   {
597     // Render some text with the shared atlas backend
598     editor.SetProperty( TextEditor::Property::RENDERING_BACKEND, Text::RENDERING_SHARED_ATLAS );
599     application.SendNotification();
600     application.Render();
601   }
602   catch( ... )
603   {
604     tet_result(TET_FAIL);
605   }
606   END_TEST;
607 }
608
609 // Positive test for the textChanged signal.
610 int utcDaliTextEditorTextChangedP(void)
611 {
612   ToolkitTestApplication application;
613   tet_infoline(" utcDaliTextEditorTextChangedP");
614   TextEditor editor = TextEditor::New();
615   DALI_TEST_CHECK( editor );
616
617   Stage::GetCurrent().Add( editor );
618
619   // connect to the text changed signal.
620   ConnectionTracker* testTracker = new ConnectionTracker();
621   editor.TextChangedSignal().Connect( &TestTextChangedCallback );
622   bool textChangedSignal = false;
623   editor.ConnectSignal( testTracker, "textChanged",   CallbackFunctor(&textChangedSignal) );
624
625   gTextChangedCallBackCalled = false;
626   editor.SetProperty( TextEditor::Property::TEXT, "ABC" );
627   DALI_TEST_CHECK( gTextChangedCallBackCalled );
628   DALI_TEST_CHECK( textChangedSignal );
629
630   application.SendNotification();
631
632   editor.SetKeyInputFocus();
633
634   gTextChangedCallBackCalled = false;
635   application.ProcessEvent( GenerateKey( "D", "D", 0, 0, 0, Integration::KeyEvent::Down ) );
636   DALI_TEST_CHECK( gTextChangedCallBackCalled );
637
638   END_TEST;
639 }
640
641 int utcDaliTextEditorInputStyleChanged01(void)
642 {
643   ToolkitTestApplication application;
644   tet_infoline(" utcDaliTextEditorInputStyleChanged01");
645
646   // The text-editor emits signals when the input style changes. These changes of style are
647   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
648   // can't be emitted during the size negotiation as the callbacks may update the UI.
649   // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
650   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
651   application.CreateAdaptor();
652
653   // Load some fonts.
654
655   char* pathNamePtr = get_current_dir_name();
656   const std::string pathName( pathNamePtr );
657   free( pathNamePtr );
658
659   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
660   fontClient.SetDpi( 93u, 93u );
661
662   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
663   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
664
665   TextEditor editor = TextEditor::New();
666   DALI_TEST_CHECK( editor );
667
668
669   editor.SetSize( 300.f, 50.f );
670   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
671   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
672
673   editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
674   editor.SetProperty( TextEditor::Property::TEXT, "<font family='DejaVuSerif' size='18'>He<color value='green'>llo</color> <font weight='bold'>world</font> demo</font>" );
675
676   // connect to the text changed signal.
677   ConnectionTracker* testTracker = new ConnectionTracker();
678   editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
679   bool inputStyleChangedSignal = false;
680   editor.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
681
682   Stage::GetCurrent().Add( editor );
683
684   // Render and notify
685   application.SendNotification();
686   application.Render();
687
688   // Executes the idle callbacks added by the text control on the change of input style.
689   application.RunIdles();
690
691   gInputStyleChangedCallbackCalled = false;
692   gInputStyleMask = TextEditor::InputStyle::NONE;
693   inputStyleChangedSignal = false;
694
695   // Create a tap event to touch the text editor.
696   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 18.f, 25.f ) ) );
697   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 18.f, 25.f ) ) );
698
699   // Render and notify
700   application.SendNotification();
701   application.Render();
702
703   // Executes the idle callbacks added by the text control on the change of input style.
704   application.RunIdles();
705
706   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
707   if( gInputStyleChangedCallbackCalled )
708   {
709     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY | TextEditor::InputStyle::POINT_SIZE ), TEST_LOCATION );
710
711     const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
712     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
713
714     const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
715     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
716   }
717   DALI_TEST_CHECK( inputStyleChangedSignal );
718
719   gInputStyleChangedCallbackCalled = false;
720   gInputStyleMask = TextEditor::InputStyle::NONE;
721   inputStyleChangedSignal = false;
722
723   // Create a tap event to touch the text editor.
724   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
725   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
726
727   // Render and notify
728   application.SendNotification();
729   application.Render();
730
731   // Executes the idle callbacks added by the text control on the change of input style.
732   application.RunIdles();
733
734   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
735   DALI_TEST_CHECK( !inputStyleChangedSignal );
736
737   gInputStyleChangedCallbackCalled = false;
738   gInputStyleMask = TextEditor::InputStyle::NONE;
739   inputStyleChangedSignal = false;
740
741   // Create a tap event to touch the text editor.
742   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 43.f, 25.f ) ) );
743   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 43.f, 25.f ) ) );
744
745   // Render and notify
746   application.SendNotification();
747   application.Render();
748
749   // Executes the idle callbacks added by the text control on the change of input style.
750   application.RunIdles();
751
752   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
753   if( gInputStyleChangedCallbackCalled )
754   {
755     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR ), TEST_LOCATION );
756
757     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
758     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
759   }
760   DALI_TEST_CHECK( inputStyleChangedSignal );
761
762   gInputStyleChangedCallbackCalled = false;
763   gInputStyleMask = TextEditor::InputStyle::NONE;
764   inputStyleChangedSignal = false;
765
766   // Create a tap event to touch the text editor.
767   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 88.f, 25.f ) ) );
768   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 88.f, 25.f ) ) );
769
770   // Render and notify
771   application.SendNotification();
772   application.Render();
773
774   // Executes the idle callbacks added by the text control on the change of input style.
775   application.RunIdles();
776
777   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
778   if( gInputStyleChangedCallbackCalled )
779   {
780     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::COLOR | TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
781
782     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
783     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
784
785     Property::Map fontStyleMapSet;
786     Property::Map fontStyleMapGet;
787
788     fontStyleMapSet.Insert( "weight", "bold" );
789
790     fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
791     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
792     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
793   }
794   DALI_TEST_CHECK( inputStyleChangedSignal );
795
796   gInputStyleChangedCallbackCalled = false;
797   gInputStyleMask = TextEditor::InputStyle::NONE;
798   inputStyleChangedSignal = false;
799
800   // Create a tap event to touch the text editor.
801   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 115.f, 25.f ) ) );
802   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 115.f, 25.f ) ) );
803
804   // Render and notify
805   application.SendNotification();
806   application.Render();
807
808   // Executes the idle callbacks added by the text control on the change of input style.
809   application.RunIdles();
810
811   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
812   DALI_TEST_CHECK( !inputStyleChangedSignal );
813
814   gInputStyleChangedCallbackCalled = false;
815   gInputStyleMask = TextEditor::InputStyle::NONE;
816   inputStyleChangedSignal = false;
817
818   // Create a tap event to touch the text editor.
819   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 164.f, 25.f ) ) );
820   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 164.f, 25.f ) ) );
821
822   // Render and notify
823   application.SendNotification();
824   application.Render();
825
826   // Executes the idle callbacks added by the text control on the change of input style.
827   application.RunIdles();
828
829   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
830   if( gInputStyleChangedCallbackCalled )
831   {
832     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ), static_cast<unsigned int>( TextEditor::InputStyle::FONT_STYLE ), TEST_LOCATION );
833
834     Property::Map fontStyleMapSet;
835     Property::Map fontStyleMapGet;
836
837     fontStyleMapGet = editor.GetProperty<Property::Map>( TextEditor::Property::INPUT_FONT_STYLE );
838     DALI_TEST_EQUALS( fontStyleMapGet.Count(), fontStyleMapSet.Count(), TEST_LOCATION );
839     DALI_TEST_EQUALS( DaliTestCheckMaps( fontStyleMapGet, fontStyleMapSet ), true, TEST_LOCATION );
840   }
841   DALI_TEST_CHECK( inputStyleChangedSignal );
842
843   gInputStyleChangedCallbackCalled = false;
844   gInputStyleMask = TextEditor::InputStyle::NONE;
845   inputStyleChangedSignal = false;
846
847   // Create a tap event to touch the text editor.
848   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 191.f, 25.f ) ) );
849   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 191.f, 25.f ) ) );
850
851   // Render and notify
852   application.SendNotification();
853   application.Render();
854
855   // Executes the idle callbacks added by the text control on the change of input style.
856   application.RunIdles();
857
858   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
859   DALI_TEST_CHECK( !inputStyleChangedSignal );
860
861   END_TEST;
862 }
863
864 int utcDaliTextEditorInputStyleChanged02(void)
865 {
866   ToolkitTestApplication application;
867   tet_infoline(" utcDaliTextEditorInputStyleChanged02");
868
869   // The text-editor emits signals when the input style changes. These changes of style are
870   // detected during the relayout process (size negotiation), i.e after the cursor has been moved. Signals
871   // can't be emitted during the size negotiation as the callbacks may update the UI.
872   // The text-editor adds an idle callback to the adaptor to emit the signals after the size negotiation.
873   // This creates an implementation of the adaptor stub and a queue of idle callbacks.
874   application.CreateAdaptor();
875
876   // Load some fonts.
877
878   char* pathNamePtr = get_current_dir_name();
879   const std::string pathName( pathNamePtr );
880   free( pathNamePtr );
881
882   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
883   fontClient.SetDpi( 93u, 93u );
884
885   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif.ttf", DEFAULT_FONT_SIZE );
886   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/dejavu/DejaVuSerif-Bold.ttf", DEFAULT_FONT_SIZE );
887
888   TextEditor editor = TextEditor::New();
889   DALI_TEST_CHECK( editor );
890
891
892   editor.SetSize( 300.f, 50.f );
893   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
894   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
895
896   editor.SetProperty( TextEditor::Property::ENABLE_MARKUP, true );
897   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>" );
898
899   // connect to the text changed signal.
900   ConnectionTracker* testTracker = new ConnectionTracker();
901   editor.InputStyleChangedSignal().Connect( &TestInputStyleChangedCallback );
902   bool inputStyleChangedSignal = false;
903   editor.ConnectSignal( testTracker, "inputStyleChanged",   CallbackFunctor(&inputStyleChangedSignal) );
904
905   Stage::GetCurrent().Add( editor );
906
907   // Render and notify
908   application.SendNotification();
909   application.Render();
910
911   // Executes the idle callbacks added by the text control on the change of input style.
912   application.RunIdles();
913
914   gInputStyleChangedCallbackCalled = false;
915   gInputStyleMask = TextEditor::InputStyle::NONE;
916   inputStyleChangedSignal = false;
917
918   // Create a tap event to touch the text editor.
919   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 53.f, 25.f ) ) );
920   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 53.f, 25.f ) ) );
921   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 53.f, 25.f ) ) );
922   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 53.f, 25.f ) ) );
923
924   // Render and notify
925   application.SendNotification();
926   application.Render();
927
928   // Executes the idle callbacks added by the text control on the change of input style.
929   application.RunIdles();
930
931   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
932   if( gInputStyleChangedCallbackCalled )
933   {
934     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
935                       static_cast<unsigned int>( TextEditor::InputStyle::FONT_FAMILY |
936                                                  TextEditor::InputStyle::POINT_SIZE  |
937                                                  TextEditor::InputStyle::COLOR ),
938                       TEST_LOCATION );
939
940     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
941     DALI_TEST_EQUALS( color, Color::GREEN, TEST_LOCATION );
942
943     const std::string fontFamily = editor.GetProperty( TextEditor::Property::INPUT_FONT_FAMILY ).Get<std::string>();
944     DALI_TEST_EQUALS( fontFamily, "DejaVuSerif", TEST_LOCATION );
945
946     const float pointSize = editor.GetProperty( TextEditor::Property::INPUT_POINT_SIZE ).Get<float>();
947     DALI_TEST_EQUALS( pointSize, 18.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
948   }
949   DALI_TEST_CHECK( inputStyleChangedSignal );
950
951   gInputStyleChangedCallbackCalled = false;
952   gInputStyleMask = TextEditor::InputStyle::NONE;
953   inputStyleChangedSignal = false;
954
955   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
956
957   // Render and notify
958   application.SendNotification();
959   application.Render();
960
961   // Executes the idle callbacks added by the text control on the change of input style.
962   application.RunIdles();
963
964   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
965   if( gInputStyleChangedCallbackCalled )
966   {
967     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
968                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
969                       TEST_LOCATION );
970
971     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
972     DALI_TEST_EQUALS( color, Color::BLUE, TEST_LOCATION );
973   }
974   DALI_TEST_CHECK( inputStyleChangedSignal );
975
976   gInputStyleChangedCallbackCalled = false;
977   gInputStyleMask = TextEditor::InputStyle::NONE;
978   inputStyleChangedSignal = false;
979
980   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
981
982   // Render and notify
983   application.SendNotification();
984   application.Render();
985
986   // Executes the idle callbacks added by the text control on the change of input style.
987   application.RunIdles();
988
989   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
990   DALI_TEST_CHECK( !inputStyleChangedSignal );
991
992   gInputStyleChangedCallbackCalled = false;
993   gInputStyleMask = TextEditor::InputStyle::NONE;
994   inputStyleChangedSignal = false;
995
996   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
997
998   // Render and notify
999   application.SendNotification();
1000   application.Render();
1001
1002   // Executes the idle callbacks added by the text control on the change of input style.
1003   application.RunIdles();
1004
1005   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1006   if( gInputStyleChangedCallbackCalled )
1007   {
1008     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1009                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR ),
1010                       TEST_LOCATION );
1011
1012     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1013     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1014   }
1015   DALI_TEST_CHECK( inputStyleChangedSignal );
1016
1017   gInputStyleChangedCallbackCalled = false;
1018   gInputStyleMask = TextEditor::InputStyle::NONE;
1019   inputStyleChangedSignal = false;
1020
1021   editor.SetProperty( TextEditor::Property::INPUT_COLOR, Color::YELLOW );
1022
1023   Property::Map fontStyleMapSet;
1024   fontStyleMapSet.Insert( "weight", "thin" );
1025   fontStyleMapSet.Insert( "width", "condensed" );
1026   fontStyleMapSet.Insert( "slant", "italic" );
1027
1028   editor.SetProperty( TextEditor::Property::INPUT_FONT_STYLE, fontStyleMapSet );
1029   editor.SetProperty( TextEditor::Property::INPUT_POINT_SIZE, 20.f );
1030   editor.SetProperty( TextEditor::Property::INPUT_LINE_SPACING, 5.f );
1031
1032   editor.SetProperty( TextEditor::Property::INPUT_UNDERLINE, "underline" );
1033   editor.SetProperty( TextEditor::Property::INPUT_SHADOW, "shadow" );
1034   editor.SetProperty( TextEditor::Property::INPUT_EMBOSS, "emboss" );
1035   editor.SetProperty( TextEditor::Property::INPUT_OUTLINE, "outline" );
1036
1037   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1038
1039   // Render and notify
1040   application.SendNotification();
1041   application.Render();
1042
1043   // Executes the idle callbacks added by the text control on the change of input style.
1044   application.RunIdles();
1045
1046   DALI_TEST_CHECK( !gInputStyleChangedCallbackCalled );
1047   DALI_TEST_CHECK( !inputStyleChangedSignal );
1048
1049   // Create a tap event to touch the text editor.
1050   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1051   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 63.f, 25.f ) ) );
1052
1053   // Render and notify
1054   application.SendNotification();
1055   application.Render();
1056
1057   // Executes the idle callbacks added by the text control on the change of input style.
1058   application.RunIdles();
1059
1060   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1061   if( gInputStyleChangedCallbackCalled )
1062   {
1063     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1064                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1065                                                  TextEditor::InputStyle::POINT_SIZE |
1066                                                  TextEditor::InputStyle::FONT_STYLE |
1067                                                  TextEditor::InputStyle::LINE_SPACING |
1068                                                  TextEditor::InputStyle::UNDERLINE |
1069                                                  TextEditor::InputStyle::SHADOW |
1070                                                  TextEditor::InputStyle::EMBOSS |
1071                                                  TextEditor::InputStyle::OUTLINE ),
1072                       TEST_LOCATION );
1073
1074     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1075     DALI_TEST_EQUALS( color, Color::BLACK, TEST_LOCATION );
1076   }
1077   DALI_TEST_CHECK( inputStyleChangedSignal );
1078
1079   gInputStyleChangedCallbackCalled = false;
1080   gInputStyleMask = TextEditor::InputStyle::NONE;
1081   inputStyleChangedSignal = false;
1082
1083   editor.SetProperty( TextEditor::Property::FONT_FAMILY, "DejaVuSerif" );
1084
1085   fontStyleMapSet.Clear();
1086   fontStyleMapSet.Insert( "weight", "black" );
1087   fontStyleMapSet.Insert( "width", "expanded" );
1088   fontStyleMapSet.Insert( "slant", "oblique" );
1089
1090   editor.SetProperty( TextEditor::Property::FONT_STYLE, fontStyleMapSet );
1091
1092   // Create a tap event to touch the text editor.
1093   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1094   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 30.f, 25.f ) ) );
1095
1096   // Render and notify
1097   application.SendNotification();
1098   application.Render();
1099
1100   // Executes the idle callbacks added by the text control on the change of input style.
1101   application.RunIdles();
1102
1103   DALI_TEST_CHECK( gInputStyleChangedCallbackCalled );
1104   if( gInputStyleChangedCallbackCalled )
1105   {
1106     DALI_TEST_EQUALS( static_cast<unsigned int>( gInputStyleMask ),
1107                       static_cast<unsigned int>( TextEditor::InputStyle::COLOR |
1108                                                  TextEditor::InputStyle::POINT_SIZE |
1109                                                  TextEditor::InputStyle::FONT_STYLE ),
1110                       TEST_LOCATION );
1111
1112     const Vector4 color = editor.GetProperty( TextEditor::Property::INPUT_COLOR ).Get<Vector4>();
1113     DALI_TEST_EQUALS( color, Color::YELLOW, TEST_LOCATION );
1114   }
1115   DALI_TEST_CHECK( inputStyleChangedSignal );
1116
1117   END_TEST;
1118 }
1119
1120 int utcDaliTextEditorEvent01(void)
1121 {
1122   ToolkitTestApplication application;
1123   tet_infoline(" utcDaliTextEditorEvent01");
1124
1125   // Creates a tap event. After creating a tap event the text editor should
1126   // have the focus and add text with key events should be possible.
1127
1128   TextEditor editor = TextEditor::New();
1129   DALI_TEST_CHECK( editor );
1130
1131   Stage::GetCurrent().Add( editor );
1132
1133   editor.SetSize( 300.f, 50.f );
1134   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1135   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1136
1137   // Avoid a crash when core load gl resources.
1138   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1139
1140   // Render and notify
1141   application.SendNotification();
1142   application.Render();
1143
1144   // Add a key event but as the text editor has not the focus it should do nothing.
1145   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1146
1147   // Render and notify
1148   application.SendNotification();
1149   application.Render();
1150
1151   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string(""), TEST_LOCATION );
1152
1153   // Create a tap event to touch the text editor.
1154   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1155   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1156
1157   // Render and notify
1158   application.SendNotification();
1159   application.Render();
1160
1161   // Now the text editor has the focus, so it can handle the key events.
1162   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1163   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1164
1165   // Render and notify
1166   application.SendNotification();
1167   application.Render();
1168
1169   DALI_TEST_EQUALS( editor.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1170
1171   // Create a second text editor and send key events to it.
1172   TextEditor editor2 = TextEditor::New();
1173
1174   editor2.SetParentOrigin( ParentOrigin::TOP_LEFT );
1175   editor2.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1176   editor2.SetSize( 100.f, 100.f );
1177   editor2.SetPosition( 100.f, 100.f );
1178
1179   Stage::GetCurrent().Add( editor2 );
1180
1181   // Render and notify
1182   application.SendNotification();
1183   application.Render();
1184
1185   // Create a tap event on the second text editor.
1186   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1187   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 125.0f ) ) );
1188
1189   // Render and notify
1190   application.SendNotification();
1191   application.Render();
1192
1193   // The second text editor has the focus. It should handle the key events.
1194   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1195   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1196
1197   // Render and notify
1198   application.SendNotification();
1199   application.Render();
1200
1201   // Check the text has been added to the second text editor.
1202   DALI_TEST_EQUALS( editor2.GetProperty<std::string>( TextEditor::Property::TEXT ), std::string("aa"), TEST_LOCATION );
1203
1204   END_TEST;
1205 }
1206
1207 int utcDaliTextEditorEvent02(void)
1208 {
1209   ToolkitTestApplication application;
1210   tet_infoline(" utcDaliTextEditorEvent02");
1211
1212   // Checks if the right number of actors are created.
1213
1214   TextEditor editor = TextEditor::New();
1215   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1216   DALI_TEST_CHECK( editor );
1217
1218   Stage::GetCurrent().Add( editor );
1219
1220   editor.SetSize( 300.f, 50.f );
1221   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1222   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1223
1224   // Avoid a crash when core load gl resources.
1225   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1226
1227   // Render and notify
1228   application.SendNotification();
1229   application.Render();
1230
1231   // Check there are the expected number of children ( offscreen root actor, and the offscreen image view
1232   DALI_TEST_EQUALS( editor.GetChildCount(), 2u, TEST_LOCATION );
1233
1234   Actor offscreenRoot = editor.GetChildAt( 0u );
1235   DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1236   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1237
1238   Actor offscreenImage = editor.GetChildAt( 1u );
1239   DALI_TEST_CHECK( offscreenImage );
1240
1241   // Create a tap event to touch the text editor.
1242   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1243   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 150.0f, 25.0f ) ) );
1244
1245   // Render and notify
1246   application.SendNotification();
1247   application.Render();
1248
1249   Actor layer = editor.GetChildAt( 2u );
1250   DALI_TEST_CHECK( layer.IsLayer() );
1251
1252   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1253   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor.
1254
1255   // Now the text editor has the focus, so it can handle the key events.
1256   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1257   application.ProcessEvent( GenerateKey( "a", "a", 0, 0, 0, Integration::KeyEvent::Down ) );
1258
1259   // Render and notify
1260   application.SendNotification();
1261   application.Render();
1262
1263   // Checks the cursor and the renderer have been created.
1264   DALI_TEST_EQUALS( layer.GetChildCount(), 1u, TEST_LOCATION ); // The cursor.
1265   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 2u, TEST_LOCATION ); // The camera actor and the renderer
1266
1267   Control cursor = Control::DownCast( layer.GetChildAt( 0u ) );
1268   DALI_TEST_CHECK( cursor );
1269
1270   CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1271   DALI_TEST_CHECK( camera );
1272
1273   // The offscreen root actor has a container with all the actors which contain the text renderers.
1274   Actor container = offscreenRoot.GetChildAt( 1u );
1275   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1276   {
1277     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1278     DALI_TEST_CHECK( renderer );
1279   }
1280
1281   // Move the cursor and check the position changes.
1282   Vector3 position1 = cursor.GetCurrentPosition();
1283
1284   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1285   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_LEFT, 0, 0, Integration::KeyEvent::Down ) );
1286
1287   // Render and notify
1288   application.SendNotification();
1289   application.Render();
1290
1291   Vector3 position2 = cursor.GetCurrentPosition();
1292
1293   DALI_TEST_CHECK( position2.x < position1.x );
1294
1295   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1296   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::Down ) );
1297
1298   // Render and notify
1299   application.SendNotification();
1300   application.Render();
1301
1302   Vector3 position3 = cursor.GetCurrentPosition();
1303
1304   DALI_TEST_EQUALS( position1, position3, TEST_LOCATION ); // Should be in the same position1.
1305
1306   // Send some taps and check the cursor positions.
1307
1308   // Try to tap at the beginning.
1309   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1310   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 1.f, 25.0f ) ) );
1311
1312   // Render and notify
1313   application.SendNotification();
1314   application.Render();
1315
1316   // Cursor position should be the same than position1.
1317   Vector3 position4 = cursor.GetCurrentPosition();
1318
1319   DALI_TEST_EQUALS( position2, position4, TEST_LOCATION ); // Should be in the same position2.
1320
1321   // Tap away from the start position.
1322   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 16.f, 25.0f ) ) );
1323   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 16.0f, 25.0f ) ) );
1324
1325   // Render and notify
1326   application.SendNotification();
1327   application.Render();
1328
1329   Vector3 position5 = cursor.GetCurrentPosition();
1330
1331   DALI_TEST_CHECK( position5.x > position4.x );
1332
1333   // Remove all the text.
1334   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1335   application.ProcessEvent( GenerateKey( "", "", DALI_KEY_BACKSPACE, 0, 0, Integration::KeyEvent::Down ) );
1336   editor.SetProperty( TextEditor::Property::TEXT, "" );
1337
1338   // Render and notify
1339   application.SendNotification();
1340   application.Render();
1341
1342   // Cursor position should be the same than position2.
1343   Vector3 position6 = cursor.GetCurrentPosition();
1344
1345   DALI_TEST_EQUALS( position2, position6, TEST_LOCATION );// Should be in the same position2.
1346
1347   // Should not be a renderer.
1348   DALI_TEST_EQUALS( offscreenRoot.GetChildCount(), 1u, TEST_LOCATION ); // The camera actor only.
1349
1350   END_TEST;
1351 }
1352
1353 int utcDaliTextEditorEvent03(void)
1354 {
1355   ToolkitTestApplication application;
1356   tet_infoline(" utcDaliTextEditorEvent03");
1357
1358   // Checks if the highlight actor is created.
1359
1360   TextEditor editor = TextEditor::New();
1361   DALI_TEST_CHECK( editor );
1362
1363   Stage::GetCurrent().Add( editor );
1364
1365   editor.SetProperty( TextEditor::Property::TEXT, "This is a long text for the size of the text-editor." );
1366   editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
1367   editor.SetSize( 30.f, 50.f );
1368   editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
1369   editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
1370
1371   // Avoid a crash when core load gl resources.
1372   application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
1373
1374   // Render and notify
1375   application.SendNotification();
1376   application.Render();
1377
1378   // Send some taps and check text controller with clipboard window
1379   Dali::Clipboard clipboard = Clipboard::Get();
1380   clipboard.ShowClipboard();
1381   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1382   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1383   clipboard.HideClipboard();
1384
1385   // Render and notify
1386   application.SendNotification();
1387   application.Render();
1388
1389   // Tap first to get the focus.
1390   application.ProcessEvent( GenerateTap( Gesture::Possible, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1391   application.ProcessEvent( GenerateTap( Gesture::Started, 1u, 1u, Vector2( 3.f, 25.0f ) ) );
1392
1393   // Render and notify
1394   application.SendNotification();
1395   application.Render();
1396
1397   // Double tap to select a word.
1398   application.ProcessEvent( GenerateTap( Gesture::Possible, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1399   application.ProcessEvent( GenerateTap( Gesture::Started, 2u, 1u, Vector2( 3.f, 25.0f ) ) );
1400
1401   // Render and notify
1402   application.SendNotification();
1403   application.Render();
1404
1405   // The offscreen root actor should have three actors: the camera, a renderer and the highlight actor.
1406   Actor offscreenRoot = editor.GetChildAt( 0u );
1407   DALI_TEST_CHECK( offscreenRoot.IsLayer() );
1408
1409   CameraActor camera = CameraActor::DownCast( offscreenRoot.GetChildAt( 0u ) );
1410   DALI_TEST_CHECK( camera );
1411
1412   // The offscreen root actor has a container with all the actors which contain the text renderers.
1413   Actor container = offscreenRoot.GetChildAt( 1u );
1414   for( unsigned int index = 0; index < container.GetChildCount(); ++index )
1415   {
1416     Renderer renderer = container.GetChildAt( index ).GetRendererAt( 0u );
1417     DALI_TEST_CHECK( renderer );
1418   }
1419
1420   Renderer highlight = offscreenRoot.GetChildAt( 2u ).GetRendererAt( 0u );
1421   DALI_TEST_CHECK( highlight );
1422
1423   END_TEST;
1424 }